Empty foreign keys in forms after Apache/PostgreSQL reset

2010-05-04 Thread Xanthus
Hi all. I will try do my best to explain my setup and the sequence of
actions triggering the issue:

1. Machine starts and all is fine.
2. We do the following operations (through and automated script):
a. stop Apache
b. stop Postgresql
c. drop database
d. create database again
e. restore database from a versioned backup
f. remove the application *.pyc files
g. start Postgresql
h. start Apache
3. We log in again and we see that the foreign key fields in all the
forms who have them are empty. In the admin change forms the foreign
keys fields are filled correctly. If we restart Apache a few times
(random) the problem fixes itself.

Setup: django 1.2beta1, PostgresSQL 8.4, Apache 2.2.12, application
served by mod_wsgi, operating system Ubuntu Linux 9.10 server edition,
Python 2.6.4

Notes: all the models are using a custom model manager (1) who uses
threadlocals to get the current authenticated user and do extra
filtering. If we remove the use the extra filtering using threadlocals
the problem doesn't happen.

(1) http://dpaste.com/hold/191037/

Any hints or pointers to debug the problem? Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Working out some custom API stuff

2010-05-04 Thread Nick
Here's the deal. I'm working on a custom API for moving information
about. I am stuck at a point in creating my view.
It might be best just to get into the details.

Here is the model:


class entry(models.Model):
question = models.CharField('Question', max_length=200,
blank=False)
answer = models.TextField('Answer', blank=False)
answerer = models.CharField("Expert's Name", max_length=100,
blank=False)
credentials = models.CharField ("Expert's Credentials",
max_length=100, blank=False)
published  = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
site = models.ForeignKey(Site)
section = TagField()

Once a site is picked the feed is narrowed down by id (whether single
id, list or range), then by section (single or multiple) and finally
some pagination and count params (I'm not worried about that right
now). Currently, I am stuck on the section portion. I may be going
about this all wrong. What I would like is for some URL like:

http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME

to produce a JSON output of Questions and Answers under that site with
that section name. Here is my view:


def QandAAPI(request, site):
quest = entry.objects.filter(site__name__icontains=site)
if 'id' in request.GET:
id = request.GET.get('id','')
id = id.split(',')
else:
id = quest.values_list('id', flat=True)
if 'sect' in request.GET:
sect = request.GET.get('sect','')
else:
sect = ''
quest = quest.filter(id__in=id, section=sect)
object = serializers.serialize("json", quest)
json = "%s" % object
return HttpResponse(json)

Basically, I would like the "else: sect=" to be a WILDCARD so if the
sect portion of the API isn't explicitly stated then it just pulls
everything.

What do you think? Raw SQL? I'm a complete bonehead? All opinions/
advice are welcome.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Equivalent of php json_encode?

2010-05-04 Thread Streamweaver
I've found the native Python JSON library about the easiest to use out
there.

http://docs.python.org/library/json.html


On May 4, 10:34 am, zweb  wrote:
> Is there a django or python equivalent of php json_encode?
>
> the data I am converting to json has text fields that have quotes,
> double quotes, newlines and html tags. Creating json manually in my
> program without escaping or converting these special characters is
> causing problem on javascript side.
>
> A php programmer suggested I use equivalent of php json_encode.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



heads up

2010-05-04 Thread darren
I thought I would pass this along in case it helps anyone.

A recent update on my Mac broke my python symlink.  I have my
/usr/bin/python pointing to /usr/local/bin/python2.6 via a symlink.  My
modules are located in /usr/local/lib/python2.6.  If you are experiencing a
problem with importing modules after a mac update, check you python path.
You will know if you are having that problem if you see this in your apache
error log:

TemplateSyntaxError: Caught ImportError while rendering: No module named



HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: add button to admin change list at row level.

2010-05-04 Thread Wayne
Thanks for your hint. It worked out pretty well.

Wayne

On May 2, 4:06 am, Daniel Roseman  wrote:
> On May 2, 4:29 am, Wayne  wrote:
>
> > Hi,
>
> > We are trying to customize Django admin change list displaying model
> > objects. We want to add two buttons (Change, delete) to each row of
> > the record, something very similar to "Add" and "Change" buttons on
> > application list beside the model name. Could somebody give us some
> > hint on this? The "list_display" can only take existing fields, but
> > not the extra buttons we want to add, right? We do not want to provide
> > user with batch admin actions option. That is why we want to add
> > action to each row.  Drop down actions menu is not our design
> > preference.
>
> > Thanks for your help.
>
> > Wayne
>
> The docs explain how you can use arbitrary ModelAdmin methods in
> list_display, which will do what you 
> want.http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#django.contri...
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 change urls for model in admin?

2010-05-04 Thread Wayne
Hi,

I am looking for the answer as well. I came across this tutorial with
some sample code. 
http://lincolnloop.com/assets/Customizing_the_Django_Admin-EuroDjangoCon09.pdf
page 59.

However, I don't want to create new view, but just modify the display
urls. So if somebody could give any hint, that would be great.

Thanks,

Wayne

On May 4, 4:23 am, akonsu  wrote:
> hello,
>
> by default an admin url for a model looks like this:
>
> http:///admin///...
>
> is there a way to change it? for different models i need to have
> different url structure. say, i want to replace "/admin/ name>" with something else.
>
> ModelAdmin.get_urls()? the documentation is not very helpful for me. i
> do not understand how i can use get_urls(). in particular, i do not
> have any custom views in my admin. and the docs only explain how to
> use get_urls() to hook up views.
>
> thanks for any help
> konstantin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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-grappelli issue

2010-05-04 Thread Tran Cao Thai
It works. Thank you very much.

On Mon, May 3, 2010 at 2:21 AM, Scot Hacker  wrote:

> On May 1, 10:12 pm, Tran Cao Thai  wrote:
> > I discovered the grappelli app today and just set up it. However, the
> admin
> > site doesn't look as good as the screenshot from the site. Here is the
> > screenshot of my admin page
> >
> > http://i979.photobucket.com/albums/ae280/jasonvoorheeszzz/Capture.png
> >
>
> This is what happens to Grappelli when you set your media directory
> correctly (the CSS is being found) but you haven't yet added the
> Grappelli templates directory to your TEMPLATES tuple in settings.
>
> ./s
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Trouble with multi-db test suite.

2010-05-04 Thread Russell Keith-Magee
On Wed, May 5, 2010 at 1:43 AM, J. Cliff Dyer  wrote:
> I'm having trouble working with multi-db using mysql replication.  When
> I run our test suite, I'm getting several hundred errors if I have more
> than one database configured, and none if I have only one configured.
>
> It seems that something isn't getting properly cleared out between test
> cases, so duplicate objects are getting created.
>
> My DATABASES setting looks like this:
>
>
> DATABASES = {
>    'default': {
>        'ENGINE': 'django.db.backends.mysql',
>        'HOST': 'jellyroll',
>        'NAME': 'ee',
>        'USER': 'ee',
>        'PASSWORD': 'ee',
>        'OPTIONS': {
>            'init_command': 'SET storage_engine=INNODB',
>            'charset' : 'utf8',
>            'use_unicode' : True,
>        },
>    },
>    'replicant0': {
>        'ENGINE': 'django.db.backends.mysql',
>        'HOST': 'jellyroll-rep0',
>        'NAME': 'test',
>        'USER': 'ee',
>        'PASSWORD': 'ee',
>        'TEST_MIRROR': 'default',
>        'OPTIONS': {
>            'init_command': 'SET storage_engine=INNODB',
>            'charset' : 'utf8',
>            'use_unicode' : True,
>        },
>    },
> }
>
>
> My router looks like this:
>
> class PrimaryReplicantRouter(object):
>    """Set up routing with one primary database, and zero or more
>    replicant databases."""
>
>    db_list = settings.DATABASES.keys()
>    primary_db = 'default'
>    replicant_db_list = [x for x in db_list if x != primary_db]
>
>    def db_for_read(self, model, **hints):
>        try:
>            return random.choice(self.replicant_db_list)
>        except IndexError:
>            return self.primary_db
>
>
>    def db_for_write(self, model, **hints):
>        """Write to the Primary DB"""
>        return self.primary_db
>
>    def allow_relation(self, obj1, obj2, **hints):
>        """Allow a relationship between any two objects in the db
>        pool"""
>
>        if (obj1._state.db in self.db_list
>            and obj2._state.db in self.db_list):
>            return True
>        return None
>
>    def allow_syncdb(self, db, models):
>        """All writes go to the primary db."""
>        return db == self.primary_db
>
> The first error that comes out of the test suite is a duplicate username
> in auth during a testcase's setUp, which makes it look like the object
> is getting created on one test pass, and then created again the next
> time around without deleting it properly:
>
>
> $ ./manage.py test --failfast
> .E
> ==
> ERROR: Regressiontest for #12462
> --
> Traceback (most recent call last):
>  File
> "/home/cliff/projects/lr-mdb/lexilereader/web/../contrib/django/contrib/auth/tests/auth_backends.py",
>  line 14, in setUp
>    User.objects.create_user('test', 't...@example.com', 'test')
> ...
> IntegrityError: (1062, "Duplicate entry 'test' for key 2")
>
>
> Any ideas what's going wrong?

I can't say I've seen this problem myself. Some more details might
help narrow down the problem:

 * Is your test case marked as a multidb test? (i.e., multidb=True on
the test case itself)

 * Can you describe your database configuration in more detaill?
Specifically, when the test framework creates the test database
(presumably on 'jellyroll') does a slave also get created
automatically? Is the test slave automatically paired to the test
master?

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-us...@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: error in urls.py

2010-05-04 Thread andy saksena
Thanks that resolved.


On May 3, 5:41 pm, Daniel Roseman  wrote:
> On May 3, 8:27 am,andysaksena  wrote:
>
>
>
> > Hi
>
> > my urls.py is
>
> > from django.conf.urls.defaults import *
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns(”,
> > # Example:
> > # (r’^/’, include(‘.foo.urls’)),
> > (r’^accounts/’, include(‘registration.backends.default.urls’)),
> > # Uncomment the admin/doc line below and add
> > ‘django.contrib.admindocs’
> > # to INSTALLED_APPS to enable admin documentation:
> > # (r’^admin/doc/’, include(‘django.contrib.admindocs.urls’)),
> > #(r’^accounts/’, include(‘.newapp.urls’)),
> > # Uncomment the next line to enable the admin:
> > (r’^admin/’, include(admin.site.urls)),
> > (r’^accounts/register/$’,register,
> > {‘form_class’:RegistrationForm,’profile_callback’:UserProfile.objects.profi 
> > le_callback},name
> > = ‘registration_register’),
> > )
>
> > but when I try looking under accounts/register I get this error
> > “”
> > SyntaxError at /accounts/logout/
>
> > (‘invalid syntax’, (‘/home/andy/src/python/django//..//
> > urls.py’, 17, 132, ” (r’^accounts/register/$’,register,
> > {‘form_class’:RegistrationForm,’profile_callback’:UserProfile.objects.profi 
> > le_callback},name
> > = ‘registration_register’),\n”))
>
> > “”
>
> > Can anyone help me with this.
> > Thanks in advance
> >Andy
>
> As the error message says, you've got an obvious syntax error - a
> space in 'profi le_callback'. But when you fix this, you'll still have
> a problem, because you aren't importing UserProfile anywhere, so
> you'll get a NameError.
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Error with django-registration

2010-05-04 Thread andy saksena
Resolved
Thanks for the help.

On May 3, 2:07 pm, andy saksena  wrote:
> Thats been resolved James but there is another thing I'm having
> problems with and I'm sorry for asking so many questions.
> All I now want is to have a minimum of 6 characters in the password
> field.
> Thanks
>
> On May 3, 8:52 am,andysaksena  wrote:
>
>
>
> > Hi James,
> > I got that smtp problem fixed by using gmail email function. But when
> > it sends an activation key and I click it it takes me to failure
> > message saying activation failed. and the account doesnt activates.
> > whats going wrong.
> > what can i do to fix this.
>
> > On Apr 28, 5:10 pm, James Bennett  wrote:
>
> > > On Wed, Apr 28, 2010 at 2:46 AM,andysaksena  
> > > wrote:
> > > > (111, 'Connection refused')
>
> > > As a Google search would have told you, this is the error Python's
> > > smtplib module will raise when you tell it to connect to a mail server
> > > and it can't. Which means you need to go double-check the settings
> > > you've given toDjangofor sending email (as covered in theDjango
> > > documentation:http://docs.djangoproject.com/en/1.1/topics/email/) to
> > > make sure you've provided the correct information for the server
> > > you're sending mail through.
>
> > > --
> > > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > > correct."
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Djangousers" group.
> > > To post to this group, send email todjango-us...@googlegroups.com.
> > > To unsubscribe from this group, send email 
> > > todjango-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



AdminField Rendering Question

2010-05-04 Thread geraldcor
Hello all,

I have been pouring over the django source trying to figure out where
the "Currently: "/images/..."" gets added to ImageField upload fields
after an image has been uploaded in the admin interface. I wonder this
because I would like to do some custom manipulation with the image
field and as I was searching for how to do this I just couldn't find
anything about how any form fields are rendered for that matter. I
understand how they are constructed and how the template is rendered
but I can't for the life of me figure out how the actual field is
rendered and represented in the html form. Could anyone please offer
me some insight into this. I really love the "Currently:" that shows
up and I would like to see how it's done.

Thank you for helping out a very confused person.

Greg.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: LOCALE_PATHS in settings.py required?

2010-05-04 Thread janedenone
On 4 Mai, 17:25, Baurzhan Ismagulov  wrote:
> On Tue, May 04, 2010 at 08:10:18AM -0700, janedenone wrote:
> > according to
>
> >http://docs.djangoproject.com/en/1.1/howto/i18n/
>
> > Django automatically looks for localizations in $PROJECTPATH/locale/
> > /LC_MESSAGES/django.(po|mo). When I installed language files
> > in this location, however, they were found only after I added
> > LOCALE_PATHS to settings.py.
>
> Hmm, this works for me with 1.0 and without LOCALE_PATHS. You do have
> .mo files, don't you?

Yes.

> I'd read Django sources or strace the web server
> to find out what goes wrong.

I found the problem: I created $PROJECTPATH/conf/locale/... instead of
$PROJECTPATH/locale/...

Sorry for wasting your time, and thanks again for your help,
Jan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Password reset email not sent

2010-05-04 Thread Shawn Milochik
I don't know why your e-mail isn't being sent, but I know that if multiple User 
instances have the same e-mail address, then that e-mail address will receive 
one message per User. Each one will specify the username, so it's easy to reset 
the correct password.

Shawn


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Password reset email not sent

2010-05-04 Thread janedenone
Hi,

when using Django's password reset mechanism, the confirmation email
is not sent (although some of my custom views do send email
successfully using the SMTP configuration from settings.py).

Also, I understand that the reset link in the email contains the user
ID, but it is based on the email address provided earlier. At the same
time, the User model's email field is not unique – so how does Django
know which password should be reset if two or more users happen to
have the same email address?

Kind regards,
Jan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: change an object from parent to child

2010-05-04 Thread Shawn Milochik
You can't subclass an instance, just a class/object.

Maybe you want a foreign key to place in restaurant.

What are you trying to do?

Shawn


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.distinct and aggregates

2010-05-04 Thread Wedg
Hrm... didn't quite work...

In [18]: Alpha.objects.filter(gamma__beta__name='Beta').values('name')
Out[18]: [{'name': u'Alpha'}, {'name': u'Alpha'}]

In [19]:
Alpha.objects.filter(gamma__beta__name='Beta').values('name').annotate(subtotal=models.Sum('id'))
Out[19]: [{'subtotal': 2, 'name': u'Alpha'}]

In [24]:
Alpha.objects.filter(gamma__beta__name='Beta').values('name').annotate(subtotal=models.Sum('id')).aggregate(total=models.Sum('subtotal'))
---
DatabaseError Traceback (most recent call
last)

/#snip#/ in ()

/usr/local/lib/python2.6/dist-packages/django/db/models/query.pyc in
aggregate(self, *args, **kwargs)
311 is_summary=True)
312
--> 313 return query.get_aggregation(using=self.db)
314
315 def count(self):

/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.pyc
in get_aggregation(self, using)
364 query.related_select_fields = []
365
--> 366 result = query.get_compiler(using).execute_sql(SINGLE)
367 if result is None:
368 result = [None for q in
query.aggregate_select.items()]

/usr/local/lib/python2.6/dist-packages/django/db/models/sql/
compiler.pyc in execute_sql(self, result_type)
725
726 cursor = self.connection.cursor()
--> 727 cursor.execute(sql, params)
728
729 if not result_type:

/usr/local/lib/python2.6/dist-packages/django/db/backends/util.pyc in
execute(self, sql, params)
 17 start = time()
 18 try:
---> 19 return self.cursor.execute(sql, params)
 20 finally:
 21 stop = time()

/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/
base.pyc in execute(self, query, params)
198 query = self.convert_query(query)
199 try:
--> 200 return Database.Cursor.execute(self, query,
params)
201 except Database.IntegrityError, e:
202 raise utils.IntegrityError,
utils.IntegrityError(*tuple(e)), sys.exc_info()[2]

DatabaseError: near "FROM": syntax error

Looks like it really doesn't like that aggregate. I might be confused,
but it seems like it wouldn't work anyway, since the annotation
produces 'subtotal':2, where what I'm going for would be 'subtotal':1,
since there's only one distinct model, but I might be missing
something.

It seems like any call to aggregate after values and annotate produces
this error (same error, same line), regardless of whether it
references the annotation.

In [25]:
Alpha.objects.filter(gamma__beta__name='Beta').values('id').annotate(subtotal=models.Sum('id')).aggregate(total=models.Sum('subtotal'))
---
DatabaseError Traceback (most recent call
last)

In [26]:
Alpha.objects.filter(gamma__beta__name='Beta').values('id').annotate(subtotal=models.Sum('id')).aggregate(total=models.Sum('id')
   : )
---
DatabaseError Traceback (most recent call
last)

And I dunno if this is related, but probably is... aggregate fails to
produce anything when called after values:

In [28]: Alpha.objects.filter(gamma__beta__name='Beta').values('id')
Out[28]: [{'id': 1}, {'id': 1}]

In [29]:
Alpha.objects.filter(gamma__beta__name='Beta').values('id').aggregate(models.Sum('id'))
Out[29]: {}

In [30]:
Alpha.objects.filter(gamma__beta__name='Beta').values('name').aggregate(models.Sum('id'))
Out[30]: {}

In [31]:
Alpha.objects.filter(gamma__beta__name='Beta').aggregate(models.Sum('id'))
Out[31]: {'id__sum': 2}

Any other ideas? It's seeming more and more like if I want this done
in the DB, I'm going to have to write some custom SQL. Either that or
do post processing in python after getting the distinct queryset.

- Jake

P.S. Thanks for your attempted help. :)


On May 4, 8:36 am, zinckiwi  wrote:
> > In [16]:
> > Alpha.objects.filter(gamma__beta__name='Beta').aggregate(models.Sum('id'))
> > Out[16]: {'id__sum': 2}
>
> > In [17]:
> > Alpha.objects.filter(gamma__beta__name='Beta').distinct().aggregate(models. 
> > Sum('id'))
> > Out[17]: {'id__sum': 2}
>
> > As you can see, the aggregate call in 17 ignores the distinct call.
>
> I think distinct() in aggregation isn't the right way to go about
> this. Using values() provides the same sort of functionality, and
> seems the way to go from the docs. Try something like (untested and
> line-split for clarity):
>
> total = Alpha.objects.filter(gamma__beta__name='Beta')
>         .values('name')
>         .annotate(subtotal=models.Sum('id'))
>         .aggregate(total=models.Sum('subtotal'))
>         .get('total')
>
> Regards
> Scott
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this 

Re: Internationalization of UserCreationForm

2010-05-04 Thread Jacek
Oh, I didn't think that they could be already translated. Yeah, I have
changed LANGUAGE_CODE and everything is working now. I didn't think it
could be done so automatically. :) Thanks a lot.

However, supposing I wanted to change translation (for example, I'm
not happy with it), would it be very difficult to do so?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



sqlite3 backend error

2010-05-04 Thread mf
Hi, before installing Ubunto 10.04 all of my projects worked pretty
well. Now I'm getting an error and I don't know how to solve it.

This is the result of running the python manage.py runserver command:

django.core.exceptions.ImproperlyConfigured:
'django.db.backends.sqlite3' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2',
'sqlite3'
Error was: No module named _md5

 python version : 2.6.4
 django version: 1.2.0.'beta'.1

Thanks in advance for your time.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Internationalization of UserCreationForm

2010-05-04 Thread Karen Tracey
On Tue, May 4, 2010 at 3:20 PM, Jacek  wrote:

> Well, I need to translate field names (labels) in register form
> (UserCreationForm). I have checked that django.contrib.auth.forms use
> hooks for internationalization (I mean ugettext_lazy).
> But when I run django-admin.py makemessages, my output locale file
> doesn't contain any strings from the form.
> What should I do to translate field names (labels) in UserCreationForm?
>
>
These strings (should) already (be) translated in the Django-provided
translations, since they are marked for translation in the Django source
tree, so I'm not understanding why you say you need to translate them? If
you use this Django-provided form in your project, you ought to just get the
Django-provided translations when you use the form and have the language set
to some non-English value. Are they not translated in the language you are
using or are you not happy with the provided translations?

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-us...@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: Internationalization of UserCreationForm

2010-05-04 Thread Felippe Bueno
I'm not sure if is this, what you are looking for,
But I use, some like this:

forms.py:

from django.utils.translation import ugettext as _
from django.contrib.auth.models import User
from django import forms

class RegForm(forms.Form):
fname = forms.CharField(label=_('First Name'),max_length=30)
lname = forms.CharField(label=_('Last Name'),max_length=30)
.
.
.
.
.
.
.
.


As you can see, I use  '_()' to identify my ids, and in my pt_BR django.po,
after running ./manage.py makemessages -l pt_BR I can see:
#: people/forms.py:19
msgid "First Name"
msgstr "Primeiro Nome"

#: people/forms.py:20
msgid "Last Name"
msgstr "Sobrenome"

Don't forget to run ./manage.py compilemessages to generate the .mo file.






On Tue, May 4, 2010 at 4:20 PM, Jacek  wrote:

> Well, I need to translate field names (labels) in register form
> (UserCreationForm). I have checked that django.contrib.auth.forms use
> hooks for internationalization (I mean ugettext_lazy).
> But when I run django-admin.py makemessages, my output locale file
> doesn't contain any strings from the form.
> What should I do to translate field names (labels) in UserCreationForm?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Internationalization of UserCreationForm

2010-05-04 Thread Jacek
Well, I need to translate field names (labels) in register form
(UserCreationForm). I have checked that django.contrib.auth.forms use
hooks for internationalization (I mean ugettext_lazy).
But when I run django-admin.py makemessages, my output locale file
doesn't contain any strings from the form.
What should I do to translate field names (labels) in UserCreationForm?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Noob questions: Syntax, Python listserv, utility/helper methods?

2010-05-04 Thread Peter Herndon

On May 4, 2010, at 2:29 PM, mhulse wrote:

> +
> 
> Question 01:
> 
> Going back to the AS example, I really dig using a dollar sign for
> method arguments and the underscore for class properties.
> 
> Does Python/Django allow for anything similar? :)

Not as such.  Names (of anything) must start with either a letter or an 
underscore 
(http://docs.python.org/reference/lexical_analysis.html#identifiers).  Names 
that start with an underscore have special meaning 
(http://docs.python.org/reference/lexical_analysis.html#reserved-classes-of-identifiers),
 and should generally not be used for normal names of functions, class methods 
or class attributes.

> 
> +
> 
> Question 02:
> 
> Is there a good Python listserv out there? I could not find an
> obviously popular Google group. Something like the PHP user group
> would be cool. :)

comp.lang.python (http://groups.google.com/group/comp.lang.python/)
> 
> +
> 
> Question 03:
> 
> I am building a view, and I would like to move functions within the
> view into other files (for the sake of modularity)... In general,
> where do you like to store your generic (to everything) / specific (to
> a particular view) "helper" methods/functions?
> 
> My co-worker suggested that I put "helper" methods in a "utilities.py"
> file:
> 
> views.py
> utilities.py
> 
> That might work well, but a part of me would prefer to do something
> like this:
> 
> views.py
> utilities/
>   +--- paginate.py
>   +--- other.py
>   +--- this.py
> 
> In other words, one method per class file, vs. cramming everything
> into one utilities file.
> 
> What do ya'll suggest?
> 
> Also, let's say "paginate.py" could be used for any project... Where
> would you suggest I store "global" utility classes/methods?

Utility functions that are used by multiple other files should go in a separate 
utilities.py.  Helper functions that are specific to either a single view or 
are used just within views.py should be included in views.py, subject to 
"taste" limitations as to how long views.py should be.  Separating out one 
helper function per file will make other Python programmers hate you.  :)  
Keeping a bunch of unrelated functions, classes and methods together all in one 
file will also make other Python programmers hate you.  

You should use one file to hold all related classes and functions.  If the file 
starts getting too large, you haven't thought enough about how related the 
classes and functions are.  Notice how I'm not defining either "related" or 
"too large". 

If you break each individual function into its own file, you are going to need 
lots and lots of import statements in order to get anything done.  That's an 
awful lot of unnecessary typing.

> +
> 
> Sorry if silly questions. :(

Not silly, just new.  You would do well to read some good Python code, to get a 
feel for how things are done.  For instance, take a look through Django's 
source code, not so much to understand what it does, but just to get a feel for 
how it is laid out, the flow of organization, and how related subjects are 
organized and things are named.

HTH,

---Peter Herndon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Noob questions: Syntax, Python listserv, utility/helper methods?

2010-05-04 Thread mhulse
I come from the PHP/CodeIgniter/Actionscript/Other world I am slowly
learning Django and Python.

+

Question 01:

Sorry if OT... This is kinda more of a Python question. :(

In as3 oop, I like to do this (for example):

=
...
public class ClickTag {

// Private:
private var _ft:FireTrace;
...
private function init($str:String = ''):void {
...
=

Notice the underscore on "_ft" and the dollar sign on "$str".

Another example, in jQuery, I like to designate objects using a dollar
sign:

=

$foo = $('#mydiv');

=

Going back to the AS example, I really dig using a dollar sign for
method arguments and the underscore for class properties.

Does Python/Django allow for anything similar? :)

+

Question 02:

Is there a good Python listserv out there? I could not find an
obviously popular Google group. Something like the PHP user group
would be cool. :)

+

Question 03:

I am building a view, and I would like to move functions within the
view into other files (for the sake of modularity)... In general,
where do you like to store your generic (to everything) / specific (to
a particular view) "helper" methods/functions?

My co-worker suggested that I put "helper" methods in a "utilities.py"
file:

views.py
utilities.py

That might work well, but a part of me would prefer to do something
like this:

views.py
utilities/
   +--- paginate.py
   +--- other.py
   +--- this.py

In other words, one method per class file, vs. cramming everything
into one utilities file.

What do ya'll suggest?

Also, let's say "paginate.py" could be used for any project... Where
would you suggest I store "global" utility classes/methods?

+

Sorry if silly questions. :(

TIA!
M

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



change an object from parent to child

2010-05-04 Thread Steve Bywater
Given...

class Place(models.Model):
name = models.CharField(max_length=50)

class Restaurant(Place):
serves_hot_dogs = models.BooleanField()

...it is trivial to create either a place or restaurant. But how do
you take an instance that is already a place and create a restaurant
from it? Is this possible, without first deleting the place?

I though this would work:

restaurant = Restaurant()
place = Place.objects.get(id=1)
restaurant.place = place
restaurant.save()

But this creates a new restaurant (and a new place) unrelated to the
existing place.

What am I missing? Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Customize what's a NULL for legacy data

2010-05-04 Thread Ole Laursen
Hi!

I have a problem. I'm dealing with a legacy database where some of the
foreign keys aren't pointing to the right place because 0 (and -1) has
been used in some places instead of NULL. I can't fix the rows as the
new application will have to live side by side with the legacy system
for some time.

The problem is that if I try to access foo.bar in any way, Django
tries to lookup a bar with id 0 or -1 and throws an exception. My
forms break, and the serializers break, making it hard to write test
code. Does anyone know of an easy way to get around this?

I had a brief look at the ForeignKey code, but it's not immediately
obvious how to add a little hook to fix this, I'd hoped I could just
convert 0 and -1 to None before the values get to Django.

If it weren't for the problem with forms and serializers, I think I'd
just write a little helper function and never use the field itself.

Ole

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Trouble with multi-db test suite.

2010-05-04 Thread J. Cliff Dyer
I'm having trouble working with multi-db using mysql replication.  When
I run our test suite, I'm getting several hundred errors if I have more
than one database configured, and none if I have only one configured.

It seems that something isn't getting properly cleared out between test
cases, so duplicate objects are getting created.

My DATABASES setting looks like this: 


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'jellyroll',
'NAME': 'ee',
'USER': 'ee',
'PASSWORD': 'ee',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
'charset' : 'utf8',
'use_unicode' : True,
},
},
'replicant0': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'jellyroll-rep0',
'NAME': 'test',
'USER': 'ee',
'PASSWORD': 'ee',
'TEST_MIRROR': 'default',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
'charset' : 'utf8',
'use_unicode' : True,
},
},
}


My router looks like this:

class PrimaryReplicantRouter(object):
"""Set up routing with one primary database, and zero or more 
replicant databases."""

db_list = settings.DATABASES.keys()
primary_db = 'default'
replicant_db_list = [x for x in db_list if x != primary_db]

def db_for_read(self, model, **hints):
try:
return random.choice(self.replicant_db_list)
except IndexError:
return self.primary_db


def db_for_write(self, model, **hints):
"""Write to the Primary DB"""
return self.primary_db

def allow_relation(self, obj1, obj2, **hints):
"""Allow a relationship between any two objects in the db 
pool"""

if (obj1._state.db in self.db_list 
and obj2._state.db in self.db_list):
return True
return None

def allow_syncdb(self, db, models):
"""All writes go to the primary db."""
return db == self.primary_db

The first error that comes out of the test suite is a duplicate username
in auth during a testcase's setUp, which makes it look like the object
is getting created on one test pass, and then created again the next
time around without deleting it properly:


$ ./manage.py test --failfast
.E
==
ERROR: Regressiontest for #12462
--
Traceback (most recent call last):
  File
"/home/cliff/projects/lr-mdb/lexilereader/web/../contrib/django/contrib/auth/tests/auth_backends.py",
 line 14, in setUp
User.objects.create_user('test', 't...@example.com', 'test')
...
IntegrityError: (1062, "Duplicate entry 'test' for key 2")


Any ideas what's going wrong?



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Decode a JSON object?

2010-05-04 Thread esatterwh...@wi.rr.com
use the simplejson module

from django.utils import simplejson

I think your code is having problems becuase you are trying to
deserialize something that isn't a json string, its an object.
On May 3, 11:33 am, Thomas Allen  wrote:
> How can I parse a simple JSON object in Django?
>
> I would like to parse the response: {"totalspace":
> 243862.672,"freespace":94053.564}
>
> django.core.serializers.deserialize('json', packet) seems to have
> trouble parsing such a simple string.
>
> Thomas
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Support of settings.ADMIN_FOR

2010-05-04 Thread lazerscience
Hi!

I'm working on creating a Django Setup, where i can manage multiple
sites through one admin using Django's sites framework. During my
researches I came across the ADMIN_FOR setting, which seems to be
something I could need, but there's hardly any documentation about it,
so i looked at django's source, but it seems to be only used for
printing template validation statements and in admindocs!

So is there anybody outthere who knows more about that, and has used
it already (and how?)?
If you have any ideas/experiences about that, let me know!

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-us...@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: LOCALE_PATHS in settings.py required?

2010-05-04 Thread Baurzhan Ismagulov
On Tue, May 04, 2010 at 08:10:18AM -0700, janedenone wrote:
> according to
> 
> http://docs.djangoproject.com/en/1.1/howto/i18n/
> 
> Django automatically looks for localizations in $PROJECTPATH/locale/
> /LC_MESSAGES/django.(po|mo). When I installed language files
> in this location, however, they were found only after I added
> LOCALE_PATHS to settings.py.

Hmm, this works for me with 1.0 and without LOCALE_PATHS. You do have
.mo files, don't you? I'd read Django sources or strace the web server
to find out what goes wrong.

With kind regards,
-- 
Baurzhan Ismagulov
http://www.kz-easy.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-us...@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.



LOCALE_PATHS in settings.py required?

2010-05-04 Thread janedenone
Hi,

according to

http://docs.djangoproject.com/en/1.1/howto/i18n/

Django automatically looks for localizations in $PROJECTPATH/locale/
/LC_MESSAGES/django.(po|mo). When I installed language files
in this location, however, they were found only after I added
LOCALE_PATHS to settings.py.

Did I misinterpret the documentation, is this a bug, or am I missing
something?

Thanks,
Jan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Translation error triggered by HttpResponse

2010-05-04 Thread Karen Tracey
On Tue, May 4, 2010 at 3:28 AM, Derek  wrote:

> The online documentation has the following example in this section:
>
> http://docs.djangoproject.com/en/1.0/topics/i18n/#standard-translation
>
> from django.utils.translation import ugettext as _
>
> def my_view(request):
>output = _("Welcome to my site.")
>return HttpResponse(output)
>
> My example looks like this:
>
> def my_function(request):
>output = _("Activities")
>return HttpResponse(output)
>
> and generates this error when called:
>
> Traceback (most recent call last):
>
>  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 279, in run
>self.result = application(self.environ, self.start_response)
>
>  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 651, in __call__
>return self.application(environ, start_response)
>
>  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py",
> line 245, in __call__
>response = middleware_method(request, response)
>
>  File "/usr/lib/python2.5/site-packages/debug_toolbar/middleware.py",
> line 91, in process_response
>response.content =
> replace_insensitive(smart_unicode(response.content), u'',
> smart_unicode(self.debug_toolbars[request].render_toolbar() +
> u''))
>
>  File "/usr/lib/python2.5/site-packages/django/http/__init__.py",
> line 365, in _get_content
>return smart_str(''.join(self._container), self._charset)
>
> TypeError: sequence item 0: expected string, __proxy__ found
>
>
> As soon as I remove the _() it works just fine.
>
> Any clues as to what could be the cause? (I am running Django 1.1 on a
> local desktop, using the development server).
>
>
debug_toolbar appears in the traceback. So I'd first ask if the problem goes
away if you disable the debug_toolbar middleware? If yes, then the next
question would be are you running the most recent debug_toolbar? If not, I'd
try updating to the latest, since this may be a problem that's already been
fixed. If the problem still occurs with the latest release of debug_toolbar
I'd start by looking around here:
http://github.com/robhudson/django-debug-toolbar/issues to see if the
problem has been reported.

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-us...@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: Admin custom filters

2010-05-04 Thread Massimiliano della Rovere
The filters are not documented.
You can learn how they works, looking at the file
DJANGO_PATH/contrib/admin/filterspecs.py
I found DateFieldFilterSpec to be useful whenever you need to filter
something that is in a range, not just for calendar matters.



On Mon, May 3, 2010 at 23:23, Thales  wrote:
> Good evening,
>
> I am trying to create a custom filter in my admin. It should be in the
> general page Modify.
>
> If a put in the filter_list the content 'project__year', it shows me
> the years avaiable on the right menu and filters well.
>
> But I want to define the default value (the default year selected) and
> the avaiable options (maybe I dont want to show all the years there).
>
> I am sorry it sounds very easy, but I couldn't find inside the
> documentation how can I do it.
>
> Thanks
> Thales
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: override a form field, to allow usernames with '@'

2010-05-04 Thread Nick Serra
I just implemented this and it's a hassle. There are heated
discussions about it. I ended up modifying the auth app and completely
eliminating the 'username' field and just using email. Then I modified
the admin app to allow the login, and am basically just completely
overriding both. Good luck!

On May 4, 10:40 am, Bill Freeman  wrote:
> Consider that there may be some third party app which you will
> want to add in the future, and that it may depend on the existing
> nature of usernames.  (E.g.; uses username as a slug and uses
> a simple regular expression in a url pattern to capture the username.
>
> Consider that usernames are currently limited to 30 characters,
> while email addresses are not, so you would also need to modify
> the User model.
>
> Wouldn't it be simpler modify the AuthenticationForm to accept
> an email address instead of a username and in the clean
> method, look up the user by email address, get the username
> from there, and authenticate on that and the collected password?
> You would still want to modify the User model to mark email
> as unique.  And you would have to modify UserCreationForm to
> collect an email address instead of a username, then in the
> clean_email method, check that the email address doesn't
> already exist, create a username that doesn't exist (from the email
> address, or randomly, adding a numeric suffix if necessary to
> make it unique, and modify the save method to set the username
> (since username wouldn't be a field of the form you might have
> to do your own user object creation and saving, rather than
> calling the super-class save method).
>
> Bill
>
>
>
>
>
> On Tue, May 4, 2010 at 1:19 AM, Felippe Bueno  wrote:
> > Btw,
>
> > I read about django don't accept @ in usernames, but I can create a User
> > using
> > User.create_user(m...@email.com, m...@email.com, mypassword)
> > The only problem is, I can't save the user at admin site.
> > I was thinking if the limitation is only at forms.
> > I did not test the authentication yet.
> > Any one know more about this ?
>
> > Thanks
> > ps - sorry my poor english.
> > Cheers
>
> > On Sun, May 2, 2010 at 7:54 AM, Rob  wrote:
>
> >> Hi,
>
> >> I'm trying to allow usernames that have '@' in them, so they can just
> >> be email addresses.  Maybe this is a bad idea.  ...  But putting that
> >> aside for a second... The admin user forms don't validate with '@' in
> >> usernames, so I thought I'd try this, which I copied from an older
> >> post in this group.
>
> >> from django.contrib.auth.admin import User, UserChangeForm,
> >> UserCreationForm, UserAdmin
>
> >> class OurUserChangeForm(UserChangeForm):
> >>    username = forms.EmailField
>
> >> class OurUserCreationForm(UserCreationForm):
> >>    username = forms.EmailField
>
> >> admin.site.unregister(User)
> >> UserAdmin.form = OurUserChangeForm
> >> UserAdmin.add_form = OurUserCreationForm
> >> admin.site.register(User, UserAdmin)
>
> >> But it doesn't work.  The user form is still validating with the
> >> 'username' from the superclass, which is a RegexField.  Is this
> >> working as designed?  Are you not allowed to override a field?
>
> >> thanks,
> >> Rob
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@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.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: override a form field, to allow usernames with '@'

2010-05-04 Thread Bill Freeman
Consider that there may be some third party app which you will
want to add in the future, and that it may depend on the existing
nature of usernames.  (E.g.; uses username as a slug and uses
a simple regular expression in a url pattern to capture the username.

Consider that usernames are currently limited to 30 characters,
while email addresses are not, so you would also need to modify
the User model.

Wouldn't it be simpler modify the AuthenticationForm to accept
an email address instead of a username and in the clean
method, look up the user by email address, get the username
from there, and authenticate on that and the collected password?
You would still want to modify the User model to mark email
as unique.  And you would have to modify UserCreationForm to
collect an email address instead of a username, then in the
clean_email method, check that the email address doesn't
already exist, create a username that doesn't exist (from the email
address, or randomly, adding a numeric suffix if necessary to
make it unique, and modify the save method to set the username
(since username wouldn't be a field of the form you might have
to do your own user object creation and saving, rather than
calling the super-class save method).

Bill

On Tue, May 4, 2010 at 1:19 AM, Felippe Bueno  wrote:
> Btw,
>
> I read about django don't accept @ in usernames, but I can create a User
> using
> User.create_user(m...@email.com, m...@email.com, mypassword)
> The only problem is, I can't save the user at admin site.
> I was thinking if the limitation is only at forms.
> I did not test the authentication yet.
> Any one know more about this ?
>
> Thanks
> ps - sorry my poor english.
> Cheers
>
> On Sun, May 2, 2010 at 7:54 AM, Rob  wrote:
>>
>> Hi,
>>
>> I'm trying to allow usernames that have '@' in them, so they can just
>> be email addresses.  Maybe this is a bad idea.  ...  But putting that
>> aside for a second... The admin user forms don't validate with '@' in
>> usernames, so I thought I'd try this, which I copied from an older
>> post in this group.
>>
>> from django.contrib.auth.admin import User, UserChangeForm,
>> UserCreationForm, UserAdmin
>>
>> class OurUserChangeForm(UserChangeForm):
>>    username = forms.EmailField
>>
>> class OurUserCreationForm(UserCreationForm):
>>    username = forms.EmailField
>>
>> admin.site.unregister(User)
>> UserAdmin.form = OurUserChangeForm
>> UserAdmin.add_form = OurUserCreationForm
>> admin.site.register(User, UserAdmin)
>>
>> But it doesn't work.  The user form is still validating with the
>> 'username' from the superclass, which is a RegexField.  Is this
>> working as designed?  Are you not allowed to override a field?
>>
>> thanks,
>> Rob
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Equivalent of php json_encode?

2010-05-04 Thread Daniel Hilton
On 4 May 2010 15:34, zweb  wrote:
> Is there a django or python equivalent of php json_encode?
>
> the data I am converting to json has text fields that have quotes,
> double quotes, newlines and html tags. Creating json manually in my
> program without escaping or converting these special characters is
> causing problem on javascript side.
>
> A php programmer suggested I use equivalent of php json_encode.
>

Have a look at django.serializers
http://docs.djangoproject.com/en/dev/topics/serialization/
 or simple-json python package.

HTH
Dan

> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Equivalent of php json_encode?

2010-05-04 Thread ge...@aquarianhouse.com
sure, simplejson is your helper

On May 4, 4:34 pm, zweb  wrote:
> Is there a django or python equivalent of php json_encode?
>
> the data I am converting to json has text fields that have quotes,
> double quotes, newlines and html tags. Creating json manually in my
> program without escaping or converting these special characters is
> causing problem on javascript side.
>
> A php programmer suggested I use equivalent of php json_encode.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Equivalent of php json_encode?

2010-05-04 Thread zweb
Is there a django or python equivalent of php json_encode?

the data I am converting to json has text fields that have quotes,
double quotes, newlines and html tags. Creating json manually in my
program without escaping or converting these special characters is
causing problem on javascript side.

A php programmer suggested I use equivalent of php json_encode.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Internationalization

2010-05-04 Thread Baurzhan Ismagulov
On Tue, May 04, 2010 at 02:47:35PM +0200, Daniel Baron wrote:
> The first question is whether django supports the declaration of a  
> message context (msgctxt) in the .po-files in order to have different  
> translations for the same string in different positions of the 
> application.

A hack could be to define different strings in the sources (like
"Public1" and "Public2") and provide also an English translation for
those (the rest will be used literally).


> The second question is whether it is possible to remove options (in my  
> special case I use the "choices" parameter in my model) depending on the  
> language. The background is the following:
> I have a field containing the salutation. In english this would contain  
> "Mr, Mrs and Ms" while in most other languages this only contains a  
> string for males and a string for females - thus only two options. Is it  
> possible to get rid of the third option if no equivalent for that is  
> available in a certain langauge?

Check the language and create a var in a view? I haven't done this
myself, though, so I haven't tried saving that. I personally would
workaround that by not using "Mrs".


With kind regards,
-- 
Baurzhan Ismagulov
http://www.kz-easy.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-us...@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: Following Django Book, get NameError when accessing certain page

2010-05-04 Thread Karen Tracey
On Sun, May 2, 2010 at 11:16 PM, kelp  wrote:

> Yes, I did that, but for some reason, it is still not working, here's
> the contents of my views.py:
> from django.http import HttpResponse
> from django.shortcuts import render_to_response
> import datetime
>
> def hello(request):
>return HttpResponse("Hello world")
>
> def search_form(request):
>return render_to_response('search_form.html')
>
> def current_datetime(request):
>now = datetime.datetime.now()
>html = "It is now %s." % now
>return HttpResponse(html)
>
>
>
> Does order matter when I am importing?
>
>
Order matters in that you must import something before attempting to use it.

As for getting the error you are getting even though views.py has a
definition for search_form -- that is a bit of a mystery. Somehow the
views.py that has the search_form function defined is not the one that is
being used. I assume you are using the development server? It should have
re-loaded itself when you changed views.py, so that the new code would be
picked up. But you can manually stop and restart it to make sure it is
picking up the latest code.

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-us...@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: send an email to users after saving is_active=True

2010-05-04 Thread zinckiwi
On May 4, 9:49 am, Sander  wrote:
> I don't want to check if if_active = True
> I wan't to check if if_active is changed to True

If you use the pre_save signal, you can get the object as it currently
exists (based in the signalled instance's pk) and compare the existing
object's `is_active` with the signalled instance's `is_active`. Of
course, then you run into the problem of the email being sent even if
the save itself fails, so you might then want to figure out a way of
persisting a flag from pre_save (which determines whether an email
should be sent) to post_save (which does the sending). Might be over-
engineering it, though.

Regards
Scott

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: send an email to users after saving is_active=True

2010-05-04 Thread Sander
I don't want to check if if_active = True
I wan't to check if if_active is changed to True


On May 4, 2:50 pm, "ge...@aquarianhouse.com" 
wrote:
> if you don't use django-registration, when listen on signal post_save
> for User, check if is_active == True and do something.
>
> On May 4, 2:45 pm, Sander  wrote:
>
>
>
> > someone got an answer to this one?
> > is there some kind of is_activated signal?
>
> > Sander
>
> > On Apr 3, 6:19 pm, Alessandro Ronchi 
> > wrote:
>
> > > I need to notify users when an admin activate them saving their
> > > profile withis_active=True.
>
> > > Is it possible?
> > > How?
> > > I need also to avoidemailduplication when admin changes something
> > > different fromis_active.
>
> > > thanks in advance!
>
> > > --
> > > Alessandro Ronchi
>
> > >http://www.soasi.com
> > > SOASI - Sviluppo Software e Sistemi Open Source
>
> > > Hobby & Giochi, l'e-commerce del 
> > > divertimentohttp://hobbygiochi.comhttp://www.facebook.com/pages/Forli/Hobby-Gioch...
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.distinct and aggregates

2010-05-04 Thread zinckiwi
> In [16]:
> Alpha.objects.filter(gamma__beta__name='Beta').aggregate(models.Sum('id'))
> Out[16]: {'id__sum': 2}
>
> In [17]:
> Alpha.objects.filter(gamma__beta__name='Beta').distinct().aggregate(models. 
> Sum('id'))
> Out[17]: {'id__sum': 2}
>
> As you can see, the aggregate call in 17 ignores the distinct call.

I think distinct() in aggregation isn't the right way to go about
this. Using values() provides the same sort of functionality, and
seems the way to go from the docs. Try something like (untested and
line-split for clarity):

total = Alpha.objects.filter(gamma__beta__name='Beta')
.values('name')
.annotate(subtotal=models.Sum('id'))
.aggregate(total=models.Sum('subtotal'))
.get('total')

Regards
Scott

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Uploads in the Form Wizard

2010-05-04 Thread Russell Keith-Magee
On Mon, May 3, 2010 at 12:02 PM, Wiiboy  wrote:
> What would be the best workaround (or is there one)?
> Perhaps overriding FormWizard.process_step()?

The only obvious workaround I can think of is to treat the N-form
wizard problem as a (N-1) form wizard, plus 1 normal form that handles
file uploads.

You might be able to cobble something together with process_step(),
but that's about the limit of the advice I can provide on that front.

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-us...@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.



Internationalization

2010-05-04 Thread Daniel Baron

Hi all,

I have two questions regarding i18n to which I find very little or even 
no information. I hope someone can help.


The first question is whether django supports the declaration of a 
message context (msgctxt) in the .po-files in order to have different 
translations for the same string in different positions of the application.


I tried the following

#: templates/client/base_project.html:21
msgctxt "templates/client/base_project.html:21"
msgid "Public"
msgstr "My translation"

and a couple of deviations but the string is never translated if the 
"msgctxt" declaration is present.


The second question is whether it is possible to remove options (in my 
special case I use the "choices" parameter in my model) depending on the 
language. The background is the following:
I have a field containing the salutation. In english this would contain 
"Mr, Mrs and Ms" while in most other languages this only contains a 
string for males and a string for females - thus only two options. Is it 
possible to get rid of the third option if no equivalent for that is 
available in a certain langauge?


Thanks in advance!
Regards,
Daniel

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: send an email to users after saving is_active=True

2010-05-04 Thread ge...@aquarianhouse.com
if you don't use django-registration, when listen on signal post_save
for User, check if is_active == True and do something.

On May 4, 2:45 pm, Sander  wrote:
> someone got an answer to this one?
> is there some kind of is_activated signal?
>
> Sander
>
> On Apr 3, 6:19 pm, Alessandro Ronchi 
> wrote:
>
>
>
> > I need to notify users when an admin activate them saving their
> > profile withis_active=True.
>
> > Is it possible?
> > How?
> > I need also to avoidemailduplication when admin changes something
> > different fromis_active.
>
> > thanks in advance!
>
> > --
> > Alessandro Ronchi
>
> >http://www.soasi.com
> > SOASI - Sviluppo Software e Sistemi Open Source
>
> > Hobby & Giochi, l'e-commerce del 
> > divertimentohttp://hobbygiochi.comhttp://www.facebook.com/pages/Forli/Hobby-Gioch...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: send an email to users after saving is_active=True

2010-05-04 Thread Sander
someone got an answer to this one?
is there some kind of is_activated signal?

Sander


On Apr 3, 6:19 pm, Alessandro Ronchi 
wrote:
> I need to notify users when an admin activate them saving their
> profile withis_active=True.
>
> Is it possible?
> How?
> I need also to avoidemailduplication when admin changes something
> different fromis_active.
>
> thanks in advance!
>
> --
> Alessandro Ronchi
>
> http://www.soasi.com
> SOASI - Sviluppo Software e Sistemi Open Source
>
> Hobby & Giochi, l'e-commerce del 
> divertimentohttp://hobbygiochi.comhttp://www.facebook.com/pages/Forli/Hobby-Giochi/185311523755

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Q objects subquery

2010-05-04 Thread danfis
thanks for your advise daniel,

is see it now and the hint with values_list works great.

thanks again

On 4 Mai, 13:11, Daniel Roseman  wrote:
> On May 4, 9:53 am, danfis  wrote:
>
>
>
>
>
> > Hi guys,
>
> > i ran into a problem today which i'm not sure if it's a bug (or a
> > feature?!) so you might can help me:
>
> > when i call a model manager method to manipulate the queryset and
> > using Q objects for filtering, it seems like the query of the method
> > (=queryset.query) "stores" the result of subqueries and not the
> > subquery itself.
> > this causes, of course, into some 'old' data sometimes, so i wondered
> > if this is correct?
>
> > a simple example:
> > this is the manager for my model Bar and there is also some other
> > model having a foreign key to this one
>
> > def get_my_stuff(self):
> >   return self.filter(Q(field_1='foobar') | Q(pk__in=[foo.bar_id for
> > foo in SomeOtherModel.objects.all()])
>
> > the problem is now, that the result of the subquery ([foo.bar_id for
> > foo in SomeOtherModel.objects.all()]) is stored as fixed value (and
> > not as subquery) in the query and changes in SomeOtherModel objects
> > are not recognized correctly.
>
> > Any advises?
>
> This is expected, because you're explicitly evaluating the result of
> SomeOtherModel.objects.all(), thanks to your list comprehension. Using
> values_list is probably better, as that produces a lazy
> ValuesListQuerySet:
>
>     Q(pk__in=SomeOtherModel.values_list('bar_id', flat=True))
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: TypeError with a Decimal Field

2010-05-04 Thread Daniel Roseman
On May 4, 1:15 pm, JonathanB  wrote:
> I'm working on a Grade Book program for my personal use. Here is the
> relevant class from my models.py file:
>
> class Grade(models.Model):
>         student = models.ForeignKey(Student)
>         assignment = models.ForeignKey(Assignment)
>         grade = models.DecimalField(max_digits=5, decimal_places=2)
>
>         def __unicode__(self):
>                 return self.grade
>
> I get the following error when I try to enter something using the
> admin interface (all the other models would save without issue): I'm
> trying to put in "10" or "10.0". I want to use a Decimal field to
> allow for 1/2 points (such as if they get the right word but the wrong
> spelling, earning a 9.5). Below is the copy/paste from the Error page
> I get when I click "Save":



> Exception Type: TypeError at /admin/grades/grade/add/
> Exception Value: coercing to Unicode: need string or buffer, Decimal
> found
>
> So, what have I missed? Do I need to import Decimal someplace? And if
> so, where? admin.py?

The problem is in your __unicode__ method. As the name implies, it
should always actually return a unicode value, but you're just
returning the value of self.grade, which is decimal. To be safe,
Python doesn't automatically coerce anything that's not a string to
unicode - you have to do it explicitly yourself. So your method should
just be:

def __unicode__(self):
return unicode(self.grade)

--
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-us...@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.



TypeError with a Decimal Field

2010-05-04 Thread JonathanB
I'm working on a Grade Book program for my personal use. Here is the
relevant class from my models.py file:

class Grade(models.Model):
student = models.ForeignKey(Student)
assignment = models.ForeignKey(Assignment)
grade = models.DecimalField(max_digits=5, decimal_places=2)

def __unicode__(self):
return self.grade

I get the following error when I try to enter something using the
admin interface (all the other models would save without issue): I'm
trying to put in "10" or "10.0". I want to use a Decimal field to
allow for 1/2 points (such as if they get the right word but the wrong
spelling, earning a 9.5). Below is the copy/paste from the Error page
I get when I click "Save":

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/grades/grade/add/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'gradebook.grades',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py"
in wrapper
  226. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "C:\Python26\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in
inner
  186. return view(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  240. res = func(*args, **kw)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py"
in add_view
  739. self.log_addition(request, new_object)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py"
in log_addition
  388. object_repr = force_unicode(object),
File "C:\Python26\lib\site-packages\django\utils\encoding.py" in
force_unicode
  71. s = unicode(s)

Exception Type: TypeError at /admin/grades/grade/add/
Exception Value: coercing to Unicode: need string or buffer, Decimal
found

So, what have I missed? Do I need to import Decimal someplace? And if
so, where? admin.py?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: HttpResponseRedirect and user message

2010-05-04 Thread Daniel Roseman
On May 4, 9:43 am, xpanta  wrote:
> Thank you. One more thing: how to save info in the session?

Read the fine documentation:
http://docs.djangoproject.com/en/1.1/topics/http/sessions/
--
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-us...@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: Q objects subquery

2010-05-04 Thread Daniel Roseman
On May 4, 9:53 am, danfis  wrote:
> Hi guys,
>
> i ran into a problem today which i'm not sure if it's a bug (or a
> feature?!) so you might can help me:
>
> when i call a model manager method to manipulate the queryset and
> using Q objects for filtering, it seems like the query of the method
> (=queryset.query) "stores" the result of subqueries and not the
> subquery itself.
> this causes, of course, into some 'old' data sometimes, so i wondered
> if this is correct?
>
> a simple example:
> this is the manager for my model Bar and there is also some other
> model having a foreign key to this one
>
> def get_my_stuff(self):
>   return self.filter(Q(field_1='foobar') | Q(pk__in=[foo.bar_id for
> foo in SomeOtherModel.objects.all()])
>
> the problem is now, that the result of the subquery ([foo.bar_id for
> foo in SomeOtherModel.objects.all()]) is stored as fixed value (and
> not as subquery) in the query and changes in SomeOtherModel objects
> are not recognized correctly.
>
> Any advises?
>

This is expected, because you're explicitly evaluating the result of
SomeOtherModel.objects.all(), thanks to your list comprehension. Using
values_list is probably better, as that produces a lazy
ValuesListQuerySet:

Q(pk__in=SomeOtherModel.values_list('bar_id', flat=True))
--
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-us...@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_audit 0.0.2

2010-05-04 Thread Dj Gilcrease
On Tue, May 4, 2010 at 4:21 AM, Euan Goddard
 wrote:
> This is all very well, but should either of these projects get to pypi
> there's going to be some serious trouble. Since I'm the main author of
> the "noSQL" django-audit, please let me know how you want to proceed.
> I'm already using the project in some pre-production code so would
> rather not rename my project. If you could rename yours that would be
> really helpful as this clearly a case of two people simultaneously
> coming up with the same name.

Google code wont let me change the project name without deleting and
recreating the project so I just added a note to the top

"This is a fairly comprehensive Audit Trail App for use with standard
RDBMS databases. If you are looking for a solution for NoSQL there is
a great project by the same name but differing author @
https://launchpad.net/django-audit that uses MongoDB."

and a little NoSQL vs SQL comparison of the two solutions

"Not all of us can use a NoSQL audit solution due to business rules or
other constraints. Django Audit for MongoDB preserves field type in
the audit history, which is lost django-audit for SQL. This loss of
field type is mitigated by the field formatters which allow you to
record the field how you want to display it to the person reading the
audit history.

Ultimately the solution you pick will depend on your requirements and
capabilities, both work, though I believe my solution takes a bit more
work for the developer to setup and configure on each model then then
MongoDB solution (have not looked too deeply into the code over there
as I cannot use MongoDB for the projects I need an Audit history in)"



I also added links to a few of the other audit solutions out there

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: filebrowser issue

2010-05-04 Thread Nuno Maltez
On Mon, May 3, 2010 at 8:10 PM, Bobby Roberts  wrote:
> hey I have a strange issue.  I was having trouble getting django-
> tinymce and filebrowser working.  I've worked through all of the
> errors etc.  In filebrowser, I can create a new directory, but when i
> try to upload a file or image, nothing happens... it acts like it's
> uploading but it's not on the server anywhere.  I've checked the perms
> on my upload directory and it seems to be ok.  Any ideas?

Do you see filebrowser calling the upload url in your logs or dev
console? Any errors, or is it logged as 200 OK?

I think fb uses Uploadify to upload the files, so you might want to
try checking the HTTP response from the server using Firebug or a
similar tool - that will probably explain what's going on and even
show you the debug page generated by django in case of any exceptions.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Q objects subquery

2010-05-04 Thread danfis
Hi guys,

i ran into a problem today which i'm not sure if it's a bug (or a
feature?!) so you might can help me:

when i call a model manager method to manipulate the queryset and
using Q objects for filtering, it seems like the query of the method
(=queryset.query) "stores" the result of subqueries and not the
subquery itself.
this causes, of course, into some 'old' data sometimes, so i wondered
if this is correct?

a simple example:
this is the manager for my model Bar and there is also some other
model having a foreign key to this one

def get_my_stuff(self):
  return self.filter(Q(field_1='foobar') | Q(pk__in=[foo.bar_id for
foo in SomeOtherModel.objects.all()])

the problem is now, that the result of the subquery ([foo.bar_id for
foo in SomeOtherModel.objects.all()]) is stored as fixed value (and
not as subquery) in the query and changes in SomeOtherModel objects
are not recognized correctly.

Any advises?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: HttpResponseRedirect and user message

2010-05-04 Thread xpanta
Thank you. One more thing: how to save info in the session?


On 4 Μάϊος, 11:27, "ge...@aquarianhouse.com" 
wrote:
> i would use reverse and redirect to a "success" page
>
> def my_view(request):
>     #do stufff
>     #save info in session
>     return HttpResponseRedirect(reverse('success_url'))
>
> def my_success_view(request):
>     #access the session and get the data
>     return render_to_response('success.html', locals())
>
> On May 4, 9:35 am, xpanta  wrote:
>
>
>
>
>
> > Hi,
>
> > I am new to django, and I have this simple task i need to accomplish.
>
> > in views.py there is a function that processes an html form (with POST
> > action). This function returns an HttpResponseRedirect object. This
> > object gets as parameters the redirect action, like this: return
> > HttpResponseRedirect('/city/%s/%s/' % (username,city))
>
> > Is there any way to add some extra fields, like a message to display
> > to the user? (i.e. "Settings have been saved, successfully!")
>
> > hope this makes sense,
> > Chris
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: HttpResponseRedirect and user message

2010-05-04 Thread ge...@aquarianhouse.com
i would use reverse and redirect to a "success" page

def my_view(request):
#do stufff
#save info in session
return HttpResponseRedirect(reverse('success_url'))

def my_success_view(request):
#access the session and get the data
return render_to_response('success.html', locals())


On May 4, 9:35 am, xpanta  wrote:
> Hi,
>
> I am new to django, and I have this simple task i need to accomplish.
>
> in views.py there is a function that processes an html form (with POST
> action). This function returns an HttpResponseRedirect object. This
> object gets as parameters the redirect action, like this: return
> HttpResponseRedirect('/city/%s/%s/' % (username,city))
>
> Is there any way to add some extra fields, like a message to display
> to the user? (i.e. "Settings have been saved, successfully!")
>
> hope this makes sense,
> Chris
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



how to change urls for model in admin?

2010-05-04 Thread akonsu
hello,

by default an admin url for a model looks like this:

http:///admin///...

is there a way to change it? for different models i need to have
different url structure. say, i want to replace "/admin/" with something else.

ModelAdmin.get_urls()? the documentation is not very helpful for me. i
do not understand how i can use get_urls(). in particular, i do not
have any custom views in my admin. and the docs only explain how to
use get_urls() to hook up views.

thanks for any help
konstantin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-04 Thread Euan Goddard
On May 1, 4:00 am, Dj Gilcrease  wrote:
> Ya I saw the announcement on it the day I pushed my code to google,
> hence my remark about not being tied to a "NoSQL" solution. I had
> already created the project name by the time I saw the announcement so
> just went with it

This is all very well, but should either of these projects get to pypi
there's going to be some serious trouble. Since I'm the main author of
the "noSQL" django-audit, please let me know how you want to proceed.
I'm already using the project in some pre-production code so would
rather not rename my project. If you could rename yours that would be
really helpful as this clearly a case of two people simultaneously
coming up with the same name.

Thanks, Euan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



HttpResponseRedirect and user message

2010-05-04 Thread xpanta
Hi,

I am new to django, and I have this simple task i need to accomplish.

in views.py there is a function that processes an html form (with POST
action). This function returns an HttpResponseRedirect object. This
object gets as parameters the redirect action, like this: return
HttpResponseRedirect('/city/%s/%s/' % (username,city))

Is there any way to add some extra fields, like a message to display
to the user? (i.e. "Settings have been saved, successfully!")

hope this makes sense,
Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Translation error triggered by HttpResponse

2010-05-04 Thread Derek
The online documentation has the following example in this section:

http://docs.djangoproject.com/en/1.0/topics/i18n/#standard-translation

from django.utils.translation import ugettext as _

def my_view(request):
output = _("Welcome to my site.")
return HttpResponse(output)

My example looks like this:

def my_function(request):
output = _("Activities")
return HttpResponse(output)

and generates this error when called:

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 279, in run
self.result = application(self.environ, self.start_response)

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py",
line 651, in __call__
return self.application(environ, start_response)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py",
line 245, in __call__
response = middleware_method(request, response)

  File "/usr/lib/python2.5/site-packages/debug_toolbar/middleware.py",
line 91, in process_response
response.content =
replace_insensitive(smart_unicode(response.content), u'',
smart_unicode(self.debug_toolbars[request].render_toolbar() +
u''))

  File "/usr/lib/python2.5/site-packages/django/http/__init__.py",
line 365, in _get_content
return smart_str(''.join(self._container), self._charset)

TypeError: sequence item 0: expected string, __proxy__ found


As soon as I remove the _() it works just fine.

Any clues as to what could be the cause? (I am running Django 1.1 on a
local desktop, using the development server).

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.