Re: Advice on checking optionally installed applications/features

2009-10-23 Thread Ethan Jucovy
On Fri, Oct 23, 2009 at 1:09 PM, Mark (Nosrednakram)  wrote:

>
> Hello Django Users,
>
> I sometimes have reversion installed and sometimes have a
> CACHE_BACKEND defined and came up with the following solution for
> determining if I should register a model or use cache specific
> functionality.  Since I'm not a Python Guru I'm asking an evaluation
> of this method before I start using it in all my code.


It seems sensible to me.  I put a few implementation-level comments inline,
but I agree that checking for imports and the existence of settings is the
best way to do this.

The length
> check on CACHE_BACKEND is in the even someone sets it to ''.
> Currently I started adding this to each file where it's relevant.
>

You might want to encapsulate these in their own module somewhere, so you
can later change or add ways of determining the answers.  From the outside
it could then look like `from my_configuration import using_reversion; if
using_reversion(): [etc]`


> try:
>import reversion
>_USE_REVERSION=True
> except:
>_USE_REVERSION=False
>

Don't use a blanket `except`, just to be on the safe side.  You want `except
ImportError`.

try:
>if len(settings.CACHE_BACKEND) > 0:
>_USE_CACHE=True
> except:
>_USE_CACHE=False
>

Again, avoid catching all exceptions.  (If e.g. the settings module threw a
RuntimeError on attribute access, you'd probably want to know about that,
not disable the cache.)  Instead, `except AttributeError`, or just `if
len(getattr(settings, "CACHE_BACKEND", '')) > 0`.

Regards,
egj

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model design

2009-10-23 Thread Léon Dignòn

The second sounds more logically.

On 23 Okt., 15:41, chefsmart  wrote:
> I would go with your second solution.
>
> On Oct 23, 5:17 pm, Caisys  wrote:
>
>
>
> > Hi,
> > I have classes for Event, Place and Subplace. Some of the Places are
> > divided into different Halls (Subplace) and some have only one. I
> > would like to know how design the relations between the classes.
>
> > 1) Should I put two columns in the Event one FK to Place and another
> > FK to Hall?
> > 2) Should I create one FK only to Hall and create a record in Hall for
> > every Place even if the Place has no Halls?
>
> > Thanks- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread Margie Roginski

Wow!  Ok, that is cool.  There is also a reference down in the comment
section about how to do this with a new API that will be coming out in
Firefox 3.6.  IE, this is without gears:

http://www.thecssninja.com/javascript/drag-and-drop-upload

This also looks very interesting and the comments in this seem to echo
what I was saying about badly needing this functionality to move
towards a web app that feels like a desktop app.

Ok, I'm off to figure this all out - thanks so much guys!

Margie

On Oct 23, 2:33 pm, kmike  wrote:
> No, my code doesn't do that, sorry for not expressing this clear.
>
> Here is the example of drag-n-drop images upload:
>
> http://www.appelsiini.net/2009/10/drag-and-drop-file-upload-with-goog...
>
> And here is the corresponding API documentation:
>
> http://code.google.com/intl/ru/apis/gears/api_desktop.html
>
> On 24 окт, 03:22, Margie Roginski  wrote:
>
> > Thanks everyone for all of your comments - I've been off looking at
> > these various choices, learning a bit about java/flash this morning.
> > I was not able to gethttp://www.radinks.com/upload/dnd.phptowork.
> > It seems that even with the demo I have access privilege issues.
> > Ariel, when you run the demo are you able to see your dropped files in
> > the demo area?  I get a message about the names of the files uploaded,
> > and some stuff like this "Files have not been saved, please edit
> > upload.php to match your configuration".  Anyway, just curious if it
> > works for you or if you didn't try it.
>
> > Javier - I took a look athttp://swfupload.org/andthat is indeed
> > very nice looking.  I have not used flash yet so I think I will take
> > this as an opportunity to figure out what that can do for me and try
> > using it.
>
> > Kmike - the gears thing seems promising but I am frankly still having
> > trouble figuring out what it does.  Does your code actually upload
> > files via drag and drop?  I will try downloading your code and see if
> > I can figure it out from that, just haven't had a chance yet.
>
> > Anyway, thanks to all of your for your insights. It seems like not
> > having this functionality is a huge impediment in making a web app
> > look and feel like a desktop app. I'm trying to write a web app that
> > will allow people to manage and discuss their tasks associated with
> > chip design, and my users' first response is always "Can I drag and
> > drop my images like I do with Outlook?".  It is amazing to me that we
> > are so far from having an easy solution for this in the web app world,
> > I have to believe all of the social networking sights would love to
> > have drag and drop images.
>
> > Ok, so I will continue diving into your various suggestions for
> > now ... thanks!
>
> > Margie
>
> > On Oct 23, 11:50 am, Javier Guerra  wrote:
>
> > > On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  
> > > wrote:
> > > > I found this while googling: "drag and drop upload":
>
> > > >http://www.radinks.com/upload/dnd.php
>
> > > > Seems to use a combination of Java (applet) + PHP (server) and is not
> > > > open source.
>
> > > i tried this one several years ago.  unfortunately, can't recommend
> > > it.  even with corporate clients, it's a nightmare to keep the applet
> > > with enough access privileges to read the dropped files.  almost any
> > > small update on the client machine, and the Java system asked (again)
> > > to authorize it.  i have yet to find a single user that could
> > > understand what it was asking, and why.  and once it's disabled on a
> > > machine, it's very hard to enable again.
>
> > > the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
> > > part is mostly to set the options for the  tag
>
> > > --
> > > Javier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django deployment using apache and mod_wsgi

2009-10-23 Thread Dhruv Adhia

I have complete application working on localhost and now I want to
deploy that so other of my teammates can use it.

I have centos,
apache,
python 2.5
django 1.1.1


I have my django project at /var/www/html/ipwn/carbon_chaos
inside carbon_chaos folder I created apache folder and inside apache
folder I created file called django.wsgi
Inside django.wsgi I have


import os
import sys
sys.path.append('/var/www/html/ipwn/carbon_chaos')
sys.path.append('/usr/lib/python2.5/site-packages/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'carbon_chaos.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


I have little idea what to do next as I have done deployment once
before

I remember using this code and creating some sort of file out of it
and enabling it

WSGIRestrictStdout Off

LimitInternalRecursion 1000
ServerAdmin webmas...@localhost
ServerName localhost
DocumentRoot /home/user/django/
ErrorLog /home/user/django/apache.log
LogLevel warn
AddHandler wsgi-script .wsgi

AllowOverride FileInfo
Options ExecCGI MultiViews FollowSymLinks
MultiviewsMatch Handlers
Order deny,allow
Allow from all

Alias /media/ "/home/user/django/myproject/media/"

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
allow from all



I had made appropriate changes and did some enabling stuff and running
apachectl start command and it showed up.
I read the following doc
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

But it didnt say what name should I be saving that file with and where
should be saving it. Also enabling part is something I am looking for.

Can somebody just briefly walk me through the steps?

Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread kmike

No, my code doesn't do that, sorry for not expressing this clear.

Here is the example of drag-n-drop images upload:

http://www.appelsiini.net/2009/10/drag-and-drop-file-upload-with-google-gears

And here is the corresponding API documentation:

http://code.google.com/intl/ru/apis/gears/api_desktop.html

On 24 окт, 03:22, Margie Roginski  wrote:
> Thanks everyone for all of your comments - I've been off looking at
> these various choices, learning a bit about java/flash this morning.
> I was not able to gethttp://www.radinks.com/upload/dnd.phpto work.
> It seems that even with the demo I have access privilege issues.
> Ariel, when you run the demo are you able to see your dropped files in
> the demo area?  I get a message about the names of the files uploaded,
> and some stuff like this "Files have not been saved, please edit
> upload.php to match your configuration".  Anyway, just curious if it
> works for you or if you didn't try it.
>
> Javier - I took a look athttp://swfupload.org/and that is indeed
> very nice looking.  I have not used flash yet so I think I will take
> this as an opportunity to figure out what that can do for me and try
> using it.
>
> Kmike - the gears thing seems promising but I am frankly still having
> trouble figuring out what it does.  Does your code actually upload
> files via drag and drop?  I will try downloading your code and see if
> I can figure it out from that, just haven't had a chance yet.
>
> Anyway, thanks to all of your for your insights. It seems like not
> having this functionality is a huge impediment in making a web app
> look and feel like a desktop app. I'm trying to write a web app that
> will allow people to manage and discuss their tasks associated with
> chip design, and my users' first response is always "Can I drag and
> drop my images like I do with Outlook?".  It is amazing to me that we
> are so far from having an easy solution for this in the web app world,
> I have to believe all of the social networking sights would love to
> have drag and drop images.
>
> Ok, so I will continue diving into your various suggestions for
> now ... thanks!
>
> Margie
>
> On Oct 23, 11:50 am, Javier Guerra  wrote:
>
>
>
> > On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  
> > wrote:
> > > I found this while googling: "drag and drop upload":
>
> > >http://www.radinks.com/upload/dnd.php
>
> > > Seems to use a combination of Java (applet) + PHP (server) and is not
> > > open source.
>
> > i tried this one several years ago.  unfortunately, can't recommend
> > it.  even with corporate clients, it's a nightmare to keep the applet
> > with enough access privileges to read the dropped files.  almost any
> > small update on the client machine, and the Java system asked (again)
> > to authorize it.  i have yet to find a single user that could
> > understand what it was asking, and why.  and once it's disabled on a
> > machine, it's very hard to enable again.
>
> > the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
> > part is mostly to set the options for the  tag
>
> > --
> > Javier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread Margie Roginski

Thanks everyone for all of your comments - I've been off looking at
these various choices, learning a bit about java/flash this morning.
I was not able to get http://www.radinks.com/upload/dnd.php to work.
It seems that even with the demo I have access privilege issues.
Ariel, when you run the demo are you able to see your dropped files in
the demo area?  I get a message about the names of the files uploaded,
and some stuff like this "Files have not been saved, please edit
upload.php to match your configuration".  Anyway, just curious if it
works for you or if you didn't try it.

Javier - I took a look at http://swfupload.org/ and that is indeed
very nice looking.  I have not used flash yet so I think I will take
this as an opportunity to figure out what that can do for me and try
using it.

Kmike - the gears thing seems promising but I am frankly still having
trouble figuring out what it does.  Does your code actually upload
files via drag and drop?  I will try downloading your code and see if
I can figure it out from that, just haven't had a chance yet.

Anyway, thanks to all of your for your insights. It seems like not
having this functionality is a huge impediment in making a web app
look and feel like a desktop app. I'm trying to write a web app that
will allow people to manage and discuss their tasks associated with
chip design, and my users' first response is always "Can I drag and
drop my images like I do with Outlook?".  It is amazing to me that we
are so far from having an easy solution for this in the web app world,
I have to believe all of the social networking sights would love to
have drag and drop images.

Ok, so I will continue diving into your various suggestions for
now ... thanks!

Margie


On Oct 23, 11:50 am, Javier Guerra  wrote:
> On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  wrote:
> > I found this while googling: "drag and drop upload":
>
> >http://www.radinks.com/upload/dnd.php
>
> > Seems to use a combination of Java (applet) + PHP (server) and is not
> > open source.
>
> i tried this one several years ago.  unfortunately, can't recommend
> it.  even with corporate clients, it's a nightmare to keep the applet
> with enough access privileges to read the dropped files.  almost any
> small update on the client machine, and the Java system asked (again)
> to authorize it.  i have yet to find a single user that could
> understand what it was asking, and why.  and once it's disabled on a
> machine, it's very hard to enable again.
>
> the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
> part is mostly to set the options for the  tag
>
> --
> Javier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Foreign Key Admin UI Error (from a new user)

2009-10-23 Thread David Nolen

My admin looks something like the following-

class TitleInline(admin.TabularInline):
model = Title
extra = 1

class WorkAdmin(admin.ModelAdmin):
inlines = [TitleInline]
admin.site.register(Work, WorkAdmin)


My models look something like this-

class Work(ArtBaseModel):
def __unicode__(self):
return "Foobar"

class Title(ArtBaseModel):
"""
Title record.
"""
work = models.ForeignKey(Work, related_name="title_set")
displayString = models.CharField(max_length=1024)
type = models.CharField(max_length=256)
lang = models.CharField(max_length=32)

def __unicode__(self):
return self.displayString


However when I try to add a new work using the admin interface I get:

 has more than 1 ForeignKey to 

I'm sure it's a simple mistake on my part.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Definitive solution for foreignkey filtering in Admin

2009-10-23 Thread Tim Valenta

I've been searching for a while on how to intercept querysets in
forms, to apply a custom filter to the choices on both foreignkey and
m2m widgets.  I'm surprised at how there are so many similar questions
out there, dating back to 2006.

I came across the documentation for
ModelAdmin.formfield_for_foreignkey (http://docs.djangoproject.com/en/
dev/ref/contrib/admin/
#django.contrib.admin.ModelAdmin.formfield_for_foreignkey), and
thought I had a perfect solution, but the method doesn't seem to
entirely fit the hole I'm trying to fill.

Consider these models:

# models.py
class Company(models.Model):
# ...
class Contract(models.Model):
company = models.ForeignKey(Company)
locations = models.ManyToManyField('Location')
class Location(models.Model):
company = models.ForeignKey(Company)

So, Company is at the top of the hierarchy, with both Contract and
Location holding foreign keys to Company, and then Contract and
Location share an m2m relationship.

The admin presents this data so that the m2m widget on Contract lets
you pick from any Location in the database.  Arguably, there should be
an option for the implied common relationship to take effect, of both
Contract and Location to Company.

The only solution I've seen has dealt with filtering by User foreign
key (being that User is available in the request object in views), and
that's primarily for non-Admin views.




I've been looking at the code for the above noted API method,
formfield_for_foreignkey, and I really can't see a way to get
references to an instance of the object being edited.  I would need
such a reference to successfully override that method and filter my
queryset on this relationship.

Any thoughts?  There are dozens of unanswered questions just like this
all over popular sites on the internet.  We need a solution.  The
feature list for Django 1.2 does not seem to reference anything on
this matter!

Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Replicating Google Groups in Django

2009-10-23 Thread CLIFFORD ILKAY

Lakshman Prasad wrote:
> You should use the lamson project, by Zed Shaw: http://lamsonproject.org/

Hello Lakshman,

Unless Lamson has years of development behind it and does all the things 
that Mailman does "out of the box", it's not a replacement for Mailman. 
It would have to implement all the good stuff that Mailman does, like 
bounce and mail loop handling, to name a couple. Also, Mailman is not an 
MTA (Mail Transfer Agent - aka, mail server) and doesn't pretend to be 
one. It's a listserv that depends on an MTA.

Lamson claims to be a "replacement" for an MTA, though I'm sceptical 
that it can be for anything but simple cases since MTAs like Postfix, 
while not necessarily being the most friendly things to configure, have 
years of development and optimization behind them and are used by many 
hosting providers, large and small. Once Postfix is set up, it runs with 
minimal maintenance. We host domains so I know that email is *the* 
mission-critical application for most businesses. Anyone who knows 
what's good for them doesn't tamper with time-tested and proven 
technologies just because something "cooler" comes along, and I'm not 
sure that Lamson is even that. We store Postfix virtual domain and 
mailbox information, and authentication information in PostgreSQL so the 
purported advantage of Lamson in being able to use the Django ORM 
against configuration stored in a database offers nothing that we don't 
already already have. There is no "bizarre combination of flat-files and 
hashtables!" issue. We don't have to change a thing in the config files 
in Postfix or even reload or restart it to add/modify/delete virtual 
domains or virtual users. We just do inserts/updates/deletes into a 
database.

I wanted to know how Lamson handled virtual domains and virtual 
mailboxes so I clicked on the "Deploying Lamson Level 2" link 
 only to 
see "Coming soon..." on that page. That only reinforces my scepticism.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Replicating Google Groups in Django

2009-10-23 Thread CLIFFORD ILKAY

Julien Phalip wrote:
> Hi,
> 
> On one site I'm considering the possibility of replicating the (basic)
> functionality of Google Groups in Django. The idea is:
> 
> - There would be 5 different mailing lists. Users can subscribe to one
> or more lists.
> - People can purely use emails to access the lists.
> - All the emails can then also be seen via a web interface.
> 
> I've been thinking of using Mailman to leverage all the email
> management part. But now I'm not sure how to reliably sync the Mailman
> subscription system with django.contrib.auth.
> 
> I don't think there's any straight forward to do this. Would you have
> any advice to get me started?

Hello Julien,

Mailman stores its membership "database" in Python pickles. You have a 
few options for integrating with it. First, you can use an adaptor for 
MM that will enable you to store the membership db in MySQL. It has been 
a while since I looked at it so I don't know if there is one for 
PostgreSQL. I doubt it would be difficult to modify, if there isn't. 
Once it's in a database, you can do whatever you want from Django. 
Second, you can do what "foreign" technologies, like Drupal, which is 
written in PHP, do and "automate" MM by treating MM as a black box and 
just invoking its web front end. There is a Drupal module for MM that 
makes the process seamless for Drupal site members so if it's feasible 
for a PHP-based application, it's certainly feasible for you to do it in 
Django.

As for how all emails can be seen via a web interface, one option is to 
have Django subscribe to the lists in question and use an IMAP client 
library to access the mailbox for that subscriber.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread Javier Guerra

On Fri, Oct 23, 2009 at 1:29 PM, Ariel Nunez  wrote:
> I found this while googling: "drag and drop upload":
>
> http://www.radinks.com/upload/dnd.php
>
> Seems to use a combination of Java (applet) + PHP (server) and is not
> open source.

i tried this one several years ago.  unfortunately, can't recommend
it.  even with corporate clients, it's a nightmare to keep the applet
with enough access privileges to read the dropped files.  almost any
small update on the client machine, and the Java system asked (again)
to authorize it.  i have yet to find a single user that could
understand what it was asking, and why.  and once it's disabled on a
machine, it's very hard to enable again.

the server doesn't have to be PHP, in fact it's usually FTP.  the PHP
part is mostly to set the options for the  tag


-- 
Javier

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread kmike

Google Gears can also be used in order to implement drag-n-drop image
uploading. I beleive it is the easiest way because it only involves
some javascript programming.

You can also do other nice things with Google Gears (resize images
client-side, for example; check http://bitbucket.org/kmike/gearsuploader/
for ready solution).

On 24 окт, 00:29, Ariel Nunez  wrote:
> Hi Margie,
>
> I found this while googling: "drag and drop upload":
>
> http://www.radinks.com/upload/dnd.php
>
> Seems to use a combination of Java (applet) + PHP (server) and is not  
> open source.
>
> But it seems to prove it is possible. Just perhaps not with simple  
> HTML + JS.
>
> Regards,
>
> Ariel.
>
> On Oct 23, 2009, at 9:28 AM, Javier Guerra wrote:
>
>
>
>
>
> > On Thu, Oct 22, 2009 at 11:54 PM, Margie Roginski
> >  wrote:
> >>  They want to use
> >> an windows app called mwsnap to basically snap images from their
> >> desktop, then ctrl-v to copy the image into my django app.
>
> > is there any web app that does this?  AFAICT, all use some upload
> > button (maybe augmented with flash libraries, like the great one from
> >http://swupload.org/)
>
> > --
> > Javier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread Ariel Nunez

Hi Margie,

I found this while googling: "drag and drop upload":

http://www.radinks.com/upload/dnd.php

Seems to use a combination of Java (applet) + PHP (server) and is not  
open source.

But it seems to prove it is possible. Just perhaps not with simple  
HTML + JS.

Regards,

Ariel.

On Oct 23, 2009, at 9:28 AM, Javier Guerra wrote:

>
> On Thu, Oct 22, 2009 at 11:54 PM, Margie Roginski
>  wrote:
>>  They want to use
>> an windows app called mwsnap to basically snap images from their
>> desktop, then ctrl-v to copy the image into my django app.
>
> is there any web app that does this?  AFAICT, all use some upload
> button (maybe augmented with flash libraries, like the great one from
> http://swupload.org/)
>
> -- 
> Javier
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



convert passing tests to beautiful test report?

2009-10-23 Thread Phlip

Djangoists:

Given a bunch of unittests, how to convert them to some kind of
literate or doc-stringed report?

The goal is to show off all our tests!

-- 
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



setting 'choices' on a custom field

2009-10-23 Thread fink

problem: setting a form field's 'choices' in the __init__ of a field class does 
not affect the choices displayed in the resulting form.
i suspect the problem lies somewhere in the custom field's handling of passed 
in values, but my form-fu is not strong enough to figure it out.

for example, the following 'choices' are ignored in the resulting form:


admin.py:

class ProductAdminForm(forms.ModelForm):
class Meta:
model = Product

def __init__(self, *args, **kwargs):
super(ProductAdminForm, self).__init__(*args, **kwargs)
self.fields['classification_tags'].choices = 
get_taggroup_tags(taggroup='classification_tags')

class ProductAdmin(admin.ModelAdmin):
form = ProductAdminForm

admin.site.register(Product, ProductAdmin)



background:
the site contains many tags, and certain tags are organized into groups of 
tags: TagGroups.
the main tagged model (Product) has specialized tag fields (eg: 
'classification_tags'), containing only the tags of a particular TagGroup.

eg:
there 100 tags on the site, and the TagGroup 'classification_tags' contains 10.
as expected, setting 'choices' on Product's 'classification_tags' field to the 
tags from 'classification_tags' shows only those 10 tags (instead of 100) when 
editing a Product instance in the admin.
however, when the 'classification_tags' TagGroup is updated (addition or 
removal of a tag from the group), the choices shown in the admin are not 
updated until a server restart.  hence, modifying 
fields['classification_tags'].choices in the admin form's __init__, as above.


models.py:

def get_taggroup_tags(taggroup):
return ( ((t.strip(',"'),t.strip(',"')) for t in 
TagGroup.objects.get(name=taggroup).tags.split() ))

class TagGroup(models.Model):
name = models.CharField(_('name'), max_length=255, unique=True)
tags = TagSelectField(filter_horizontal=True, blank=False)

def __unicode__(self):
return self.name

class Product(models.Model):
title = models.CharField(_('title'), max_length=255, unique=True)

#classification_tags = 
TagSelectField(filter_horizontal=True,choices=get_taggroup_tags(taggroup='classification_tags'))
classification_tags = TagSelectField(filter_horizontal=True)

def __unicode__(self):
return self.title

tagging.register(Product)



TagSelectField is a variation of django-tagging's TagField, and uses a 
SelectMultiple widget, from here: 
http://code.google.com/p/django-tagging/issues/detail?id=189


tagselect.py:

"""
TagSelectField

A variation of the django-tagging TagField which uses a 
SelectMultiple widget instead of free text field.

class MyModel(models.Model):
...
tags = TagSelectField(filter_horizontal=True, blank=False)

"""
from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from tagging.models import Tag, TaggedItem
from tagging.fields import TagField
from tagging.utils import *

class TagSelectFormField(forms.MultipleChoiceField):
def clean(self, value):
return ', '.join(['"%s"' % tag for tag in value ])

class TagSelectField(TagField):
def __init__(self, filter_horizontal=False, *args, **kwargs):
super(TagSelectField, self).__init__(*args, **kwargs)
self.filter_horizontal = filter_horizontal

def formfield(self, **defaults):
if not self.choices:
#if no choices are specified, get all tags
choices = [ (str(t)) for t in Tag.objects.all() ]
else:
#otherwise show only the tags passed in via choices
choices = [ (t[0]) for t in self.choices]

if self.filter_horizontal:
widget = FilteredSelectMultiple(self.verbose_name, is_stacked=False)
else:
widget = forms.SelectMultiple()

def _render(name, value, attrs=None, *args, **kwargs):
value = parse_tag_input(value)
return type(widget).render(widget, name, value, attrs, *args, 
**kwargs)

widget.render = _render
defaults['widget'] = widget

choices = [ (str(t), str(t)) for t in choices ]

return TagSelectFormField(choices=choices, required=not self.blank, 
**defaults)


the 'get_taggroup_tags' function is known to work and provide 2-tuples.

i realize this is rather esoteric and unusual, but any help would be 
appreciated. thanks!


  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Advice on checking optionally installed applications/features

2009-10-23 Thread Mark (Nosrednakram)

Hello Django Users,

I sometimes have reversion installed and sometimes have a
CACHE_BACKEND defined and came up with the following solution for
determining if I should register a model or use cache specific
functionality.  Since I'm not a Python Guru I'm asking an evaluation
of this method before I start using it in all my code.  The length
check on CACHE_BACKEND is in the even someone sets it to ''.
Currently I started adding this to each file where it's relevant.

try:
import reversion
_USE_REVERSION=True
except:
_USE_REVERSION=False

try:
if len(settings.CACHE_BACKEND) > 0:
_USE_CACHE=True
except:
_USE_CACHE=False

Thank you,
Mark
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: nginx, apache, and odd admin error

2009-10-23 Thread rd-london

Right, well, replying to myself ... and hoping someone else will jump
in, here's where I'm upto ...

Having read around a bit, I figured that the reverse proxy my well be
losing the original IP address, so I looked into configuring
"SetRemoteAddrFromForwardedFor" (http://code.djangoproject.com/browser/
django/trunk/django/middleware/http.py?rev=11000#L33). Whilst this
certainly helped retain the original IP address (I setup reporting to
apache_error.log via my .wsgi file), what became clear is that it's
not the IP address that's the problem, it's the *port*.

So, I try logging in via http://127.0.0.1:81/admin/ and end up being
redirected to http://127.0.0.1/admin/ (port 81 is managed and served
via nginx).
However, if I login to admin via my apache port, 127.0.0.1:96 I don't
suffer in this way 

So, any thoughts anyone?

On a slightly separate note - forgetting the reverse proxy arrangment
for a moment, how would one serve admin on a separate port?

Thanks for any help,
R




On Oct 21, 10:25 pm, rd-london  wrote:
> Hi,
> Wonder if someone can help.This issue is all with a local dev
> situation, so this isn't live.
>
> I have nginx running on port 81 e.g.http://127.0.0.1:81/and serving
> static media - which in turn proxies through to Apache running on port
> 96. All works fine (apart from the issue I outline below) - so I can
> browse my content no problem.
>
> The issues relate to the admin interface.
>
> If I request the admin interface athttp://127.0.0.1:81/admin/, the
> admin login window appears but on "log in", I am taken to  
> http://127.0.0.1/admin/
> - which of course 404's i.e. doesn't work (there appears to be some
> kind of redirect going on).
>
> Once I've got this 404, if I then requesthttp://127.0.0.1:81/admin/
> again, the full "logged in" interface now comes up - i.e. I am now
> *not* redirected and am now logged in.
>
> Carrying on ... if I try to edit some content, all works fine until I
> try to Save or Save and Continue ... at which point again I am
> redirected to admin URL minus the port (incidentally the item is then
> saved).
>
> If I work directly on the Apache interface athttp://127.0.0.1:96/I
> don't have this problem.
>
> Anyone any suggestions as to what's going on and how to fix it?
>
> Many thanks,
> R
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Url params with space

2009-10-23 Thread Andrius A
Hi Sumanth,

Yes we do. Use urlib.unquote_plus()

Regards,
Andrius

On 23 Oct 2009 17:14, "Sumanth"  wrote:


Hi All,

I have url as show below

http://localhost:8000/view/1/1/?scenario=Base,%20Credit

now when I do a request.REQUEST['scenario']

I see a value of 'Base,+Credit'  I get char + instead of space

How do I retain space char ? Do we have a any functions or module
which will return correct url encoding ?

Thanks
Sumanth



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Appropriate decorator for use with database-level autocommit

2009-10-23 Thread Christophe Pettus

For a new project, I'm planning to use the database-level autocommit  
functionality for Postgres as described in:

http://docs.djangoproject.com/en/dev/ref/databases/#ref-databases

For view functions that do database modification, I'll wrap them in  
the appropriate start/end transaction handling.  Is there an existing  
decorator function that would be useful for that?  Rolling my own  
doesn't seem too intimidating, but if one already exists, why not use  
it?

Thanks!
--
-- Christophe Pettus
x...@thebuild.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Url params with space

2009-10-23 Thread Sumanth

Hi All,

I have url as show below

http://localhost:8000/view/1/1/?scenario=Base,%20Credit

now when I do a request.REQUEST['scenario']

I see a value of 'Base,+Credit'  I get char + instead of space

How do I retain space char ? Do we have a any functions or module
which will return correct url encoding ?

Thanks
Sumanth


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: problem with test client

2009-10-23 Thread Ralph

Thanks! That was the missing piece.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



An app that can provide user friendly, multiple / mass file upload functionality to other apps

2009-10-23 Thread Michiel

Hi,

I want to create an app that makes it easy to do user friendly,
multiple / mass file upload in your own apps. With user friendly I
mean upload like Gmail, Flickr, ... where the user can select multiple
files at once in the browse file dialog. The files are then uploaded
sequentially or in parallel and a nice overview of the selected files
is shown on the page with a progress bar next to them. A 'Cancel'
upload button is also a possible option.

All that niceness is usually solved by using a Flash object. Complete
solutions are out there for the client side, like: SWFUpload
http://swfupload.org/ , FancyUpload http://digitarald.de/project/fancyupload/
, YUI 2 Uploader http://developer.yahoo.com/yui/uploader/ and probably
many more.

Ofcourse the trick is getting those solutions integrated in your
project. Especially in a framework like Django, double so if you want
it to be reusable.

So, I have a few ideas, but I'm neither an expert on Django nor on
Flash based upload solutions. I'll share my ideas here in the hope of
getting some feedback from more knowledgeable and experienced people.
Or even just some 'I want this too!' replies :) (seriously do reply!)

You will notice that I make a few assumptions: this is to keep the
(initial) scope of the application under control. These assumptions
are ofcourse open for comments!

Allright, my idea's so far:

* If you want to mass upload multiple files, you are going to have a
model to contain each file in. I.e. the model will contain one
FileField or one ImageField.
  Models with multiple (but ofcourse finite) amount of FileFields/
ImageFields are not in need of easy mass uploading imho: if you have a
model with 100 FileFields you are doing something wrong :)
  Examples where you would want my envisioned kind of mass upload:
  * An app that has just one model 'Brochure' with a file field, a
title field (dynamically created from the filename) and a date_added
field.
  * A photo gallery app with models 'Gallery' and 'Photo'. You pick a
Gallery to add pictures to, upload the pictures and new Photo objects
are created and foreign keys set to the choosen Gallery.

* It would be nice to be able to configure or extend the app for your
favourite Flash upload solution. We can pick one of the three above as
a default, but implement the app so that people can easily add
additional implementations (kinda like Django can use multiple
databases). Let it be agnostic to any particular client side solution.

* If we need to pick one to start with, maybe pick the one with the
smallest footprint? (smallest download of client side stuff)

* The Flash based solutions asynchronously (and either sequentially or
in parallel) POST the files to a url. I suggest that url to be local
to our generic app (so it's the same for every app where you use our
app in). That url will go to a view provided by our generic app.

* The view will do the following: create a new model instance, add the
file, OPTIONALLY DO EXTRA STUFF and save the instance.

* DO EXTRA STUFF is code that the app that uses our app wants to run.
It doesn't have to provide any extra code, if the model has just a
FileField/ImageField the standard view code will do the job.
  But most app will want to do extra stuff I think, like filling in
the other fields: title, date_added, foreignkeys, manytomany, ...

* I have not yet thought about a mechanism for DO EXTRA STUFF. Just
wrapping the generic app view came to mind, but that is not developer
friendly, since you would have to write your own url pattern and your
own view. Then you have to tell the Flash solutions to use a new url
etc...
  I think something like signals could be used here?

* Forms/Admin: I'm still very sketchy on how all this could best be
integrated in the Admin or generic Django forms/widgets/...
  (and this is were my lack of Django experience shows):
  * In the case of the Gallery/Photo app:
You could provide a mass Photo upload widget on the Gallery detail
form. But what if the Gallery instance is not saved yet? The file
upload view won't be able to set the foreignkeys on the Photo
instances. I see that the auth app, when you create a user, first asks
for username and password and only then provides you with a bigger
form to fill in emailadres, pick roles etc. We could do something like
that.
  * In the case of an app with just one model:
How do you provide a form in the Django admin to do your mass
upload? You can't do it with the detail form of your model, that's
just for one model instance.


There's probably dozens more questions that need to be answered before
I can even start on this app. So please tell me what you think! Give
me input! What do you like? What not? What would you do different? Is
this idea solid? Where is it not?

Thank you,

Michiel

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to 

Re: problem with test client

2009-10-23 Thread Daniel Roseman

On Oct 23, 4:16 pm, Ralph  wrote:
> I am using Django 1.1 with Python 2.6.1 and have a problem with
> testing
> views that require a login. I was hoping someone could enlighten me
> were
> it all goes wrong
>
> in the setup function of a unit test i am adding a user and create a
> test client
>
> User.objects.create(username='myuser', password='mypassword')
> self.client = Client()
>
> but get an AssertionError when i do this
> self.assertEquals(self.client.login
> (username='myuser',password='mypassword'), True)
> as the login fails.
>
> The User class in  django.auth.models in
> the check_password method returns False. In line 182
>
> is_correct = (self.password == get_hexdigest('md5', '', raw_password))
>
> self.password is at this stage "mypassword" and will be
> compared to a hexdigest so that the comparison will return False.
> Authentification
> works fine outside the tests. Is there anything in the settings
> that I need to adjust to get this to work? Thanks

Look at the documentation for authentication - don't use
User.objects.create() but User.objects.create_user(), as this takes
care of hashing the password.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



problem with test client

2009-10-23 Thread Ralph

I am using Django 1.1 with Python 2.6.1 and have a problem with
testing
views that require a login. I was hoping someone could enlighten me
were
it all goes wrong

in the setup function of a unit test i am adding a user and create a
test client

User.objects.create(username='myuser', password='mypassword')
self.client = Client()

but get an AssertionError when i do this
self.assertEquals(self.client.login
(username='myuser',password='mypassword'), True)
as the login fails.

The User class in  django.auth.models in
the check_password method returns False. In line 182

is_correct = (self.password == get_hexdigest('md5', '', raw_password))

self.password is at this stage "mypassword" and will be
compared to a hexdigest so that the comparison will return False.
Authentification
works fine outside the tests. Is there anything in the settings
that I need to adjust to get this to work? Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django basic tests are failing

2009-10-23 Thread jamesM

solved by changing the default collation of mysql server from utf8_bin
to utf8_general_ci.

in case you encounter something similar, do change db backend to
sqlite3 and then rerun the test,
if the tests pass - there's a problem with database server.

j

On Oct 23, 1:50 pm, jamesM  wrote:
> This apparently is my bad, i've just created an empty project, and all
> the tests of it pass. Am working on tracking down the problem.
>
> On Oct 23, 1:29 pm, jamesM  wrote:
>
> > Hi guys,
>
> > i've decided to practice some test-driven development with django and
> > bumped into some small problems.
> > No idea is this a bug or my bad, but after running python manage.py
> > test i get the two tests which fail (error below). Both of them
> > expects unicode value, but receives a simple string. I'm using django
> > trunk.
>
> > I could try fix the Expected value to the one which is returned, but i
> > guess that's not the best practice to start with:)
> > Maybe anyone has any ideas how to make those tests pass?
>
> > cheers!
> > j
>
> > 
> > output of $python manage.py test
> > 
>
> > Creating test database...
> > Creating table auth_permission
> > Creating table auth_group
> > Creating table auth_user
> > Creating table auth_message
> > Creating table django_content_type
> > Creating table django_session
> > Creating table django_site
> > Creating table django_admin_log
> > Creating table documents
> > Installing index for auth.Permission model
> > Installing index for auth.Message model
> > Installing index for admin.LogEntry model
> > FF.
> > ==
> > FAIL: Doctest: django.contrib.auth.tests.__test__.BASIC_TESTS
> > --
> > Traceback (most recent call last):
> >   File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
> > line 2180, in runTest
> >     raise self.failureException(self.format_failure(new.getvalue()))
> > AssertionError: Failed doctest test for
> > django.contrib.auth.tests.__test__.BASIC_TESTS
> >   File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> > __init__.py", line unknown line number, in BASIC_TESTS
>
> > --
> > File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> > __init__.py", line ?, in
> > django.contrib.auth.tests.__test__.BASIC_TESTS
> > Failed example:
> >     u.email
> > Expected:
> >     u'@somewhere.org'
> > Got:
> >     '@somewhere.org'
> > --
> > File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> > __init__.py", line ?, in
> > django.contrib.auth.tests.__test__.BASIC_TESTS
> > Failed example:
> >     u.password
> > Expected:
> >     u'!'
> > Got:
> >     '!'
>
> > ==
> > FAIL: Doctest: django.contrib.sites.tests
> > --
> > Traceback (most recent call last):
> >   File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
> > line 2180, in runTest
> >     raise self.failureException(self.format_failure(new.getvalue()))
> > AssertionError: Failed doctest test for django.contrib.sites.tests
> >   File "/usr/lib/python2.5/site-packages/django/contrib/sites/
> > tests.py", line 0, in tests
>
> > --
> > File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
> > line 21, in django.contrib.sites.tests
> > Failed example:
> >     site.name
> > Expected:
> >     u"example.com"
> > Got:
> >     'example.com'
> > --
> > File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
> > line 27, in django.contrib.sites.tests
> > Failed example:
> >     site.name
> > Expected:
> >     u"Example site"
> > Got:
> >     'Example site'
>
> > --
> > Ran 35 tests in 21.128s
>
> > FAILED (failures=2)
> > Destroying test database...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to cut and paste image into django app

2009-10-23 Thread Javier Guerra

On Thu, Oct 22, 2009 at 11:54 PM, Margie Roginski
 wrote:
>  They want to use
> an windows app called mwsnap to basically snap images from their
> desktop, then ctrl-v to copy the image into my django app.

is there any web app that does this?  AFAICT, all use some upload
button (maybe augmented with flash libraries, like the great one from
http://swupload.org/)

-- 
Javier

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: More than one stackedinline in admin

2009-10-23 Thread Karen Tracey
On Fri, Oct 23, 2009 at 8:24 AM, Caisys  wrote:

>
> I tried:
> 
> class child1Inline(admin.StackedInline):
>model = child1
>extra = 2
>
> class child2Inline(admin.StackedInline):
>model = child2
>extra = 2
>
> class child1Admin(admin.ModelAdmin):
>inlines = [child1Inline]
>
> class child2Admin(admin.ModelAdmin):
>inlines = [child2Inline]
>
>
> admin.site.register(model1, child1Admin, child2Admin)
> 
>
> You want to create a single ModelAdmin class for model1, specifying both
child1inline and child2inline, in its inlines attribute.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Replicating Google Groups in Django

2009-10-23 Thread Lakshman Prasad
You should use the lamson project, by Zed Shaw: http://lamsonproject.org/

On Fri, Oct 23, 2009 at 6:36 PM, Julien Phalip  wrote:

>
> Hi,
>
> On one site I'm considering the possibility of replicating the (basic)
> functionality of Google Groups in Django. The idea is:
>
> - There would be 5 different mailing lists. Users can subscribe to one
> or more lists.
> - People can purely use emails to access the lists.
> - All the emails can then also be seen via a web interface.
>
> I've been thinking of using Mailman to leverage all the email
> management part. But now I'm not sure how to reliably sync the Mailman
> subscription system with django.contrib.auth.
>
> I don't think there's any straight forward to do this. Would you have
> any advice to get me started?
>
> Thanks!
>
> Julien
> >
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Connecting to multiple db masters

2009-10-23 Thread dave

I've encountered the multiple database issue but with a twist.  I want
to propagate data across a dual master Oracle database setup which
seems to be a little different topic than the online discussions I've
seen.  In order to do this I want to pass the url for both domains to
Oracle as the connection string.  I've written code to make this work
but thought I'd get some input from this group as to whether this has
been done before and if not if my solution is the best approach.

I updated my local settings.py to contain a DATABASE_URL variable
which has the username, password and dsn of both domains.

DATABASE_URL = username/password@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=host1)(PORT=1234)))(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=host2)(PORT=1234)))(LOAD_BALANCE=yes)(CONNECT_DATA=
(SERVER=DEDICATED)(SID=test)))'

I added a method to the django\db\backends\oracle\base.py
DatabaseWrapper class.

def _connect_url(self):
settings_module = os.environ["DJANGO_SETTINGS_MODULE"]
mod = importlib.import_module(settings_module)
return mod.DATABASE_URL

And updated the existing _cursor method to call the new _connect_url
method.

conn_string = convert_unicode(self._connect_string())
if conn_string == '/@': # This means no connection string
information was found.
conn_url = convert_unicode(self._connect_url())
self.connection = Database.connect(conn_url,
**self.settings_dict['DATABASE_OPTIONS'])
else:
self.connection = Database.connect(conn_string,
**self.settings_dict['DATABASE_OPTIONS'])

This enables user to either use the existing functionality by
populating the existing 'DATABASE' variables, or they can comment out
the DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST,
and DATABASE_PORT in their settings.py and use the DATABASE_URL
instead.  Does this look like a feasible solution?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model design

2009-10-23 Thread chefsmart

I would go with your second solution.

On Oct 23, 5:17 pm, Caisys  wrote:
> Hi,
> I have classes for Event, Place and Subplace. Some of the Places are
> divided into different Halls (Subplace) and some have only one. I
> would like to know how design the relations between the classes.
>
> 1) Should I put two columns in the Event one FK to Place and another
> FK to Hall?
> 2) Should I create one FK only to Hall and create a record in Hall for
> every Place even if the Place has no Halls?
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Passing Parameter to form in inlineformset_factory

2009-10-23 Thread chefsmart

This is coming off untested, but with a couple of tweaks it should
work.

Try creating a dynamic class. In your views.py, do something like
this: -

def make_my_form(readonly):
class MyForm(forms.ModelForm):
  def __init__(self, *args, **kwargs):
  if readOnly:
 Do stuff to make the inputs readonly
return MyForm

Then in your view function where you create your inline formset, do
something like: -

def your_main_view_function(request):
#
#
#
passing_readonly = True
yourdynamicform = make_my_form(passing_readonly)
YourFormSet = inlineformset_factory(ModelA, ModelB ,
form=yourdynamicform)
#
#
#

On Oct 23, 4:30 am, Andew Gee  wrote:
> Hi,
>
> I have the following Form defined
>
> class MyForm(ModelForm)
>
>   def __init__(self, readOnly=False, *args, **kwargs):
>       if readOnly:
>          Do stuff to make the inputs readonly
>
> MyForm works perfectly when I instantiate it in the view as a form
> form = MyForm(readOnly=True, instance=ModelA)
>
> but when I try to use it in the inlineformset_factory I get the error
>
> NoneType object is not callable.
>
> I know the problem id the way I am using the MyForm in the inline call
> because I get the same error if I do either of the following
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm
> (readOnly=True))
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm())
>
> but it works if I do
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
>
> obviously the readOnly param defaults to False and my inputs are not
> changed.
>
> Does anyone know how I can pass the readOnly param to MyForm using the
> inlineformset_factory or how else I can achieve what I want?
>
> Thanks
> Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Replicating Google Groups in Django

2009-10-23 Thread Julien Phalip

Hi,

On one site I'm considering the possibility of replicating the (basic)
functionality of Google Groups in Django. The idea is:

- There would be 5 different mailing lists. Users can subscribe to one
or more lists.
- People can purely use emails to access the lists.
- All the emails can then also be seen via a web interface.

I've been thinking of using Mailman to leverage all the email
management part. But now I'm not sure how to reliably sync the Mailman
subscription system with django.contrib.auth.

I don't think there's any straight forward to do this. Would you have
any advice to get me started?

Thanks!

Julien
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Passing Parameter to form in inlineformset_factory

2009-10-23 Thread pjrhar...@gmail.com

Try using a lambda function. The problem is that the factory wants a
callable that creates a form, not a form instance (ie it wants to be
able to execute MyForm() for each form in the formset.

Formset = inlineformset_factory(ModelA, ModelB form=lambda: MyForm
(readOnly=True))

Note I've not tried this and never actually used formsets either!

On Oct 23, 12:30 am, Andew Gee  wrote:
> Hi,
>
> I have the following Form defined
>
> class MyForm(ModelForm)
>
>   def __init__(self, readOnly=False, *args, **kwargs):
>       if readOnly:
>          Do stuff to make the inputs readonly
>
> MyForm works perfectly when I instantiate it in the view as a form
> form = MyForm(readOnly=True, instance=ModelA)
>
> but when I try to use it in the inlineformset_factory I get the error
>
> NoneType object is not callable.
>
> I know the problem id the way I am using the MyForm in the inline call
> because I get the same error if I do either of the following
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm
> (readOnly=True))
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm())
>
> but it works if I do
>
> Formset = inlineformset_factory(ModelA, ModelB form=MyForm)
>
> obviously the readOnly param defaults to False and my inputs are not
> changed.
>
> Does anyone know how I can pass the readOnly param to MyForm using the
> inlineformset_factory or how else I can achieve what I want?
>
> Thanks
> Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: More than one stackedinline in admin

2009-10-23 Thread Caisys

I tried:

class child1Inline(admin.StackedInline):
model = child1
extra = 2

class child2Inline(admin.StackedInline):
model = child2
extra = 2

class child1Admin(admin.ModelAdmin):
inlines = [child1Inline]

class child2Admin(admin.ModelAdmin):
inlines = [child2Inline]


admin.site.register(model1, child1Admin, child2Admin)

On Oct 21, 3:45 pm, Daniel Roseman  wrote:
> On Oct 21, 2:42 pm, Caisys  wrote:
>
>
>
>
>
> > Hi,
> > Suppose i have 3 model classes:
> > 
> > class model1(model.Models):
> >     fields .
>
> > class child1(models.Model):
> >      model1 = models.ForeignKey(model1)
>
> > class child2(models.Model):
> >      model1 = models.ForeignKey(model1)
>
> > --
>
> > Is it possible to have child1 and child2 appear on the admin page of
> > model1 as StackedInline ??
>
> > Thanks
>
> Yes, it is. What happened when you tried?
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Interesting code abstraction Challenge

2009-10-23 Thread Jason Beaudoin

2009/10/23 kmike :
>
> Maybe you don't have enough information to make an abstraction right
> now. If so I suggest to actually implement several API's in a dumb
> way. After that it'll be clear what are the differences and what are
> the common parts so making a good abstraction will be easier.

I've implemented each of the APIs enough (standalone) to know a lot of
the differences. Where I'm struggling is envisioning the proper
abstraction and implementation with python / django code to tie it all
together.

My current idea is to setup a Request class, then create specific
subclasses of this, overriding the default methods, writing conversion
methods, and defining additional fields. But "seeing" the python code
around this has yet to come.

As I've never really implemented this type of abstraction (and I
imagine others have), I'm really interested in what has been done /
known solutions to the general problem / do I have the right idea /
any source folks can suggest / etc..

Thanks for taking the time to read about my situation!

~Jason

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Model design

2009-10-23 Thread Caisys

Hi,
I have classes for Event, Place and Subplace. Some of the Places are
divided into different Halls (Subplace) and some have only one. I
would like to know how design the relations between the classes.

1) Should I put two columns in the Event one FK to Place and another
FK to Hall?
2) Should I create one FK only to Hall and create a record in Hall for
every Place even if the Place has no Halls?

Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Underscores in PKs

2009-10-23 Thread Eugene Mirotin

I have an application working with legacy DB.
Some tables have humen-redable PKs, and some of them contain underscores.
Django admin escapes them (for what reason?) and seems not unescaping.
So these objects are unavailable for editing.
The relevant bug (2 years old!) is here:
http://code.djangoproject.com/ticket/1375
Unfortunately, the patch is too old and can't be applied since the
code has changed.
The biggest changes seem to be in the views/main.py file.

Did somebody encounter such a problem? What is the simplest solution?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django basic tests are failing

2009-10-23 Thread jamesM

This apparently is my bad, i've just created an empty project, and all
the tests of it pass. Am working on tracking down the problem.

On Oct 23, 1:29 pm, jamesM  wrote:
> Hi guys,
>
> i've decided to practice some test-driven development with django and
> bumped into some small problems.
> No idea is this a bug or my bad, but after running python manage.py
> test i get the two tests which fail (error below). Both of them
> expects unicode value, but receives a simple string. I'm using django
> trunk.
>
> I could try fix the Expected value to the one which is returned, but i
> guess that's not the best practice to start with:)
> Maybe anyone has any ideas how to make those tests pass?
>
> cheers!
> j
>
> 
> output of $python manage.py test
> 
>
> Creating test database...
> Creating table auth_permission
> Creating table auth_group
> Creating table auth_user
> Creating table auth_message
> Creating table django_content_type
> Creating table django_session
> Creating table django_site
> Creating table django_admin_log
> Creating table documents
> Installing index for auth.Permission model
> Installing index for auth.Message model
> Installing index for admin.LogEntry model
> FF.
> ==
> FAIL: Doctest: django.contrib.auth.tests.__test__.BASIC_TESTS
> --
> Traceback (most recent call last):
>   File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
> line 2180, in runTest
>     raise self.failureException(self.format_failure(new.getvalue()))
> AssertionError: Failed doctest test for
> django.contrib.auth.tests.__test__.BASIC_TESTS
>   File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> __init__.py", line unknown line number, in BASIC_TESTS
>
> --
> File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> __init__.py", line ?, in
> django.contrib.auth.tests.__test__.BASIC_TESTS
> Failed example:
>     u.email
> Expected:
>     u'@somewhere.org'
> Got:
>     '@somewhere.org'
> --
> File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
> __init__.py", line ?, in
> django.contrib.auth.tests.__test__.BASIC_TESTS
> Failed example:
>     u.password
> Expected:
>     u'!'
> Got:
>     '!'
>
> ==
> FAIL: Doctest: django.contrib.sites.tests
> --
> Traceback (most recent call last):
>   File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
> line 2180, in runTest
>     raise self.failureException(self.format_failure(new.getvalue()))
> AssertionError: Failed doctest test for django.contrib.sites.tests
>   File "/usr/lib/python2.5/site-packages/django/contrib/sites/
> tests.py", line 0, in tests
>
> --
> File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
> line 21, in django.contrib.sites.tests
> Failed example:
>     site.name
> Expected:
>     u"example.com"
> Got:
>     'example.com'
> --
> File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
> line 27, in django.contrib.sites.tests
> Failed example:
>     site.name
> Expected:
>     u"Example site"
> Got:
>     'Example site'
>
> --
> Ran 35 tests in 21.128s
>
> FAILED (failures=2)
> Destroying test database...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django basic tests are failing

2009-10-23 Thread jamesM

Hi guys,

i've decided to practice some test-driven development with django and
bumped into some small problems.
No idea is this a bug or my bad, but after running python manage.py
test i get the two tests which fail (error below). Both of them
expects unicode value, but receives a simple string. I'm using django
trunk.

I could try fix the Expected value to the one which is returned, but i
guess that's not the best practice to start with:)
Maybe anyone has any ideas how to make those tests pass?

cheers!
j


output of $python manage.py test


Creating test database...
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table documents
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
FF.
==
FAIL: Doctest: django.contrib.auth.tests.__test__.BASIC_TESTS
--
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
line 2180, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for
django.contrib.auth.tests.__test__.BASIC_TESTS
  File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
__init__.py", line unknown line number, in BASIC_TESTS

--
File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
__init__.py", line ?, in
django.contrib.auth.tests.__test__.BASIC_TESTS
Failed example:
u.email
Expected:
u'j...@somewhere.org'
Got:
'j...@somewhere.org'
--
File "/usr/lib/python2.5/site-packages/django/contrib/auth/tests/
__init__.py", line ?, in
django.contrib.auth.tests.__test__.BASIC_TESTS
Failed example:
u.password
Expected:
u'!'
Got:
'!'


==
FAIL: Doctest: django.contrib.sites.tests
--
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/test/_doctest.py",
line 2180, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for django.contrib.sites.tests
  File "/usr/lib/python2.5/site-packages/django/contrib/sites/
tests.py", line 0, in tests

--
File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
line 21, in django.contrib.sites.tests
Failed example:
site.name
Expected:
u"example.com"
Got:
'example.com'
--
File "/usr/lib/python2.5/site-packages/django/contrib/sites/tests.py",
line 27, in django.contrib.sites.tests
Failed example:
site.name
Expected:
u"Example site"
Got:
'Example site'


--
Ran 35 tests in 21.128s

FAILED (failures=2)
Destroying test database...

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Caching performance regression between django 1.0 and django 1.1.1

2009-10-23 Thread mt



On Oct 22, 1:46 pm, Russell Keith-Magee 
wrote:
> On Thu, Oct 22, 2009 at 4:38 PM, mt  wrote:
>
> > On Oct 19, 1:08 pm, Russell Keith-Magee 
> > wrote:
> >> On Mon, Oct 19, 2009 at 6:52 PM, mt  wrote:
>
> >> > Hi All,
> >> > I recently upgraded a high traffic site from django 1.0 to django
> >> > 1.1.1 and noticed that the load on the server went through the roof,
> >> > so I had to revert to django 1.0.
> >> > I've done some testing and noticed that the caching behaviour between
> >> > 1. 0 and 1.1.1 has changed.
> >> > Basically I was caching expensive database queries using memcached, in
> >> > django 1.0 reading from the cache is a fast operation however in
> >> > django 1.1.1 reading from cache causes all fields with a callable as
> >> > default to be called.
> >> > In the case where that callable is an expensive operation the
> >> > performance is severely affected.
> >> > I've created patches showing this regression for the branches
> >> >http://code.djangoproject.com/svn/django/branches/releases/1.0.X
> >> > and
> >> >http://code.djangoproject.com/svn/django/branches/releases/1.1.X
> >> > which shows the default callable being called on cache read.
>
> >> > My questions are:
> >> > 1. Is it wrong to store querysets in the cache?
>
> >> Strictly, a queryset doesn't contain *any* data - it's just a
> >> programatic representation of a SQL query. So, putting a queryset in
> >> the cache doesn't inherently mean that anything is being stored.
> >> However, if the queryset has been evaluated, there might be something
> >> in the queryset's internal result cache, and *that* value will be
> >> returned when the value is retrieved from the cache.
>
> >> > 2. Should I log a bug for this in the django tracker and upload my
> >> > test case patches?
>
> >> Certainly.
> > Hi Russell,
> > I've found the cause of the performance regression and have suggested
> > a patch on ticket 12057 (http://code.djangoproject.com/ticket/12057)
> > The patch runs without causing any other tests to fail in the django
> > tree.
> > Do you think this patch could have other side effects or is it OK?
>
> First off - the test case is awesome - that helps a lot.
>
> As for the fix: there's a much easier solution - on line 356 of
> django/db/models/base.py, replace the current implementation:
>
> return (self.__class__, (), data)
>
> with an implementation that essentially reverts to the underlying
> implementation of __reduce__:
>
> return super(Model, self).__reduce__()
>
> You can see the underlying problem if you inspect super().__reduce__,
> and compare it to the current return value.
>
> As a result, I suspect that an analogous problem will exist for any
> model with deferred fields. I'll need to confirm this before I commit
> the fix. If you can spare any time to look into this, I'd be much
> obliged.
Hi Russell,
Thanks for taking the time to look at this.
Your solution is much more elegant and the test case passes using your
change to base.py.
With regard to models with deferred fields your suspicions are
correct.
I added a new test case for models with deferred fields (http://
code.djangoproject.com/attachment/ticket/12057/
prevent__init__on_pickle_load.patch) to test querysets that use
defer.
This test currently fails when I:
cd django (root directory that contains tests folder)
echo "DATABASE_ENGINE = 'sqlite3'" > settings.py
PYTHONPATH=`pwd`:$PYTHONPATH ./tests/runtests.py --settings=settings -
v1 cache

Thanks
Michael
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Design decision

2009-10-23 Thread Léon Dignòn

callerlist will MAYBE use a database of another program (not django),
or it uses a database of another django application. This is optional
and I want callerlist to work with or without. For that i decided to
create an application customerlist and develop a model Customer and an
optional interface for any existing crms. customerlist will either use
an own model for the crm, or a database of a completely different
software. To have the callerlist coherent I included a customer-field
in the PhoneCall model wich should ot throw an error if the
customerlist application is not installed.

Now I have the following model in the app callerlist with a foreign
key customer_crm to the optional crm application.

class PhoneCall(models.Model):
user = models.ForeignKey(auth.models.User)
caller_name = models.CharField(...)
customer_crm = models.ForeignKey(customerlist.models.Customer)

If I don't want install the customerlist, model PhoneCall throws an
error, of course! How would I best change the application callerlist
to recognize whether customerlist is installed or not, and use the
customer_crm field or not. Both applications have to be coherent and
work properly alone.

Any ideas?




On 16 Okt., 21:11, Chip Grandits  wrote:
> I'm not sure if there is an exact technical defintion of the term
> 'bind' here. I am assuming you will need the two applications to
> share a common database? And I am assuming that other application has
> already been developed and
> deployed and so you are inclined to work around it?
>
> So this becomes more of a database question, and might be
> particular to the particular database engine in use.  I hope it is
> clear that you do NOT have to use a database that is created
> with the manage.py syncdb command; although you must have
> a database that is compatible with one that is created by that
> command - but it can be a 'superset' of that database.
>
> My guess is that you might need to know a little bit about the
> command line interface of the database engine (I doubt you
> need to be a "power user")  And then brush up on the
> manage.py database subcommands (dumpdata, inspectdb,
> and various sql*) and that will help clarify a solution path.
>
> -Chip
> On Oct 16, 10:10 am, Léon Dignòn  wrote:
>
>
>
> > I have a project. Within that project I have the app callerlist.
> > Callerlist is a list of either inbound or outbound phone calls. To
> > each phone call the following information should be written down: own
> > name, name of the caller, subject, message and time. This app has to
> > be coherent.
>
> > Now, for example, I want to bind the above app to an crm system or
> > another application with customer data. I am not sure which is the
> > best way to provide that interface. Should I provide an additional
> > field as a foreign key to the customer table? The table could be
> > defined via a variable in the settings.py.
>
> > Or are there better solutions?
>
> > ld- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Interesting code abstraction Challenge

2009-10-23 Thread kmike

Maybe you don't have enough information to make an abstraction right
now. If so I suggest to actually implement several API's in a dumb
way. After that it'll be clear what are the differences and what are
the common parts so making a good abstraction will be easier.

On 23 окт, 11:06, Jason Beaudoin  wrote:
> Why hello there,
>
> I have been thinking over this system design for quite a while now,
> and I'm still a bit unsure of the sensible way to properly (and
> sufficiently) abstract the system - the django-way, so to speak. I am
> very interested in what other folks have to say - maybe I have been
> thinking about this too much, maybe I haven't crossed paths with the
> techniques you would use, but I imagine that while a little
> challenging, this is still a common situation.
>
> Please share your crazy, genius ideas, reading tips, code snippets, etc  : )
>
> Here is the general setup:
>
> Client Servers <---> The Application in Question <---> Partner Applications
>
> The main role of the webapp is to serve as a proxy application to many
> other partner web applications - we receive requests from client
> servers, work out the processing with one or more of our partner
> applications, and return the results to the client server. All data
> communication is done via predefined APIs, and each API is different..
> we define the API our client servers use to send/receive requests to
> us, we follow the APIs as defined by our partners to communicate with
> their applications. In this way, our client servers are connected to
> many similar applications through our one webapp.
>
> Several baseline "rules", if you will:
>
>  - The application receives specially formatted requests for
> processing (via POSTs).
>  - As stated, all requests are formatted as defined by our, or our
> partner, APIs.
>  - All incoming requests will need to be re-formatted before passing
> on, as each API is different.
>  - Some communication is handled via passing XML around, others aren't.
>  - A few situations require additional user interaction
>
> The Challenge, or Where I'm caught up:
>
> The end points are easy, as the APIs need to be followed.
> Re-formatting a request from our API to a partner's - and vice versa -
> isn't really a problem either.. (if I wanted to do this the crappy
> way, this could be written out for each conversion, but there are 10 -
> 20 conversions). The challenge I am trying to figure out is how to
> abstract the re-formatting process to eliminate code duplication, as
> our API and each partner API will be similar (in an abstract way).
>
> What's difficult is that each API is different enough that it isn't a
> straight up a --> b field name translation, the conversion mechanism
> has to be pretty dynamic. To put specifics on it, differing field
> names are one thing, but the APIs differ in the information they
> require (field types, so to speak) - for example: additional fields
> for some APIs, or a field in one API may be a combination of others in
> another API, etc.
>
> What I have in mind so far:
>
>  - For each partner, define the list of fields required
>  - Define translations for each field, with 3 parts: our field name
> (or data source), the partner's field name, and a translation function
> (with the appropriate conversion algorithm if necessary).
>  - When a partner has a field that doesn't have an equivalent in our
> system, define a function for generating the field's value.
>  - Once we've converted the information, format the data as either XML
> or ready for a URLencode to POST
>
> Questions:
>
> Am I on the right track here?
> Should I be thinking about this differently?
> How do I tie these translations into a generic process, with generic
> code, leaving the specifics to these translation functions?
> How the hell would you set this up? Even if I'm on the right path
> here, I'm having difficulty envisioning the python code behind all of
> this..
>
> All ideas, feedback, input, comments, etc welcome!!
>
> Regards,
>
> ~Jason
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Advantages of using ManyToManyField(Bar, through='Foo_Bar') syntax vs not declaring a ManyToManyField at all

2009-10-23 Thread Monika Sulik

Thanks :)

On Oct 22, 5:52 pm, Tom Evans  wrote:
> On Thu, 2009-10-22 at 07:57 -0700, Monika Sulik wrote:
> > Hi,
>
> > I was wondering what exactly are the advantages of having code like
> > this:
>
> > class Foo (models.Model):
> >     bar_m2m = models.ManyToManyField(Bar,through='Foo_Bar')
>
> > class Bar (models.Model):
> >     pass
>
> > class Foo_Bar (models.Model):
> >     foo = models.ForeignKey(Foo)
> >     bar = models.ForeignKey(Bar)
> >     x = models.IntegerField()
>
> > over having the same code, but having the Foo class like so:
>
> > class Foo (models.Model):
> >     pass
>
> > In both cases I can use foo.foo_bar_set and bar.foo_bar_set (assuming
> > foo is a Foo Object and bar is a Bar Object). Why would I need the
> > bar_m2m variable?
> > I'm probably missing something pretty obvious, but if someone could
> > point out the answer to me that would be great :)
>
> > Monika
>
> With a many to many with a through table, you can either go directly to
> the other end of the relationship, or look at the through table. Without
> it, you cannot look directly at the relationship, only at the link.
>
> Eg, Users can be in many UserGroups and UserGroups can have many Users.
> If I use a m2m relationship with a through table, I can do both these
> things:
>
> class UserGroup(models.Model):
>   users=ManyToManyField(User, through='UserUserGroupPreferences')
>
> class UserUserGroupPreferences(models.Model):
>   user=models.ForeignKey('User')
>   usergroup=models.ForeignKey('UserGroup')
>   is_group_super_user=models.BooleanField(default=False)
>
> u=User.objects.get(...)
> # I can see directly which groups a user is in
> u.usergroup_set.all()
> # I can also examine things about a particular user -> group association
> u.userusergrouppreferences_set.filter(is_group_super_user=True)
>
> Without the m2m field, I wouldn't be able to go directly to the
> usergroup from the user, I would only be able to go via the through
> table.
>
> Cheers
>
> Tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Queryset inspection in models.Manager not possible without breaking

2009-10-23 Thread Gerard

Matias,

Thanx for your response. After having decided, for research sake, to apply 
the security in my views and see what the impact is I get run down on way to 
many places. All the great intelligence that Django has starts to get 
useless in my setup. E.g. when auto populating dropdown lists in Modelforms, 
then also the objects not allowed are show up.

This actually brings me to a whole different question. Wouldn't it be easier 
instead of an owner attrib on the models, to start giving the modelnames a 
username or userid prefix. In database terms my tables would be named 
[userid]_customers. That way i can still benefit from Django's intelligence. 
Another issue that comes to mind however is that it wont be easy (or 
possible) to seemlessly set up new users, since my app needs to have 
models(tables) setup on the fly.

I realise that the topic got way to big all of a sudden, I do hope though 
that you give me some pointers as to multi-user setups.

Thanx a lot.

Kind regards,

Gerard.

Matías Costa wrote:
> On Fri, Oct 23, 2009 at 9:25 AM, Gerard  wrote:
>> Hi All,
>>
>> I'm trying to find a way to filter on a certain field (myowner) in my views.
>> If the field in the returned queryset is not unique then raise an exception.
>> The code in my manager:
>>
>> class UserFilteredManager(models.Manager):
>>
>> def get_query_set(self):
>> FullQuerySet = super(UserFilteredManager, self).get_query_set()
>>
>> if FullQuerySet.aggregate(Count('myowner'))['myowner__count'] > 1:
>> raise Exception('Ouch, multiple owners received')
>> else:
>> return FullQuerySet
>>
>> The result I'm aiming for is that this works as normal:
>>
>> customers = Customer.objects.filter(myowner=request.user)
>>
>> And that this raises the exception:
>>
>> customers = Customer.objects.all()
> 
> 
> This is not the way because get_query_set returns the equivalent of
> 'select * from ...'. And this would break the lazyness, because it is
> evaluated on every access to the model. This can bring the db to its
> kness easy.
> 
> I think you should go down the layer a bit, and capture the evaluation
> at the Query level:
> 
> class OwnerCheckedQuery(models.Query):
> def _fill_cache(self, num=None):
>  if self.aggregate(Count('myowner'))['myowner__count'] > 1:
>  raise Exception('Ouch, multiple owners received')
>  else:
>  return super(models.Query, self)._fill_cache(num)
> 
> class UserFilteredManager(models.Manager):
> def get_query_set(self):
> return OwnerCheckedQuery(self.model)
> 
> 
> So the check is done after client code has done all its filters
> 
>> As you probably guessed, I'm working on row level security. I could ofcourse
>> do this in my views but it feels to fragile. One error on my side can return
>>  in people seeing confidential information.
> 
> There are various obvious way to bypass this method. But it is a easy
> solution and breaking the rules requires conscious effort. So the
> balance is OK for me. To be absolute sure, you should do it at DB
> level? I do not really know.
> 
>> I have two questions.
>>
>> - Why doesn't the queryset inspection work as I intented?
>> - Where else could I force such a requirement in a generic way?
>>
>> Thanx a lot.
>>
>> Gerard.
>>
>> --
>> self.url = www.gerardjp.com
>>
> 
> > 


-- 
self.url = www.gerardjp.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Queryset inspection in models.Manager not possible without breaking

2009-10-23 Thread Matías Costa

On Fri, Oct 23, 2009 at 9:25 AM, Gerard  wrote:
>
> Hi All,
>
> I'm trying to find a way to filter on a certain field (myowner) in my views.
> If the field in the returned queryset is not unique then raise an exception.
> The code in my manager:
>
> class UserFilteredManager(models.Manager):
>
>     def get_query_set(self):
>         FullQuerySet = super(UserFilteredManager, self).get_query_set()
>
>         if FullQuerySet.aggregate(Count('myowner'))['myowner__count'] > 1:
>             raise Exception('Ouch, multiple owners received')
>         else:
>             return FullQuerySet
>
> The result I'm aiming for is that this works as normal:
>
>     customers = Customer.objects.filter(myowner=request.user)
>
> And that this raises the exception:
>
>     customers = Customer.objects.all()


This is not the way because get_query_set returns the equivalent of
'select * from ...'. And this would break the lazyness, because it is
evaluated on every access to the model. This can bring the db to its
kness easy.

I think you should go down the layer a bit, and capture the evaluation
at the Query level:

class OwnerCheckedQuery(models.Query):
def _fill_cache(self, num=None):
 if self.aggregate(Count('myowner'))['myowner__count'] > 1:
 raise Exception('Ouch, multiple owners received')
 else:
 return super(models.Query, self)._fill_cache(num)

class UserFilteredManager(models.Manager):
def get_query_set(self):
return OwnerCheckedQuery(self.model)


So the check is done after client code has done all its filters

> As you probably guessed, I'm working on row level security. I could ofcourse
> do this in my views but it feels to fragile. One error on my side can return
>  in people seeing confidential information.

There are various obvious way to bypass this method. But it is a easy
solution and breaking the rules requires conscious effort. So the
balance is OK for me. To be absolute sure, you should do it at DB
level? I do not really know.

> I have two questions.
>
> - Why doesn't the queryset inspection work as I intented?
> - Where else could I force such a requirement in a generic way?
>
> Thanx a lot.
>
> Gerard.
>
> --
> self.url = www.gerardjp.com
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Queryset inspection in models.Manager not possible without breaking

2009-10-23 Thread Gerard

Hi All,

I'm trying to find a way to filter on a certain field (myowner) in my views. 
If the field in the returned queryset is not unique then raise an exception. 
The code in my manager:

class UserFilteredManager(models.Manager):

 def get_query_set(self):
 FullQuerySet = super(UserFilteredManager, self).get_query_set()

 if FullQuerySet.aggregate(Count('myowner'))['myowner__count'] > 1:
 raise Exception('Ouch, multiple owners received')
 else:
 return FullQuerySet

The result I'm aiming for is that this works as normal:

 customers = Customer.objects.filter(myowner=request.user)

And that this raises the exception:

 customers = Customer.objects.all()

As you probably guessed, I'm working on row level security. I could ofcourse 
do this in my views but it feels to fragile. One error on my side can return 
  in people seeing confidential information.

I have two questions.

- Why doesn't the queryset inspection work as I intented?
- Where else could I force such a requirement in a generic way?

Thanx a lot.

Gerard.

-- 
self.url = www.gerardjp.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: If search string contains a number ... Do this ...

2009-10-23 Thread Grant Livingston
What about using pythons regular expression module (re) ? Example,
if re.search("\d", "Search query 2 search"):
# Do this.
else:
# Do this instead.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---