Re: RadioSelect widget not rendering

2009-04-14 Thread Daniel Roseman

On Apr 15, 7:10 am, Adam Yee  wrote:
> Can't get the forms.RadioSelect widget to render.  I'm using svn
> 10559, I've looked over forms/widgets.py, but I don't know...  I'm
> able to use forms.CheckboxSelect just fine.
>
> Is it Firefox giving me issues?  What's going on here?
>
> #forms.py
> class PollForm(forms.Form):
>     def make_fields(self, poll):
>         for c in poll.choice_set.iterator():
>             self.fields[c.choice] = forms.CharField
> (widget=forms.RadioSelect, label=c.choice)
>

What is this make_fields? Where did you get it from? What calls it?

If you want to create a dynamic field with choices from a queryset,
the usual way to do this is in the __init__ method.

And it won't work to declare a separate field for each choice. You
want a single field for 'polls', with the choices set to
poll.choice_set.all(). Even better, use a ModelChoiceField and use the
queryset argument.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



RadioSelect widget not rendering

2009-04-14 Thread Adam Yee

Can't get the forms.RadioSelect widget to render.  I'm using svn
10559, I've looked over forms/widgets.py, but I don't know...  I'm
able to use forms.CheckboxSelect just fine.

Is it Firefox giving me issues?  What's going on here?

#forms.py
class PollForm(forms.Form):
def make_fields(self, poll):
for c in poll.choice_set.iterator():
self.fields[c.choice] = forms.CharField
(widget=forms.RadioSelect, label=c.choice)

#template

{{ form.as_p }}



#source output from Firefox (missing fields)

Cable: 

Satelite: 

Regular TV: 




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



Re: residual fields admin error

2009-04-14 Thread zayatzz

i think the change has not hit the database. if your database is still
empty then try doing python manage.py reset appname - that clears
whole app database though.

Alan

On Apr 15, 6:24 am, CrabbyPete  wrote:
> I am just starting coding with django. So please bear with me.
>
> I made a change to my User model so the field email_addr is now email.
> I deleted the database, made new tables with manage.py, did a resync,
> and changed all the code that refered to email_addr to email.
> Everything looks fine, but I still get Ithe following error  when I
> looked at my database with the admin. Is there some
>
> Caught an exception while rendering: 'User' object has no attribute
> 'email_addr'Request Method: GET
> Request URL:http://localhost:8000/admin/base/message/1/
> Exception Type: TemplateSyntaxError
> Exception Value: Caught an exception while rendering: 'User' object
> has no attribute 'email_addr'
> Exception Location: C:\Python26\lib\site-packages\django\template
> \debug.py in render_node, line 81
> Python Executable: C:\Python26\pythonw.exe
> Python Version: 2.6.1
> Python Path: [u'C:\\Django\\spot', u'C:\\Django', 'C:\\Documents and
> Settings\\pdouma\\Application Data\\PyScripter', 'C:\\Python26\\lib\
> \site-packages\\setuptools-0.6c9-py2.6.egg', 'C:\\Python26\\lib\\site-
> packages\\elixir-0.6.1-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \tesla-0.2.5-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \authkit-0.4.3-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \migrate-0.2.2-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \pil-1.1.7a2-py2.6-win32.egg', 'C:\\Python26\\lib\\site-packages\
> \pylint-0.18.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \logilab_astng-0.19.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
> \logilab_common-0.39.0-py2.6.egg', 'C:\\WINDOWS\\system32\
> \python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\
> \Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\
> \Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\
> \site-packages\\PIL', 'C:\\Python26\\lib\\site-packages\\win32', 'C:\
> \Python26\\lib\\site-packages\\win32\\lib', 'C:\\Python26\\lib\\site-
> packages\\Pythonwin']
> Server time: Tue, 14 Apr 2009 16:36:05 -0400
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models.py - retrieve information from other models via ForeignKey field?

2009-04-14 Thread zayatzz

well, im also a beginner but i think this should help you :

http://docs.djangoproject.com/en/dev/ref/models/querysets/

Scroll down abit. there is example about books and authors which have
quite similar relations to your models. In any case your information
should e possible to get with one django query or queryset

Alan.

On Apr 15, 5:06 am, Emma F  wrote:
> I feel like there must be something very elementary that I'm missing
> here, but I've been all through the documentation and can't figure it
> out.
>
> Say an app includes three models:
>
>  -  "Products"
> (includes fields: Product Name, Supplier, Cost Price, Retail Price
>
> - "Customers"
> (includes fields: Customer Name, Address, Contact Number, Payment
> Details)
>
> - "Orders", a list of individual orders placed with the business.
> (includes fields: Product Name, Customer Name, Delivery Address,
> Price, Payment Details)
>
> The Product Name and Customer Name fields in "Orders" are ForeignKey
> fields linked to the relevant models.  Each Order only involves one
> Product and one Customer.
>
> My question: Is it then possible to autopopulate the other fields in
> the Orders model (eg. delivery address, payment details, retail price)
> with the corresponding default information associated with that
> Product or Customer?  I'm using hooks to the save(self) process in the
> admin, and it's working fine for hard-coded values, but I can't get it
> to go to the related objects for data.
>
> I'd be very grateful for any nudge in the right direction.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Different approach?

2009-04-14 Thread Mariano Sokal
Well, i'm also new :)

I've been using django for a couple of days trying to learn while developing
a Pizza Delivery Software... (yes, I got bored doing blogs) and since it is
not a traditional website where one has an admin area and a
regular-user-live-site area, I feel that almost every functionality that I
want for my app can be accomplished just by using admin.

Ok, as I told you, I am new... but I need to add customers, add addresses,
add orders... and after doing all the models and registering the admin
models I feel that I'm almost done with the application. Is that the way you
do an application where there's no public website but is more like a
point-of-sale?

Regards,
Mariano

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



residual fields admin error

2009-04-14 Thread CrabbyPete

I am just starting coding with django. So please bear with me.

I made a change to my User model so the field email_addr is now email.
I deleted the database, made new tables with manage.py, did a resync,
and changed all the code that refered to email_addr to email.
Everything looks fine, but I still get Ithe following error  when I
looked at my database with the admin. Is there some

Caught an exception while rendering: 'User' object has no attribute
'email_addr'Request Method: GET
Request URL: http://localhost:8000/admin/base/message/1/
Exception Type: TemplateSyntaxError
Exception Value: Caught an exception while rendering: 'User' object
has no attribute 'email_addr'
Exception Location: C:\Python26\lib\site-packages\django\template
\debug.py in render_node, line 81
Python Executable: C:\Python26\pythonw.exe
Python Version: 2.6.1
Python Path: [u'C:\\Django\\spot', u'C:\\Django', 'C:\\Documents and
Settings\\pdouma\\Application Data\\PyScripter', 'C:\\Python26\\lib\
\site-packages\\setuptools-0.6c9-py2.6.egg', 'C:\\Python26\\lib\\site-
packages\\elixir-0.6.1-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\tesla-0.2.5-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\authkit-0.4.3-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\migrate-0.2.2-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\pil-1.1.7a2-py2.6-win32.egg', 'C:\\Python26\\lib\\site-packages\
\pylint-0.18.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\logilab_astng-0.19.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\logilab_common-0.39.0-py2.6.egg', 'C:\\WINDOWS\\system32\
\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\
\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\
\Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\
\site-packages\\PIL', 'C:\\Python26\\lib\\site-packages\\win32', 'C:\
\Python26\\lib\\site-packages\\win32\\lib', 'C:\\Python26\\lib\\site-
packages\\Pythonwin']
Server time: Tue, 14 Apr 2009 16:36:05 -0400


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



Re: NetBeans IDE for Python

2009-04-14 Thread Frank Liu

Why don't people use komodo edit. It's free and import works(mostly).
It's got project browser, snippets, and commands, and works in mac/
linux/windows. There's even a django syntax highlighter plugin and an
sqlite db browser plugin.  Oh, you can also write macros for it in
python or javascript (funny the whole thing is firefox based).

The only thing is it's somewhat slow to start compare to my previously
fav gvim. But i guess it's worth it.

Frank

On Apr 14, 6:51 pm, Victor Hooi  wrote:
> heya,
>
> I'm still a bit confused as to how to setup Django to work with
> Netbeans.
>
> I'm using Netbeans 6.7 M3 from here:
>
> http://bits.netbeans.org/download/6.7/m3/
>
> I've created a new Django project using django-admin, e.g.:
>
> django-admin.py startproject testproject
>
> and then I'm creating a new "Python Project with Existing Sources",
> and pointing it to the "testproject" directory".
>
> In project properties, I've set Main Module to "manage.py", and
> Application Arguments to "runserver --noreload" (thanks 
> tohttp://esauro.wordpress.com/2008/11/21/django-on-netbeans-65/), so
> that takes care of running the server when I click Run.
>
> However, how should I go about setting up autocompletion? It doesn't
> seem to recognise Django, and using Ctrl-Space on say,
> "django.db.models." just brings up a random list of Python options?
> And when I start typing, I don't get a list of models, as people up
> above seem to be getting on occasion.
>
> What settings should I change in the project in order to import it
> correctly, and get autocomplete and the like working?
>
> Cheers,
> Victor
>
> On Feb 26, 6:11 pm, "bruce.hpshare"  wrote:
>
> > It's a good news for the django develpement ...
>
> > 2009-02-26
>
> > bruce.hpshare
>
> > 发件人: पुनित मदान
> > 发送时间: 2009-02-26  15:31:41
> > 收件人: django-users
> > 抄送:
> > 主题: Re: NetBeans IDE for Python
>
> > u dont need to move django ... but need to configure python path in project 
> > properties 
>
> > 2009/2/26 Amirouche aka Mouche 
>
> > It looks like they plan to give some love to django in the next
> > release
>
> >http://wiki.netbeans.org/Python70Roadmap
>
> > here is the pre-beta nb 7http://bits.netbeans.org/download/6.7/m2/
>
> > their is a ruby column but no python ! Hell ! I wonder why ! Is ruby
> > that mainstream ?
>
> > can't try it myself now, hope it helps !
>
> > On Feb 26, 5:38 am, Amirouche aka Mouche
>
> >  wrote:
> > > On Feb 4, 10:54 pm, phillc  wrote:
>
> > > > mine wasnt working exactly as you all described it...
>
> > > > until i moved my django symlink to someplace else on my python path...
> > > > and it suddenly worked its really odd.
>
> > > uhh what do you mean ?
>
> > > > On Feb 3, 12:49 am, mrsixcount  wrote:
>
> > > > > Can't seem to get the auto complete to work when I import
> > > > > django.db.models as models.  Shows models when I start typing but
> > > > > after the . nothing in the django model section comes up.  Shows the
> > > > > master list of python options.  IntegerField isn't in there nor could
> > > > > I find any of the other ones.  Oh well hopefully it will be out soon
> > > > > with more support for Django
>
> > > > > On Jan 17, 3:29 am, Gautam  wrote:
>
> > > > > > There is some problem with the parser recognizing package imports in
> > > > > > the from ... import ... syntax. What seems to work is if you import
> > > > > > packages directly as import ... as 
>
> > > > > > So for the django models import as:
>
> > > > > > import django.db.models as models
>
> > > > > > And voila, completion in Netbeans works!
>
> > > > > > On Nov 20 2008, 5:01 pm, lig  wrote:
>
> > > > > > > On 19 нояб, 21:22, Delta20  wrote:
>
> > > > > > > > NetBeans for Python has been released and based on the NB Python
> > > > > > > > roadmap, it looks interesting for those of us working with 
> > > > > > > > Django. I
> > > > > > > > haven't had much of a chance to play with it yet since it just 
> > > > > > > > came
> > > > > > > > out today, but here's the info for anyone interested:
>
> > > > > > > > NetBeans IDE for 
> > > > > > > > Python:http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
>
> > > > > > > from django.db import models
>
> > > > > > > class Page(models.Model):
> > > > > > >     name    = models. # hitting Ctrl+Space here don't show field 
> > > > > > > type
> > > > > > > suggestions or anything from imported models package
>
> > --
> > If you spin an oriental man, does he become disoriented?
> > (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> > is der net süß » ε(●̮̮̃•̃)з
> > -PM
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/g

Re: Target WSGI script cannot be loaded as Python module

2009-04-14 Thread Thierry

Hello world with import socket gave me the same issue.  I just re-
installed Python 2.6, more specifically 2.6.2 and everything is
working fine, thanks for your help.

On Apr 14, 10:25 pm, Graham Dumpleton 
wrote:
> On Apr 15, 12:07 pm, Thierry  wrote:
>
>
>
> > I'm currently running Apache 2.2 on Windows and I can get the hello
> > world of modwsgi to run.  However, when I configure my Django project,
> > Apache has the following errors from the error.log file:
>
> > mod_wsgi (pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
> > mysite.wsgi' cannot be loaded as Python module.
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] mod_wsgi
> > (pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
> > mysite/apache/mysite.wsgi'.
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] Traceback (most
> > recent call last):
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:/
> > django_proj/mysite/apache/mysite.wsgi", line 7, in 
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> > django.core.handlers.wsgi
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
> > 8, in 
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     from django
> > import http
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in
> > 
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     from urllib
> > import urlencode
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\urllib.py", line 26, in 
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> > socket
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\socket.py", line 46, in 
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> > _socket
> > [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] ImportError: DLL
> > load failed: The specified module could not be found.
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
> > (pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
> > mysite.wsgi' cannot be loaded as Python module.
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
> > (pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
> > mysite/apache/myite.wsgi'.
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] Traceback (most
> > recent call last):
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:/
> > django_proj/mysite/apache/mysite.wsgi", line 7, in 
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> > django.core.handlers.wsgi
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
> > 8, in 
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     from django
> > import http
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in
> > 
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     from urllib
> > import urlencode
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\urllib.py", line 26, in 
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> > socket
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> > \Python26\\lib\\socket.py", line 46, in 
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> > _socket
> > [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] ImportError: DLL
> > load failed: The specified module could not be found.
>
> > My 'C:/django_proj/mysite/apache/mysite.wsgi' is the following:
> > import os, sys
> > sys.path.append('C:/django_proj')
> > sys.path.append('C:/django_proj/mysite')
>
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> > import django.core.handlers.wsgi
> > application = django.core.handlers.wsgi.WSGIHandler()
>
> > The apache conf is:
> > Alias /media/ "C:/django_proj/mysite/media/"
>
> > 
> >     Order allow,deny
> >     Options Indexes
> >     Allow from all
> >     IndexOptions FancyIndexing
> > 
>
> > WSGIScriptAlias /blah "C:/django_proj/mysite/apache/mysite.wsgi"
>
> > 
> >     Order allow,deny
> >     Allow from all
> > 
>
> > I'm trying to run the above locally by accessing:http://localhost/blah,
> > I get the 500 Internal Server Error.  Can anyone tell me what I'm
> > missing?
>
> This is not a Django problem, there is something wrong with how Python
> is installed on your system.
>
> Replace your Django WSGI script file with:
>
>   # Attempt to import 'socket' module.
>
>   import socket
>
>   # Now for the hello world application.
>
>   def application(environ, start_response):
>     status = '200 OK'
>     output = 'Hello World!'
>
>     response_he

Re: NetBeans IDE for Python

2009-04-14 Thread Victor Hooi

heya,

I'm still a bit confused as to how to setup Django to work with
Netbeans.

I'm using Netbeans 6.7 M3 from here:

http://bits.netbeans.org/download/6.7/m3/

I've created a new Django project using django-admin, e.g.:

django-admin.py startproject testproject

and then I'm creating a new "Python Project with Existing Sources",
and pointing it to the "testproject" directory".

In project properties, I've set Main Module to "manage.py", and
Application Arguments to "runserver --noreload" (thanks to
http://esauro.wordpress.com/2008/11/21/django-on-netbeans-65/), so
that takes care of running the server when I click Run.

However, how should I go about setting up autocompletion? It doesn't
seem to recognise Django, and using Ctrl-Space on say,
"django.db.models." just brings up a random list of Python options?
And when I start typing, I don't get a list of models, as people up
above seem to be getting on occasion.

What settings should I change in the project in order to import it
correctly, and get autocomplete and the like working?

Cheers,
Victor

On Feb 26, 6:11 pm, "bruce.hpshare"  wrote:
> It's a good news for the django develpement ...
>
> 2009-02-26
>
> bruce.hpshare
>
> 发件人: पुनित मदान
> 发送时间: 2009-02-26  15:31:41
> 收件人: django-users
> 抄送:
> 主题: Re: NetBeans IDE for Python
>
> u dont need to move django ... but need to configure python path in project 
> properties 
>
> 2009/2/26 Amirouche aka Mouche 
>
> It looks like they plan to give some love to django in the next
> release
>
> http://wiki.netbeans.org/Python70Roadmap
>
> here is the pre-beta nb 7http://bits.netbeans.org/download/6.7/m2/
>
> their is a ruby column but no python ! Hell ! I wonder why ! Is ruby
> that mainstream ?
>
> can't try it myself now, hope it helps !
>
> On Feb 26, 5:38 am, Amirouche aka Mouche
>
>
>
>
>
>  wrote:
> > On Feb 4, 10:54 pm, phillc  wrote:
>
> > > mine wasnt working exactly as you all described it...
>
> > > until i moved my django symlink to someplace else on my python path...
> > > and it suddenly worked its really odd.
>
> > uhh what do you mean ?
>
> > > On Feb 3, 12:49 am, mrsixcount  wrote:
>
> > > > Can't seem to get the auto complete to work when I import
> > > > django.db.models as models.  Shows models when I start typing but
> > > > after the . nothing in the django model section comes up.  Shows the
> > > > master list of python options.  IntegerField isn't in there nor could
> > > > I find any of the other ones.  Oh well hopefully it will be out soon
> > > > with more support for Django
>
> > > > On Jan 17, 3:29 am, Gautam  wrote:
>
> > > > > There is some problem with the parser recognizing package imports in
> > > > > the from ... import ... syntax. What seems to work is if you import
> > > > > packages directly as import ... as 
>
> > > > > So for the django models import as:
>
> > > > > import django.db.models as models
>
> > > > > And voila, completion in Netbeans works!
>
> > > > > On Nov 20 2008, 5:01 pm, lig  wrote:
>
> > > > > > On 19 нояб, 21:22, Delta20  wrote:
>
> > > > > > > NetBeans for Python has been released and based on the NB Python
> > > > > > > roadmap, it looks interesting for those of us working with 
> > > > > > > Django. I
> > > > > > > haven't had much of a chance to play with it yet since it just 
> > > > > > > came
> > > > > > > out today, but here's the info for anyone interested:
>
> > > > > > > NetBeans IDE for 
> > > > > > > Python:http://download.netbeans.org/netbeans/6.5/python/ea/
> > > > > > > NB Python Roadmap:http://wiki.netbeans.org/Python
>
> > > > > > from django.db import models
>
> > > > > > class Page(models.Model):
> > > > > >     name    = models. # hitting Ctrl+Space here don't show field 
> > > > > > type
> > > > > > suggestions or anything from imported models package
>
> --
> If you spin an oriental man, does he become disoriented?
> (-: ¿ʇɥǝɹpɹǝʌ ɟdoʞ uǝp ɹıp ɥɔı ,qɐɥ 'ɐɐu
>
> is der net süß » ε(●̮̮̃•̃)з
> -PM

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



Models.py - retrieve information from other models via ForeignKey field?

2009-04-14 Thread Emma F

I feel like there must be something very elementary that I'm missing
here, but I've been all through the documentation and can't figure it
out.

Say an app includes three models:

 -  "Products"
(includes fields: Product Name, Supplier, Cost Price, Retail Price

- "Customers"
(includes fields: Customer Name, Address, Contact Number, Payment
Details)

- "Orders", a list of individual orders placed with the business.
(includes fields: Product Name, Customer Name, Delivery Address,
Price, Payment Details)

The Product Name and Customer Name fields in "Orders" are ForeignKey
fields linked to the relevant models.  Each Order only involves one
Product and one Customer.

My question: Is it then possible to autopopulate the other fields in
the Orders model (eg. delivery address, payment details, retail price)
with the corresponding default information associated with that
Product or Customer?  I'm using hooks to the save(self) process in the
admin, and it's working fine for hard-coded values, but I can't get it
to go to the related objects for data.

I'd be very grateful for any nudge in the right direction.


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



Re: Two projects, one admin, filebrowser

2009-04-14 Thread Micah Ransdell
If you are just wanting to serve out the files on the public site then you
can just copy them over from the media/uploads folder on the intranet site,
to the media/uploads folder on the public site. You can setup an cron job or
simple post_save signal on the private side that automatically copies the
files over.

Micah

On Tue, Apr 14, 2009 at 5:56 PM, shacker  wrote:

>
> We're building an intranet and a public site that share a lot of data
> but without shared views. Therefore we're building them as two
> distinct Django projects connecting to a single shared database, with
> shared apps. To reduce confusion, the contrib.admin is only enabled on
> the intranet side, not on the public side (one database, one admin
> site seemed to make sense).
>
> All is going well, but we just hit a puzzle:  After installing django-
> filebrowser and integrating it into some admin views and flat pages,
> we found that it (of course) only uploads media into media/uploads  on
> the intranet side. If you create a flat page with uploaded media and
> view it on the public site, images are broken because their URLs are /
> media/uploads The path is technically correct, but points to the
> file tree on the intranet side. There doesn't seem to be a way to tell
> filebrowser which filesystem to upload into. Selecting a "Site" in the
> flatpage editor doesn't communicate that info to filebrowser, of
> course.
>
> At this point I'm thinking the only way to resolve this is going to be
> to have two /admin sites after all, rather than one. Or is there
> another/better way to solve this?
>
> Thanks,
> Scot
>
> >
>

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



Re: Target WSGI script cannot be loaded as Python module

2009-04-14 Thread Graham Dumpleton



On Apr 15, 12:07 pm, Thierry  wrote:
> I'm currently running Apache 2.2 on Windows and I can get the hello
> world of modwsgi to run.  However, when I configure my Django project,
> Apache has the following errors from the error.log file:
>
> mod_wsgi (pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
> mysite.wsgi' cannot be loaded as Python module.
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] mod_wsgi
> (pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
> mysite/apache/mysite.wsgi'.
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] Traceback (most
> recent call last):
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:/
> django_proj/mysite/apache/mysite.wsgi", line 7, in 
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> django.core.handlers.wsgi
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
> 8, in 
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     from django
> import http
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in
> 
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     from urllib
> import urlencode
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\urllib.py", line 26, in 
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> socket
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\socket.py", line 46, in 
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]     import
> _socket
> [Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] ImportError: DLL
> load failed: The specified module could not be found.
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
> (pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
> mysite.wsgi' cannot be loaded as Python module.
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
> (pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
> mysite/apache/myite.wsgi'.
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] Traceback (most
> recent call last):
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:/
> django_proj/mysite/apache/mysite.wsgi", line 7, in 
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> django.core.handlers.wsgi
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
> 8, in 
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     from django
> import http
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in
> 
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     from urllib
> import urlencode
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\urllib.py", line 26, in 
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> socket
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
> \Python26\\lib\\socket.py", line 46, in 
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]     import
> _socket
> [Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] ImportError: DLL
> load failed: The specified module could not be found.
>
> My 'C:/django_proj/mysite/apache/mysite.wsgi' is the following:
> import os, sys
> sys.path.append('C:/django_proj')
> sys.path.append('C:/django_proj/mysite')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> The apache conf is:
> Alias /media/ "C:/django_proj/mysite/media/"
>
> 
>     Order allow,deny
>     Options Indexes
>     Allow from all
>     IndexOptions FancyIndexing
> 
>
> WSGIScriptAlias /blah "C:/django_proj/mysite/apache/mysite.wsgi"
>
> 
>     Order allow,deny
>     Allow from all
> 
>
> I'm trying to run the above locally by accessing:http://localhost/blah,
> I get the 500 Internal Server Error.  Can anyone tell me what I'm
> missing?

This is not a Django problem, there is something wrong with how Python
is installed on your system.

Replace your Django WSGI script file with:

  # Attempt to import 'socket' module.

  import socket

  # Now for the hello world application.

  def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

and you will likely get a similar result, because the import of
'socket' will fail.

When you install Python, ensure you did so as an account with
Administrator rights and select that you want to make it available to
all users on the system. If you don't 

Target WSGI script cannot be loaded as Python module

2009-04-14 Thread Thierry

I'm currently running Apache 2.2 on Windows and I can get the hello
world of modwsgi to run.  However, when I configure my Django project,
Apache has the following errors from the error.log file:

mod_wsgi (pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
mysite.wsgi' cannot be loaded as Python module.
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
mysite/apache/mysite.wsgi'.
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] Traceback (most
recent call last):
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:/
django_proj/mysite/apache/mysite.wsgi", line 7, in 
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] import
django.core.handlers.wsgi
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
8, in 
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] from django
import http
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in

[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] from urllib
import urlencode
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\urllib.py", line 26, in 
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] import
socket
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\socket.py", line 46, in 
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] import
_socket
[Tue Apr 14 21:59:21 2009] [error] [client 127.0.0.1] ImportError: DLL
load failed: The specified module could not be found.
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=5956): Target WSGI script 'C:/django_proj/mysite/apache/
mysite.wsgi' cannot be loaded as Python module.
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] mod_wsgi
(pid=5956): Exception occurred processing WSGI script 'C:/django_proj/
mysite/apache/myite.wsgi'.
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] Traceback (most
recent call last):
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:/
django_proj/mysite/apache/mysite.wsgi", line 7, in 
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] import
django.core.handlers.wsgi
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line
8, in 
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] from django
import http
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\site-packages\\django\\http\\__init__.py", line 5, in

[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] from urllib
import urlencode
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\urllib.py", line 26, in 
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] import
socket
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1]   File "C:\
\Python26\\lib\\socket.py", line 46, in 
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] import
_socket
[Tue Apr 14 21:59:24 2009] [error] [client 127.0.0.1] ImportError: DLL
load failed: The specified module could not be found.

My 'C:/django_proj/mysite/apache/mysite.wsgi' is the following:
import os, sys
sys.path.append('C:/django_proj')
sys.path.append('C:/django_proj/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

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

The apache conf is:
Alias /media/ "C:/django_proj/mysite/media/"


Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing


WSGIScriptAlias /blah "C:/django_proj/mysite/apache/mysite.wsgi"


Order allow,deny
Allow from all


I'm trying to run the above locally by accessing: http://localhost/blah,
I get the 500 Internal Server Error.  Can anyone tell me what I'm
missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sending large, generated files

2009-04-14 Thread Graham Dumpleton



On Apr 15, 7:49 am, Alex Loddengaard  wrote:
> I've found several messages on this list discussing ways to send large files
> in a HttpResponse.  One can use FileWrapper, or one can use a generator and
> yield chunks of the large file.  What about the case when the large file is
> generated at HTTP request time?  In this case, it would be annoying to have
> the user wait for the page to generate the large file and then stream the
> file.  Instead we would want a way to start the HTTP response (so that the
> user gets the download dialogue), generate the large file, and then stream
> the file.  Let's take the following example:
>
> def create_tarball():
>
> >   path = create_some_big_tarball()
>
> >   chunk = None
> >   fh = open(path, 'r')
> >   while True:
> >     chunk = fh.read(1024 * 128)
> >     if chunk == '':
> >       break
> >     yield chunk
>
> > def sample_view(request):
> >   response = HttpResponse(create_tarball(),
> > mimetype='application/x-compressed')
> >   response['Content-Disposition'] = "attachment;filename=mytarball.tar.gz"
>
> The above example nearly accomplishes what we want, but it doesn't start the
> HTTP response before the tarball is created, hence making the user wait a
> long time before the download dialogue box shows up.  Let's try something
> like this (notice the addition of a noop yield):
>
> def create_tarball():
>
>   yield '' # noop to send the HTTP headers
>
> >   path = create_some_big_tarball()
>
> >   chunk = None
> >   fh = open(path, 'r')
> >   while True:
> >     chunk = fh.read(1024 * 128)
> >     if chunk == '':
> >       break
> >     yield chunk
>
> > def sample_view(request):
> >   response = HttpResponse(create_tarball(),
> > mimetype='application/x-compressed')
> >   response['Content-Disposition'] = "attachment;filename=mytarball.tar.gz"
>
> The issue with the above example is that the "yield ''" seems to be
> ignored.  HTTP headers are not sent before the tarball is created.
> Similarly, "yield ' '" and "yield None" don't work, because they corrupt the
> tarball (HttpResponse calls str() on the iterable items given to the
> HttpResponse constructor).  As a temporary solution, we're writing an empty
> gzip file in the first yield.  Our large tarball is gzipped, and since gzip
> files can be concatenated to one and other, our hack seems to be working.
> In the above example, replace the first "yield ''" with:
>
>   noop = StringIO.StringIO()
>
> >   empty = gzip.GzipFile(mode='w', fileobj=noop)
> >   empty.write("")
> >   empty.close()
> >   yield noop.getvalue()
>
> I'm wondering if there is a better way to accomplish this?  I don't quite
> understand why HTTP responses are written to stdout.  Possibly orthogonal to
> that, it seems like, in theory, yielding an empty value in the generator
> should work, because a flush is called after the HTTP headers are written.
> Any ideas, either on how to solve this problem with the Django API, or on
> why Django doesn't send HTTP headers on a "yield ''"?

>From memory, file wrappers at django level, in order to work across
different hosting mechanisms supported, only allow a file name to be
supplied. At the WSGI level the file wrapper actually takes a file
like object. If you were doing this in raw WSGI, you could run your
tar ball creation as a separately exec'd pipeline and rather than
create a file in the file system, have tar output to the pipeline,
ie., use '-' instead of filename. The file object resulting from the
pipeline could then be used as input to the WSGI file wrapper object.

So, if this operation isn't somehow bound into needing Django itself,
and this is important to you, maybe you should create a separate
little WSGI application just for this purpose.

Actually, even if bound into needing Django you may still be able to
do it. Using mod_wsgi, you could even delegate the special WSGI
application to run in same process as Django and mount it at a URL
which appears within Django application. Because though you are side
stepping Django dispatch, you couldn't though have it be protected by
Django based form authentication.

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



Re: Random Syntax Errors on Download

2009-04-14 Thread James Bennett

On Tue, Apr 14, 2009 at 11:59 AM, AliasXNeo  wrote:
> The problem is intriguing, and I attempted to download and install the
> official release 3 more times and then proceeded to get the latest
> develepor release from SVN only to get the same exact problem. I'm
> running the latest version of Python 3 on standard Windows XP. My
> question is, why are these random syntax errors showing up and how can
> I fix it?

You can fix it by using a supported version of Python:

http://docs.djangoproject.com/en/dev/faq/install/#can-i-use-django-with-python-3-0


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: How do you retrieve a username that is not in the URL?

2009-04-14 Thread James Bennett

On Tue, Apr 14, 2009 at 5:12 PM, stkpoi  wrote:
>    if form.is_valid():
>      submission = Submission.objects.get_or_create(
>      title=form['title'],
>      link=form['link'],
>      user=request.user.username
>      )

And right there's your problem. The value to put into a ForeignKey is
the actual User object itself, not its id or username or some other
attribute. The error message you're seeing is a consequence of putting
the wrong value in there.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: Converting from local DST to UTC

2009-04-14 Thread Brian Neal

On Apr 14, 7:26 pm, Jamie  wrote:
> I am working on an app that will export a calendar event to Google
> Calendar. Google Calendar requires that event datetimes be in UTC
> format. I can make the conversion from local (America/New_York) to UTC
> using pytz, but the time is off by an hour due to daylight savings
> time (Python thinks the offset is -0500 rather than -0400) so all of
> my exported events are off as a result.

pytz does adjust for daylight savings time, that is one of its primary
jobs.

>
> I'm first taking the naive datetime stored by Django and adding the
> local timezone pulled from settings.py then using astimezone(pytz.utc)
> to make the conversion to UTC. I'm not sure how to adjust for DST,
> especially since all the events will be in the future and DST will
> have to be calculated for each of them.

Try using 'US/Eastern' instead of 'America/New_York'. It might be
different.

This is how I am doing it (I'm also integrating with Google Calendar):

from django.utils.tzinfo import FixedOffset

d = datetime.datetime.now()
tz_name = 'US/Eastern'  # or whatever
tz = pytz.timezone(tz_name)  # create timezone
local = tz.localize(d)  # make naive datetime localized
zulu = local.astimezone(FixedOffset(0))  # convert to UTC
s = zulu.strftime('%Y-%m-%dT%H:%M:%S.000Z')

I think I probably could have used pytz.utc instead of FixedOffset(0).
It's the same idea. But at least now this thread has Django
content. :-)

Hope that helps,
BN





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



Error: no module named manager

2009-04-14 Thread Daniel Sisco

All:

I'm adding an app (from django snippits) that is just a template tag
for a calendar application in my blog. This is the new directory
structure:

/apps/postcal
  |
  --> __init__.py
  |
  --> /templatetags
|
--> __init__.py
|
--> calendar.py

settings.py has been modified to include postcal as such:

ADDITIONAL_APPS = (
'recaptcha',
'pingback',
'watchlist',
'blogroll',
'robots',
'django.contrib.admindocs',
'gravatar',
'userdata',
'thumbnail',
'postcal',
)

Calls to manage.py that worked fine before, now throw the error:
"Error: no module named manager".

calendar.py is:

from datetime import date, timedelta
from django import template
from blog.models import Post

register = template.Library()

def get_last_day_of_month(year, month):
if (month == 12):
year += 1
month = 1
else:
month += 1
return date(year, month, 1) - timedelta(1)

def month_cal(year, month):
post_list = Post.objects.filter(date__year=year,
date__month=month)

first_day_of_month = date(year, month, 1)
last_day_of_month = get_last_day_of_month(year, month)
first_day_of_calendar = first_day_of_month - timedelta
(first_day_of_month.weekday())
last_day_of_calendar = last_day_of_month + timedelta(7 -
last_day_of_month.weekday())

month_cal = []
week = []
week_headers = []

i = 0
day = first_day_of_calendar
while day <= last_day_of_calendar:
if i < 7:
week_headers.append(day)
cal_day = {}
cal_day['day'] = day
cal_day['event'] = False
for post in post_list:
if day >= post.date.date() and day <= post.date.date():
cal_day['event'] = True
if day.month == month:
cal_day['in_month'] = True
else:
cal_day['in_month'] = False
week.append(cal_day)
if day.weekday() == 6:
month_cal.append(week)
week = []
i += 1
day += timedelta(1)

return {'calendar': month_cal, 'headers': week_headers}

register.inclusion_tag('templatetags/calendar.html')(month_cal)

Any suggestions??

Thanks!

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



Re: Sending large, generated files

2009-04-14 Thread Ryan Kelly

> Looking at the code for the wsgi handler, it does call start_response()
> before processing any of the response body - my understanding is that
> this should cause the headers to be sent immediately.

Humph, looks like my understanding isn't so hot - PEP 333 explicitly
forbids start_response from sending the headers.  Nevertheless, I'd be
interested to hear if different deployment options affect the behaviour
of your examples.

 Cheers,

   Ryan

-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part


Re: Sending large, generated files

2009-04-14 Thread Ryan Kelly
> I've found several messages on this list discussing ways to send large
> files in a HttpResponse.  One can use FileWrapper, or one can use a
> generator and yield chunks of the large file.  What about the case
> when the large file is generated at HTTP request time?  In this case,
> it would be annoying to have the user wait for the page to generate
> the large file and then stream the file.  Instead we would want a way
> to start the HTTP response (so that the user gets the download
> dialogue), generate the large file, and then stream the file.
>
> [..snip..]
>
> The issue with the above example is that the "yield ''" seems to be
> ignored.  HTTP headers are not sent before the tarball is created.


Out of curiosity, what deployment method are you using?

Looking at the code for the wsgi handler, it does call start_response()
before processing any of the response body - my understanding is that
this should cause the headers to be sent immediately.  Have you tried
this under mod_wsgi?

 Cheers,

   Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part


Two projects, one admin, filebrowser

2009-04-14 Thread shacker

We're building an intranet and a public site that share a lot of data
but without shared views. Therefore we're building them as two
distinct Django projects connecting to a single shared database, with
shared apps. To reduce confusion, the contrib.admin is only enabled on
the intranet side, not on the public side (one database, one admin
site seemed to make sense).

All is going well, but we just hit a puzzle:  After installing django-
filebrowser and integrating it into some admin views and flat pages,
we found that it (of course) only uploads media into media/uploads  on
the intranet side. If you create a flat page with uploaded media and
view it on the public site, images are broken because their URLs are /
media/uploads The path is technically correct, but points to the
file tree on the intranet side. There doesn't seem to be a way to tell
filebrowser which filesystem to upload into. Selecting a "Site" in the
flatpage editor doesn't communicate that info to filebrowser, of
course.

At this point I'm thinking the only way to resolve this is going to be
to have two /admin sites after all, rather than one. Or is there
another/better way to solve this?

Thanks,
Scot

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



Converting from local DST to UTC

2009-04-14 Thread Jamie

I am working on an app that will export a calendar event to Google
Calendar. Google Calendar requires that event datetimes be in UTC
format. I can make the conversion from local (America/New_York) to UTC
using pytz, but the time is off by an hour due to daylight savings
time (Python thinks the offset is -0500 rather than -0400) so all of
my exported events are off as a result.

This is a Python "problem," not a Django one, but I'm hoping someone
else has dealt with this issue and come up with a solution.

I'm first taking the naive datetime stored by Django and adding the
local timezone pulled from settings.py then using astimezone(pytz.utc)
to make the conversion to UTC. I'm not sure how to adjust for DST,
especially since all the events will be in the future and DST will
have to be calculated for each of them.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do you retrieve a username that is not in the URL?

2009-04-14 Thread stkpoi

#urls.py
urlpatterns = patterns('',
(r'^$', main_page),
# ...
(r'^submit/$', submit_page),
(r'^submit/success/$', direct_to_template,
 { 'template': 'submit/submit_success.html' }),
)

The error occurs at the "user=request.user.username" line in views.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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trying to wrap my head around nested regroups or other ways to handle ordered ForeignKey stuff

2009-04-14 Thread Daniel Roseman

On Apr 14, 6:11 pm, Kevin Cole  wrote:
> Hi,
>
> First let me say I've looked at documentation, but feel a bit dyslexic
> when it comes to this stuff.
>
> The situation: I have three tables: a service provider table with
> city, state abbreviation and country abbreviation (among other other
> info), a states table with state names, abbreviations, and other state
> info, and a country table with country names, abbreviations and other
> country info.  I want an output like:
> ___
>
> FULL COUNTRY NAME
>
>    Full State Name
>            City. Provider
>                        Provider
>            City. Provider
>
>     Full State Name
>            City. Provider
>                        Provider
>            City. Provider
>
> FULL COUNTRY NAME
> ___
>
> I only want Country and State headings for countries and states having
> providers.  Experimenting at the shell, it appears my model is okay:
> _
>
> >>> from mhd.models import *
> >>> countries = Country.objects.filter(iso2__in=["US","CA"]).distinct()
> >>> countries
>
>     [, ]
>
> >>> countries[0].state_set.all()
>
>     [, ,  Manitoba>, ...]
>
> >>> countries[1].state_set.all()
>
>     [, , , ...]>>> 
> countries[1].state_set.all()[1]
>
>     
>
> >>> countries[1].state_set.all()[1].provider_set.all()
>
>     []
>
> >>> countries[1].state_set.all()[1].provider_set.all()[0]
>
>     
>
> >>> countries[1].state_set.all()[1].provider_set.all()[0].practitioner
>
>     u'Anne B. ... PsyS, LPC'
>
> >>> countries[1].state_set.all()[1].provider_set.all()[0].city
>
>     u'Anchorage'
> _
>
> For the next 5 days, a whittled down version of what I thought I was
> trying to do lives on dpaste.com:
>
> http://dpaste.com/32704/model.pyhttp://dpaste.com/32755/views.pyhttp://dpaste.com/32706/listings.html
>  template
>
> However my later experiments in the manage.py shell (above) lead me to
> suspect maybe I'm bass-ackwards about the whole thing.  Unfortunately,
> suspecting that is still not enough to get me where I'm trying to go.
>
> Help?
>
> Thanks.

I very much doubt that select_related is the answer to your problem,
as proposed in your other post. select_related is purely for query
optimisation, and doesn't actually change the results of your queries.

That said, I am having trouble working out what your actual problem
is. If I understand correctly, it's how to order multiple nested query
sets. But in what way does the code you have posted fail to give the
right output? What does it actually give?

I can say that this line in your view:
providers = Provider.objects.order_by("country").order_by
("state").order_by("city")
does nothing at all. Each successive order_by will override the one
before.

I'm also intrigued by the way you've set up your tables. Are they
based on an already existing database schema? If not, I would
seriously reconsider the way you have the foreign keys set up to
reference character fields in the related model. Better to leave these
as the default so that Django manages the relationship with the
automatic 'id' field. (What happens if two states in different
countries have the same abbreviation?)

Looking closer, I suspect that the problem is that both state and
country are related to provider, instead of relying on the
relationship between state and country. I would leave out the FK from
provider to country, so the relationship goes like this:
provider -> state -> country
You might even think about having another intermediate model for City,
so the provider only has a relationship with that.

Finally, I would leave out all the 'regroup' tags. Your data is
already grouped, since it is in a set of nested relationships.

In the view, get all the countries that have providers:
countries = Country.objects.filter(state__provider__isnull=False)

And in the template, without all the table tags:
{% for country in countries %}
  {{ country.name }}
  {% for state in country.state_set.all %}
{{ state.name }}
{% for provider in state.provider_set.all %}
{{ provider.name }}
{% endfor %}
  {% endfor %}
{% endfor %}

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



Re: Grasping apps / projects and shared data

2009-04-14 Thread Daniel Roseman

On Apr 14, 9:47 pm, Leon  wrote:
> Hello!
>
> I'm new to django so far I like it, but I've now reached my first big
> hurdle.
>
> I'm building a page which has a cms in the root, which shows the main
> menu, and submenu of the site,
> but then I have a blog app and a gallery app which are coupled to a
> special section of the site, I still want the cms menues to work.
>
> Another example where this shows up.
> I have a site with groups that show information about the groups like
> a group name and such. I then have a blog app wich works well by it
> self, but i would like the blog app to filter out so that only the
> groups items are shown, but the blog app shouldn't know about the
> groups?
>
> How can I make the apps share data?
> Who's incharge of what?
> How can I make one app filter out data in another?
>
> Cheers
> // Leon

Template tags are your friend.
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/
http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Model Fields / Multi-table inheritance / get_db_prep_value / postgresql_psycopg2

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 6:00 PM, gordyt  wrote:

>
> I think I've tracked down the problem.  Here is a bit of code from
> django.db.models.fields.related.py:
>
>def get_db_prep_lookup(self, lookup_type, value):
># If we are doing a lookup on a Related Field, we must be
># comparing object instances. The value should be the PK of
> value,
># not value itself.
>def pk_trace(value):
># Value may be a primary key, or an object held in a
> relation.
># If it is an object, then we need to get the primary key
> value for
># that object. In certain conditions (especially one-to-
> one relations),
># the primary key may itself be an object - so we need to
> keep drilling
># down until we hit a value that can be used for a
> comparison.
>v, field = value, None
>try:
>while True:
>v, field = getattr(v, v._meta.pk.name), v._meta.pk
>
>except AttributeError:
>pass
>if field:
>if lookup_type in ('range', 'in'):
>v = [v]
>v = field.get_db_prep_lookup(lookup_type, v)
>if isinstance(v, list):
>v = v[0]
># BEGIN (got)
>else:
>field = self.rel.get_related_field()
>if field:
>v = field.get_db_prep_lookup(lookup_type, v)
># END (got)
>return v
>
> I added the part between BEGIN and END.
>
> The problem was that, for the child model in multi-table inheritance,
> its primary key in the database was being created by django as a
> OneToOneField (which is correct, of course), and it was creating the
> column using the proper type and everything, but you can see that
> without the little part that I added, the value was not being properly
> prepared for a lookup.
>
> --gordy
> >
>
Take a look at: http://code.djangoproject.com/ticket/10785

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: How do you retrieve a username that is not in the URL?

2009-04-14 Thread Daniel Roseman

On Apr 14, 11:12 pm, stkpoi  wrote:
> I would like the url to not include the user's name.  For example, it
> would be "/submit" and not "/submit/joe_user".
>
> request.user.username is not working for me.
>
> # Model
> class Submission(models.Model):
>     title = models.CharField(max_length=200)
>     link = models.URLField()
>     user = models.ForeignKey(User)
>
> # Form
> class SubmissionForm(forms.Form):
>   title = forms.CharField(max_length=200)
>   link = forms.URLField()
>
> # View
> def submit_page(request):
>   if request.method == 'POST':
>     form = SubmissionForm(request.POST)
>     if form.is_valid():
>       submission = Submission.objects.get_or_create(
>       title=form['title'],
>       link=form['link'],
>       user=request.user.username
>       )
>       return HttpResponseRedirect('/submit/submit_success.html')
>   else:
>     form = SubmissionForm()
>
>   variables = RequestContext(request, {
>     'form': form, 'user':request.user.username
>   })
>   return render_to_response('submit/submission.html', variables)
>
> # Result: Error binding parameter 1 - probably unsupported type


You haven't shown any code that puts the username in the URL, or
explained where that error appears, so it's hard to diagnose your
problem. It might help if you showed your urls.py.

If you don't want to put the username in the URL, don't put it there.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: textarea in ModelForm

2009-04-14 Thread Daniel Roseman

On Apr 14, 8:51 pm, grimmus  wrote:
> Thanks for the reply Alex,
>
> I am not really sure how i am supposed to override the default field
> type.
>
> The link talks about MyDateFormField() but is this a method or what ?
>
> Could you provide an example of how i could put the form field on the
> form instead of the model ?
>
> Thanks alot.
>

I can't really understand what you're not getting here. Model fields
go on the model, form fields go in the form.

class ContactEnquiry(models.Model):
    blah 
enquiry = models.CharField(max_length=100)

class ContactForm(ModelForm):
enquiry = forms.CharField(widget=forms.Textarea)


Or, if you use a TextField in the model, you will automatically get a
Textarea in the form and you won't need to override the field in the
form.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do you retrieve a username that is not in the URL?

2009-04-14 Thread stkpoi

I would like the url to not include the user's name.  For example, it
would be "/submit" and not "/submit/joe_user".

request.user.username is not working for me.

# Model
class Submission(models.Model):
title = models.CharField(max_length=200)
link = models.URLField()
user = models.ForeignKey(User)

# Form
class SubmissionForm(forms.Form):
  title = forms.CharField(max_length=200)
  link = forms.URLField()

# View
def submit_page(request):
  if request.method == 'POST':
form = SubmissionForm(request.POST)
if form.is_valid():
  submission = Submission.objects.get_or_create(
  title=form['title'],
  link=form['link'],
  user=request.user.username
  )
  return HttpResponseRedirect('/submit/submit_success.html')
  else:
form = SubmissionForm()

  variables = RequestContext(request, {
'form': form, 'user':request.user.username
  })
  return render_to_response('submit/submission.html', variables)

# Result: Error binding parameter 1 - probably unsupported type

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



Re: Custom Model Fields / Multi-table inheritance / get_db_prep_value / postgresql_psycopg2

2009-04-14 Thread gordyt

Here is a dpaste link to that same bit of code that looks nicer:

http://dpaste.com/hold/33474/

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



Sending large, generated files

2009-04-14 Thread Alex Loddengaard
I've found several messages on this list discussing ways to send large files
in a HttpResponse.  One can use FileWrapper, or one can use a generator and
yield chunks of the large file.  What about the case when the large file is
generated at HTTP request time?  In this case, it would be annoying to have
the user wait for the page to generate the large file and then stream the
file.  Instead we would want a way to start the HTTP response (so that the
user gets the download dialogue), generate the large file, and then stream
the file.  Let's take the following example:

def create_tarball():
>   path = create_some_big_tarball()
>
>   chunk = None
>   fh = open(path, 'r')
>   while True:
> chunk = fh.read(1024 * 128)
> if chunk == '':
>   break
> yield chunk
>
> def sample_view(request):
>   response = HttpResponse(create_tarball(),
> mimetype='application/x-compressed')
>   response['Content-Disposition'] = "attachment;filename=mytarball.tar.gz"
>

The above example nearly accomplishes what we want, but it doesn't start the
HTTP response before the tarball is created, hence making the user wait a
long time before the download dialogue box shows up.  Let's try something
like this (notice the addition of a noop yield):

def create_tarball():

  yield '' # noop to send the HTTP headers
>   path = create_some_big_tarball()
>
>   chunk = None
>   fh = open(path, 'r')
>   while True:
> chunk = fh.read(1024 * 128)
> if chunk == '':
>   break
> yield chunk
>
> def sample_view(request):
>   response = HttpResponse(create_tarball(),
> mimetype='application/x-compressed')
>   response['Content-Disposition'] = "attachment;filename=mytarball.tar.gz"
>

The issue with the above example is that the "yield ''" seems to be
ignored.  HTTP headers are not sent before the tarball is created.
Similarly, "yield ' '" and "yield None" don't work, because they corrupt the
tarball (HttpResponse calls str() on the iterable items given to the
HttpResponse constructor).  As a temporary solution, we're writing an empty
gzip file in the first yield.  Our large tarball is gzipped, and since gzip
files can be concatenated to one and other, our hack seems to be working.
In the above example, replace the first "yield ''" with:

  noop = StringIO.StringIO()
>   empty = gzip.GzipFile(mode='w', fileobj=noop)
>   empty.write("")
>   empty.close()
>   yield noop.getvalue()
>

I'm wondering if there is a better way to accomplish this?  I don't quite
understand why HTTP responses are written to stdout.  Possibly orthogonal to
that, it seems like, in theory, yielding an empty value in the generator
should work, because a flush is called after the HTTP headers are written.
Any ideas, either on how to solve this problem with the Django API, or on
why Django doesn't send HTTP headers on a "yield ''"?

Thanks!

Alex

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



Re: Custom Model Fields / Multi-table inheritance / get_db_prep_value / postgresql_psycopg2

2009-04-14 Thread gordyt

I think I've tracked down the problem.  Here is a bit of code from
django.db.models.fields.related.py:

def get_db_prep_lookup(self, lookup_type, value):
# If we are doing a lookup on a Related Field, we must be
# comparing object instances. The value should be the PK of
value,
# not value itself.
def pk_trace(value):
# Value may be a primary key, or an object held in a
relation.
# If it is an object, then we need to get the primary key
value for
# that object. In certain conditions (especially one-to-
one relations),
# the primary key may itself be an object - so we need to
keep drilling
# down until we hit a value that can be used for a
comparison.
v, field = value, None
try:
while True:
v, field = getattr(v, v._meta.pk.name), v._meta.pk

except AttributeError:
pass
if field:
if lookup_type in ('range', 'in'):
v = [v]
v = field.get_db_prep_lookup(lookup_type, v)
if isinstance(v, list):
v = v[0]
# BEGIN (got)
else:
field = self.rel.get_related_field()
if field:
v = field.get_db_prep_lookup(lookup_type, v)
# END (got)
return v

I added the part between BEGIN and END.

The problem was that, for the child model in multi-table inheritance,
its primary key in the database was being created by django as a
OneToOneField (which is correct, of course), and it was creating the
column using the proper type and everything, but you can see that
without the little part that I added, the value was not being properly
prepared for a lookup.

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



Re: django-grappelli setup problem

2009-04-14 Thread Karen Tracey
On Tue, Apr 14, 2009 at 2:36 PM, Lars Stavholm  wrote:

>
> Hi All,
>
> I'm trying to get django-grappelli running, but after following
> the installation instructions, I end up with a 404 and the following:
>
> Using the URLconf defined in bfact.urls, Django tried these URL
> patterns, in this order:
>
>   1. ^admin/(.*)
>   2. ^grappelli/ ^bookmark/add/$
>   3. ^grappelli/ ^bookmark/remove/$
>   4. ^grappelli/ ^help/(?P\d+)/$
>   5. ^grappelli/ ^help
>   6. ^grappelli/ ^obj_lookup/$
>   7. ^grappelli/ ^related_lookup/$
>   8. ^grappelli/ ^m2m_lookup/$
>   9. ^accounts/login/$
>  10. ^accounts/logout/$
>
> Notice the space after "grappelli/".
>
> Anyone else out there using django-grappelli?
> Any ideas as to what causes this?
>
> I'm using django-1.0.2 on Linux with latest grappelli from trunk.
>
> Any ideas appreciated


I don't know what grappelli is, but the "extra" space in the listing above
is normal when you have used include() (
http://docs.djangoproject.com/en/dev/topics/http/urls/#including-other-urlconfs)
as you apparently have for the ^grappelli/ pattern.  So the space isn't the
problem.

Unfortunately I can't give you any clue what the real problem is, since you
neglected to include the part of the debug output that shows what actual url
the dispatcher was attempting to match (the line that says "The current URL,
whatever/it/may/be/ didn't match any of these").  Whatever it is, it isn't
matching anything in that list.

Karen

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



Re: TreePanel in Django

2009-04-14 Thread Peter Herndon

I've done something similar using jquery and the dynatree plugin,
though the directory "structure" doesn't actually exist on the file
system of the server.  I'm building my tree from relationships stored
in the db.

Works for me so far, though I've yet to test with large quantities of objects.

---Peter

On 4/13/09, Eduardo Aragón Montes  wrote:
> Hi everyone..I'm new in django and I'm developing and app that have virtual
> storage for users...so i would like to do a treepanel for every user where
> they can see what files they have uploaded and if they want create folders
> and organize their files...I know i can use ext-js but i would like to know
> if anyone of you know other way to perform this...Thanks
>
> --
> Eduardo Aragón Montes
> Cel. 3113072880
>
> >
>

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



Grasping apps / projects and shared data

2009-04-14 Thread Leon

Hello!

I'm new to django so far I like it, but I've now reached my first big
hurdle.

I'm building a page which has a cms in the root, which shows the main
menu, and submenu of the site,
but then I have a blog app and a gallery app which are coupled to a
special section of the site, I still want the cms menues to work.

Another example where this shows up.
I have a site with groups that show information about the groups like
a group name and such. I then have a blog app wich works well by it
self, but i would like the blog app to filter out so that only the
groups items are shown, but the blog app shouldn't know about the
groups?

How can I make the apps share data?
Who's incharge of what?
How can I make one app filter out data in another?

Cheers
// Leon

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



Re: Temperature degree ascii code error on cvs output file

2009-04-14 Thread Jesse

Thanks I'll give the suggestions a try.

On Apr 14, 9:55 am, Karen Tracey  wrote:
> On Tue, Apr 14, 2009 at 12:35 PM, Alex Gaynor  wrote:
> > On Tue, Apr 14, 2009 at 12:25 PM, Jesse  wrote:
>
> >> The error is 'ascii' codec can't encode character u'\xb0' in position
> >> 98: ordinal not in range(128) and it occurs when a temperature degree
> >> such as 35°C
> >> is in the text.
>
> >> I'm using the following code in the view.py:
>
> >>   response = HttpResponse(mimetype='text/csv')
> >>    response['Content-Disposition'] = 'attachment;
> >> filename=publication.csv'
> >>    writer = csv.writer(response)
> >>    writer.writerow(['Title', 'Authors', 'Year', 'Journal',
> >> 'Citation', 'Web Address'])
> >>    for publication in publication_list:
> >>        writer.writerow([publication.pubtitlestrip,
> >> publication.pubauthors, publication.year, publication.journal,
> >> publication.pubcitationnum, publication.pubwebaddress])
> >>    return response
>
> >> Is there someway to unicode the writer?
>
> > Simon Willison(I think) wrote up a class that implements the same API but
> > handles unicode:http://www.djangosnippets.org/snippets/993/
>
> Note also this is really a pure Python question and has nothing to do with
> Django.  Don't forget to consult the relevant docs for whatever code (in
> this case csv) you happen to be using.
>
> In this case the Python csv doc:
>
> http://docs.python.org/library/csv.html
>
> covers the issue pretty clearly (just search for unicode on the page), and
> also includes an example of a writer class that supports writing Unicode.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Creating an object with a FileField programmatically

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 4:04 PM, Vincent Foley  wrote:

>
> Hello,
>
> I want to be able to add files inside a model to test that model.
> However, I'm unable to find in the documentation any mention on how to
> do so.  I asked on IRC and somebody suggested the following:
>
> from django.core.files import File
> from myproject.myapp.models import MyModel
> fd = open('/path/to/file')
> f = File(fd)
> obj = MyModel.objects.create(file_field=f)
> f.close()
> fd.close()
>
>
> However, when I try to access obj, I get the following exception:
> SuspiciousOperation: Attempted access to '/path/to/file' denied.
>
> Is it how one is supposed to "attach" file into a model?  If so, what
> could be causing my problem?
>
> Thanks,
>
> Vincent
>
> >
>
If the file isn't already relative to your MEDIA_ROOT you need to do:

m = MyModel()
m.file_field.save('new_file_name', open('/path/to/file').read()).

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Creating an object with a FileField programmatically

2009-04-14 Thread Vincent Foley

Hello,

I want to be able to add files inside a model to test that model.
However, I'm unable to find in the documentation any mention on how to
do so.  I asked on IRC and somebody suggested the following:

from django.core.files import File
from myproject.myapp.models import MyModel
fd = open('/path/to/file')
f = File(fd)
obj = MyModel.objects.create(file_field=f)
f.close()
fd.close()


However, when I try to access obj, I get the following exception:
SuspiciousOperation: Attempted access to '/path/to/file' denied.

Is it how one is supposed to "attach" file into a model?  If so, what
could be causing my problem?

Thanks,

Vincent

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



Re: textarea in ModelForm

2009-04-14 Thread grimmus

Thanks for the reply Alex,

I am not really sure how i am supposed to override the default field
type.

The link talks about MyDateFormField() but is this a method or what ?

Could you provide an example of how i could put the form field on the
form instead of the model ?

Thanks alot.

On Apr 6, 9:48 pm, Alex Gaynor  wrote:
> On Mon, Apr 6, 2009 at 3:46 PM, grimmus  wrote:
>
> > Thanks for the reply.
>
> > I dont get an error anymore but nothing appears now, not even a
> > textbox ! Please see my model below
>
> > from django.db import models
> > from django import forms
> > from django.forms import ModelForm
>
> > import datetime
>
> > ENQUIRY_TYPES = (
> >    ('Allergy Testing','Allergy Testing'),
> >    ('Reflexology','Reflexology'),
> >    ('Other','Other'),
> > )
>
> > class ContactEnquiry(models.Model):
> >    name = models.CharField(max_length=100)
> >    phone_number = models.CharField(max_length=100)
> >    email_Address = models.EmailField()
> >    what_are_you_interested_in = models.CharField
> > (max_length=16,choices=ENQUIRY_TYPES)
> >    enquiry = forms.CharField(widget=forms.Textarea)
> >    enquiry_date = models.DateTimeField(auto_now_add=True)
> >    replied = models.BooleanField(default=False)
> >    def __unicode__(self):
> >        return self.name
>
> > class ContactForm(ModelForm):
> >    class Meta:
> >        model = ContactEnquiry
> >        exclude = ('replied','enquiry_date')
>
> > Any idea why the tetxtarea isnt appearing ?
>
> > On Apr 6, 8:21 pm, Alex Gaynor  wrote:
> > > On Mon, Apr 6, 2009 at 2:04 PM, grimmus  wrote:
>
> > > > Hi,
>
> > > > I am trying to create a text area for a form that is generated through
> > > > ModelForm.
>
> > > > The field i have is
>
> > > > enquiry = models.CharField(widget=models.Textarea)
>
> > > > but i get the error
>
> > > > 'module' object has no attribute 'Textarea'
>
> > > > I have tried a few variations but with no luck,
>
> > > > Any ideas ?
>
> > > > Thanks in advance
>
> > > Those are par tof the Django forms library, not the models library, so it
> > > should look like:
>
> > > from django import forms
>
> > > forms.CharField(widget=forms.Textarea)
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> You've put the form field on the model, instead of on the form, 
> seehttp://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overrid...
> how it should work.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-14 Thread zayatzz

Ok your idea worked just fine, but i keep coming up with new
questions :)

The result of it was that when i opened poll i got poll with name


So i wrote something (i dont know how its called - model instance?
model manager?) to retrieve the actual value of translation and my
poll model looks like this now :
class Poll(models.Model):
name = generic.GenericRelation(Trans)
pub_date = models.DateTimeField('date published')
active = models.BooleanField()
def __unicode__(self):
return unicode(self.name)
def tname(self):
q = Trans.objects.filter(poll = self)
q = q.get(keel = 1)
t = q.name
return t

Can this query also be shorter? and better? cause the first line seems
not to filter out anything at all.

Another one - this might solve the problem for displaying poll names
in list view, but when im creating questions for this poll, then in
the selectbox where i choose to which poll question belongs to i still
have poll name as
.
How could that be changed? Can it be changed withing admin.py of my
app?

Alan

On Apr 14, 3:45 pm, matehat  wrote:
> Sorry about the last post (was a little tired from a sleepless night
> of solving problems in physics ...). I think you can solve the issue
> by putting "return unicode(self.name)" instead of "return self.name"
> in all of the __unicode__ method of your models. The things is that
> you must make sure to return unicode object in that method.
>
> Another thing that pops in my mind from inspecting your code is that
> line in TranslationInline,
>
> >class TranslationInline(generic.GenericTabularInline):
> >        model = Trans
> >        extra = len(lang.objects.all())
>
> where it would be more efficient to do :
>
> extra = lang.objects.count()
>
> But that's just optimization stuff...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trying to wrap my head around nested regroups or other ways to handle ordered ForeignKey stuff

2009-04-14 Thread Kevin Cole

And... Never mind. Not sure how I missed it before, but it appears
select_related() gets me what I want.  I think...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django-grappelli setup problem

2009-04-14 Thread Lars Stavholm

Hi All,

I'm trying to get django-grappelli running, but after following
the installation instructions, I end up with a 404 and the following:

Using the URLconf defined in bfact.urls, Django tried these URL
patterns, in this order:

   1. ^admin/(.*)
   2. ^grappelli/ ^bookmark/add/$
   3. ^grappelli/ ^bookmark/remove/$
   4. ^grappelli/ ^help/(?P\d+)/$
   5. ^grappelli/ ^help
   6. ^grappelli/ ^obj_lookup/$
   7. ^grappelli/ ^related_lookup/$
   8. ^grappelli/ ^m2m_lookup/$
   9. ^accounts/login/$
  10. ^accounts/logout/$

Notice the space after "grappelli/".

Anyone else out there using django-grappelli?
Any ideas as to what causes this?

I'm using django-1.0.2 on Linux with latest grappelli from trunk.

Any ideas appreciated
/Lars

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



Re: Statistic gathering

2009-04-14 Thread Tim Chase

Alex Gaynor wrote:
> On Tue, Apr 14, 2009 at 1:21 PM, ab3...@gmail.com  wrote:
> 
>> I'm new to Django. I'm trying to figure out if there is a well
>> established design paradigm to collect statistics on hyperlink usage.
>>
>> When a visitor follows a  link to an external website, I
>> would like to insert the following information into a mysql database
>> table:
>>
>>  - the datetime of the click
>>  - the visitor's IP address
>>  - perhaps the visitor's url if it is easily available
>>  - key identifying which external link was selected
>>
>> Note: All visitors are anonymous. My site does not ask them to log in
>> or support username / password.
>>
>> I'd also like to be able to collect similar stats for page visits,
>> although I have a less-detailed workaround for this using Google
>> Analytics.
> The only way to know when an external link is clicked is to have some
> javascript fire that sends off an AJAX request to your site to tell it an
> external link was pressed, you then need to have a view that handles that
> data and inserts it into the DB.

In addition to JavaScript, there's a "ping" attribute[1] in HTML5

  http://example.com"; 
ping="http://mysite.example.org/ping/some_id";>thing

which is supported to varying degrees by browsers.  Both of these 
are brittle -- if the browser doesn't support the ping attribute, 
or if your visitors browse with JavaScript disabled (yay, NoScript!)

The only sure way to track outbound linking is to link to an 
internal page (that does the link tracking) which then returns a 
3xx result code[2] (303 or 307), setting the Location header to 
the external URL.  Thus, instead of linking with

   http://external.example.com/wherever";>thing

you link to

   thing

and then /external_url/42 returns the 303/307 with the Location 
pointed at "http://external.example.com/wherever";.  It requires 
your app to internally track the mapping from ID to external URL. 
  It also has the weakness of spoofability -- I could put

   http://yoursite.example.org/external_url/42";>

on my page, and every time my page was hit, it would look like 
somebody was doing an outbound link from your page to an external 
site.  You might be able to use Referer[3] (sic) tracking at the 
redirector link, but again, it's only an optional header, not a 
required header, so us privacy buffs may have "referer"s 
disabled.  The only other way I know around this is produce some 
sort of single-use token for each URL displayed, but then you 
have to track a huge number of URLs with their unique token.  And 
if a page is cached by something like Squid, only the first 
person to view click that link behind that cache counts.

As you can see, there are lots of options, but all of them have 
holes in them.  Choose your favorite poison.

Hope this helps give you some ideas of how to do it.

-tim

[1]
http://whatwg.org/specs/web-apps/current-work/#ping

[2]
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4

[3]
http://en.wikipedia.org/wiki/Referer






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



Re: Statistic gathering

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 1:21 PM, ab3...@gmail.com  wrote:

>
> I'm new to Django. I'm trying to figure out if there is a well
> established design paradigm to collect statistics on hyperlink usage.
>
> When a visitor follows a  link to an external website, I
> would like to insert the following information into a mysql database
> table:
>
>  - the datetime of the click
>  - the visitor's IP address
>  - perhaps the visitor's url if it is easily available
>  - key identifying which external link was selected
>
> Note: All visitors are anonymous. My site does not ask them to log in
> or support username / password.
>
> I'd also like to be able to collect similar stats for page visits,
> although I have a less-detailed workaround for this using Google
> Analytics.
> >
>
The only way to know when an external link is clicked is to have some
javascript fire that sends off an AJAX request to your site to tell it an
external link was pressed, you then need to have a view that handles that
data and inserts it into the DB.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Statistic gathering

2009-04-14 Thread ab3...@gmail.com

I'm new to Django. I'm trying to figure out if there is a well
established design paradigm to collect statistics on hyperlink usage.

When a visitor follows a  link to an external website, I
would like to insert the following information into a mysql database
table:

 - the datetime of the click
 - the visitor's IP address
 - perhaps the visitor's url if it is easily available
 - key identifying which external link was selected

Note: All visitors are anonymous. My site does not ask them to log in
or support username / password.

I'd also like to be able to collect similar stats for page visits,
although I have a less-detailed workaround for this using Google
Analytics.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Trying to wrap my head around nested regroups or other ways to handle ordered ForeignKey stuff

2009-04-14 Thread Kevin Cole

Hi,

First let me say I've looked at documentation, but feel a bit dyslexic
when it comes to this stuff.

The situation: I have three tables: a service provider table with
city, state abbreviation and country abbreviation (among other other
info), a states table with state names, abbreviations, and other state
info, and a country table with country names, abbreviations and other
country info.  I want an output like:
___

FULL COUNTRY NAME

   Full State Name
   City. Provider
   Provider
   City. Provider

Full State Name
   City. Provider
   Provider
   City. Provider

FULL COUNTRY NAME
___

I only want Country and State headings for countries and states having
providers.  Experimenting at the shell, it appears my model is okay:
_

>>> from mhd.models import *
>>> countries = Country.objects.filter(iso2__in=["US","CA"]).distinct()
>>> countries
[, ]

>>> countries[0].state_set.all()
[, , , ...]

>>> countries[1].state_set.all()
[, , , ...]
>>> countries[1].state_set.all()[1]


>>> countries[1].state_set.all()[1].provider_set.all()
[]

>>> countries[1].state_set.all()[1].provider_set.all()[0]


>>> countries[1].state_set.all()[1].provider_set.all()[0].practitioner
u'Anne B. ... PsyS, LPC'

>>> countries[1].state_set.all()[1].provider_set.all()[0].city
u'Anchorage'
_

For the next 5 days, a whittled down version of what I thought I was
trying to do lives on dpaste.com:

http://dpaste.com/32704/ model.py
http://dpaste.com/32755/ views.py
http://dpaste.com/32706/ listings.html template

However my later experiments in the manage.py shell (above) lead me to
suspect maybe I'm bass-ackwards about the whole thing.  Unfortunately,
suspecting that is still not enough to get me where I'm trying to go.

Help?

Thanks.

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



Re: Random Syntax Errors on Download

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 12:59 PM, AliasXNeo  wrote:

>
> I recently downloaded the latest Official release of Django for
> installation on my Windows XP OS. After copying the appropriate files
> over to the site-packages folder in the python installation, I
> attempted to create a test project to insure correct installation by
> invoking the command: django-admin.py startproject testproject. Python
> returns a syntax error, pointing to a spot in django/__init__.py on
> line 15 where the code is: if svn_rev != u'SVN-known' :. Now clearly
> the random u before the first quote is not supposed to be there, and
> removing it fixes the syntax error. The problem is after fixing it
> another syntax error is brought up with the same problem, random
> characters where they are not supposed to be.
>
> The problem is intriguing, and I attempted to download and install the
> official release 3 more times and then proceeded to get the latest
> develepor release from SVN only to get the same exact problem. I'm
> running the latest version of Python 3 on standard Windows XP. My
> question is, why are these random syntax errors showing up and how can
> I fix it?
>
> >
>
That charecter is most assuradley supposed to be there u indicates the
string is a unicode literal.  Django does not work with Python 3.0 as
documented.  It works with Python 2.3-2.6.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Random Syntax Errors on Download

2009-04-14 Thread AliasXNeo

I recently downloaded the latest Official release of Django for
installation on my Windows XP OS. After copying the appropriate files
over to the site-packages folder in the python installation, I
attempted to create a test project to insure correct installation by
invoking the command: django-admin.py startproject testproject. Python
returns a syntax error, pointing to a spot in django/__init__.py on
line 15 where the code is: if svn_rev != u'SVN-known' :. Now clearly
the random u before the first quote is not supposed to be there, and
removing it fixes the syntax error. The problem is after fixing it
another syntax error is brought up with the same problem, random
characters where they are not supposed to be.

The problem is intriguing, and I attempted to download and install the
official release 3 more times and then proceeded to get the latest
develepor release from SVN only to get the same exact problem. I'm
running the latest version of Python 3 on standard Windows XP. My
question is, why are these random syntax errors showing up and how can
I fix it?

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



Re: Temperature degree ascii code error on cvs output file

2009-04-14 Thread Karen Tracey
On Tue, Apr 14, 2009 at 12:35 PM, Alex Gaynor  wrote:

> On Tue, Apr 14, 2009 at 12:25 PM, Jesse  wrote:
>
>>
>> The error is 'ascii' codec can't encode character u'\xb0' in position
>> 98: ordinal not in range(128) and it occurs when a temperature degree
>> such as 35°C
>> is in the text.
>>
>> I'm using the following code in the view.py:
>>
>>   response = HttpResponse(mimetype='text/csv')
>>response['Content-Disposition'] = 'attachment;
>> filename=publication.csv'
>>writer = csv.writer(response)
>>writer.writerow(['Title', 'Authors', 'Year', 'Journal',
>> 'Citation', 'Web Address'])
>>for publication in publication_list:
>>writer.writerow([publication.pubtitlestrip,
>> publication.pubauthors, publication.year, publication.journal,
>> publication.pubcitationnum, publication.pubwebaddress])
>>return response
>>
>> Is there someway to unicode the writer?
>>
>>
>>
>>
> Simon Willison(I think) wrote up a class that implements the same API but
> handles unicode: http://www.djangosnippets.org/snippets/993/
>

Note also this is really a pure Python question and has nothing to do with
Django.  Don't forget to consult the relevant docs for whatever code (in
this case csv) you happen to be using.

In this case the Python csv doc:

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

covers the issue pretty clearly (just search for unicode on the page), and
also includes an example of a writer class that supports writing Unicode.

Karen

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



Re: Temperature degree ascii code error on cvs output file

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 12:25 PM, Jesse  wrote:

>
> The error is 'ascii' codec can't encode character u'\xb0' in position
> 98: ordinal not in range(128) and it occurs when a temperature degree
> such as 35°C
> is in the text.
>
> I'm using the following code in the view.py:
>
>   response = HttpResponse(mimetype='text/csv')
>response['Content-Disposition'] = 'attachment;
> filename=publication.csv'
>writer = csv.writer(response)
>writer.writerow(['Title', 'Authors', 'Year', 'Journal',
> 'Citation', 'Web Address'])
>for publication in publication_list:
>writer.writerow([publication.pubtitlestrip,
> publication.pubauthors, publication.year, publication.journal,
> publication.pubcitationnum, publication.pubwebaddress])
>return response
>
> Is there someway to unicode the writer?
>
>
> >
>
Simon Willison(I think) wrote up a class that implements the same API but
handles unicode: http://www.djangosnippets.org/snippets/993/

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Temperature degree ascii code error on cvs output file

2009-04-14 Thread Jesse

The error is 'ascii' codec can't encode character u'\xb0' in position
98: ordinal not in range(128) and it occurs when a temperature degree
such as 35°C
is in the text.

I'm using the following code in the view.py:

   response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment;
filename=publication.csv'
writer = csv.writer(response)
writer.writerow(['Title', 'Authors', 'Year', 'Journal',
'Citation', 'Web Address'])
for publication in publication_list:
writer.writerow([publication.pubtitlestrip,
publication.pubauthors, publication.year, publication.journal,
publication.pubcitationnum, publication.pubwebaddress])
return response

Is there someway to unicode the writer?


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



Re: Adding model instance attributes

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 11:33 AM, Mitch Chapman wrote:

>
> Is it bad form in Django to add "transient" instance variables to
> model instances?
>
> I'm rendering a set of search results.  Each result record is a User
> instance.  I want to show whether or not each record is a friend of
> the user who is conducting the search.
>
> Right now my view is annotating each search result record to indicate
> whether or not it is a friend of the requesting user.  This works, but
> I'm not sure what might break as a result of adding the instance
> variable:
>
>matched_users = User.objects.filter(...)
>friends_set = set([...])
>for u in matched_users:
>u.is_my_friend = (u.username in friends_set)
>
> I don't need to store this information permanently.  I just want to
> use it to simplify template rendering, e.g.
>
>{% for user in matched_users %}
>...
>{% if user.is_my_friend %}
>{{user.username}} is already your friend.
>{% endif %}
>...
>
> Is there a different, recommended way to do this?  Thanks for the help!
> >
>
In my view this is perfectly acceptable.  Django is just python and that's
completely legal Python and even idiomatic.  Indeed just adding attribute is
how annotations work in the development version.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Adding model instance attributes

2009-04-14 Thread Mitch Chapman

Is it bad form in Django to add "transient" instance variables to
model instances?

I'm rendering a set of search results.  Each result record is a User
instance.  I want to show whether or not each record is a friend of
the user who is conducting the search.

Right now my view is annotating each search result record to indicate
whether or not it is a friend of the requesting user.  This works, but
I'm not sure what might break as a result of adding the instance
variable:

matched_users = User.objects.filter(...)
friends_set = set([...])
for u in matched_users:
u.is_my_friend = (u.username in friends_set)

I don't need to store this information permanently.  I just want to
use it to simplify template rendering, e.g.

{% for user in matched_users %}
...
{% if user.is_my_friend %}
{{user.username}} is already your friend.
{% endif %}
...

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



Re: get_absolute_url method append extra text

2009-04-14 Thread nixon66

Alex,

Thanks

Ron

On Apr 14, 11:22 am, Alex Gaynor  wrote:
> On Tue, Apr 14, 2009 at 11:19 AM, nixon66  wrote:
>
> > Alex,
>
> > Ok, I'm going to ram my head into a wall now. Seriously thanks.
>
> > On Apr 14, 11:03 am, Alex Gaynor  wrote:
> > > On Tue, Apr 14, 2009 at 11:01 AM, nixon66  wrote:
>
> > > > I have this model with an get_absolute_url method.
>
> > > > class Country(models.Model):
> > > >    country_cd = models.CharField(max_length=2, primary_key=True)
> > > >    country = models.CharField(max_length=80, blank=True)
> > > >    slug = models.CharField(max_length=80, blank=True)
> > > >    class Meta:
> > > >        db_table = u'country'
>
> > > >    def __unicode__(self):
> > > >        return self.country
>
> > > >    def get_absolute_url(self):
> > > >        return 'lobby/country/%s/' % self.slug
>
> > > > using this in a template
>
> > > > {% for country in country_list %}
>
> > > > {{ country.country }} > > > a>
>
> > > > gets me a list of countries.
>
> > > > *Algeria
> > > > *Australia
> > > > *Afghanistan
> > > > etc
>
> > > > But when I put my mouse over the links or click on the links instead
> > > > of getting   
> > > > 'http://localhost:8000/lobby/country/algeria'for
> > > > example, I get
> > > >  'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone
> > > > have an idea of why its adding the extra text onto the url? I've done
> > > > this before and have not have a problem. In fact the code and
> > > > templates are from another app and they work just fine.
>
> > > It's because your urls don't start with a / so they are relative to your
> > > current location.
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> I'd also reccomend you use reverse/the permalink decorator in place of
> handcrafting the URL as it makes your apps easier to reuse and more
> flexible:http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddo...
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url method append extra text

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 11:19 AM, nixon66  wrote:

>
> Alex,
>
> Ok, I'm going to ram my head into a wall now. Seriously thanks.
>
> On Apr 14, 11:03 am, Alex Gaynor  wrote:
> > On Tue, Apr 14, 2009 at 11:01 AM, nixon66  wrote:
> >
> > > I have this model with an get_absolute_url method.
> >
> > > class Country(models.Model):
> > >country_cd = models.CharField(max_length=2, primary_key=True)
> > >country = models.CharField(max_length=80, blank=True)
> > >slug = models.CharField(max_length=80, blank=True)
> > >class Meta:
> > >db_table = u'country'
> >
> > >def __unicode__(self):
> > >return self.country
> >
> > >def get_absolute_url(self):
> > >return 'lobby/country/%s/' % self.slug
> >
> > > using this in a template
> >
> > > {% for country in country_list %}
> >
> > > {{ country.country }} > > a>
> >
> > > gets me a list of countries.
> >
> > > *Algeria
> > > *Australia
> > > *Afghanistan
> > > etc
> >
> > > But when I put my mouse over the links or click on the links instead
> > > of getting   
> > > 'http://localhost:8000/lobby/country/algeria'for
> > > example, I get
> > >  'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone
> > > have an idea of why its adding the extra text onto the url? I've done
> > > this before and have not have a problem. In fact the code and
> > > templates are from another app and they work just fine.
> >
> > It's because your urls don't start with a / so they are relative to your
> > current location.
> >
> > Alex
> >
> > --
> > "I disapprove of what you say, but I will defend to the death your right
> to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
> >
>
I'd also reccomend you use reverse/the permalink decorator in place of
handcrafting the URL as it makes your apps easier to reuse and more
flexible:
http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#get-absolute-url

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: get_absolute_url method append extra text

2009-04-14 Thread nixon66

Alex,

Ok, I'm going to ram my head into a wall now. Seriously thanks.

On Apr 14, 11:03 am, Alex Gaynor  wrote:
> On Tue, Apr 14, 2009 at 11:01 AM, nixon66  wrote:
>
> > I have this model with an get_absolute_url method.
>
> > class Country(models.Model):
> >    country_cd = models.CharField(max_length=2, primary_key=True)
> >    country = models.CharField(max_length=80, blank=True)
> >    slug = models.CharField(max_length=80, blank=True)
> >    class Meta:
> >        db_table = u'country'
>
> >    def __unicode__(self):
> >        return self.country
>
> >    def get_absolute_url(self):
> >        return 'lobby/country/%s/' % self.slug
>
> > using this in a template
>
> > {% for country in country_list %}
>
> > {{ country.country }} > a>
>
> > gets me a list of countries.
>
> > *Algeria
> > *Australia
> > *Afghanistan
> > etc
>
> > But when I put my mouse over the links or click on the links instead
> > of getting   'http://localhost:8000/lobby/country/algeria'for
> > example, I get
> >  'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone
> > have an idea of why its adding the extra text onto the url? I've done
> > this before and have not have a problem. In fact the code and
> > templates are from another app and they work just fine.
>
> It's because your urls don't start with a / so they are relative to your
> current location.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: get_absolute_url method append extra text

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 11:01 AM, nixon66  wrote:

>
>
> I have this model with an get_absolute_url method.
>
>
>
> class Country(models.Model):
>country_cd = models.CharField(max_length=2, primary_key=True)
>country = models.CharField(max_length=80, blank=True)
>slug = models.CharField(max_length=80, blank=True)
>class Meta:
>db_table = u'country'
>
>def __unicode__(self):
>return self.country
>
>def get_absolute_url(self):
>return 'lobby/country/%s/' % self.slug
>
>
> using this in a template
>
> {% for country in country_list %}
>
> {{ country.country }} a>
>
> gets me a list of countries.
>
> *Algeria
> *Australia
> *Afghanistan
> etc
>
> But when I put my mouse over the links or click on the links instead
> of getting   'http://localhost:8000/lobby/country/algeria' for
> example, I get
>  'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone
> have an idea of why its adding the extra text onto the url? I've done
> this before and have not have a problem. In fact the code and
> templates are from another app and they work just fine.
>
>
> >
>
It's because your urls don't start with a / so they are relative to your
current location.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



get_absolute_url method append extra text

2009-04-14 Thread nixon66


I have this model with an get_absolute_url method.



class Country(models.Model):
country_cd = models.CharField(max_length=2, primary_key=True)
country = models.CharField(max_length=80, blank=True)
slug = models.CharField(max_length=80, blank=True)
class Meta:
db_table = u'country'

def __unicode__(self):
return self.country

def get_absolute_url(self):
return 'lobby/country/%s/' % self.slug


using this in a template

{% for country in country_list %}

{{ country.country }}

gets me a list of countries.

*Algeria
*Australia
*Afghanistan
etc

But when I put my mouse over the links or click on the links instead
of getting   'http://localhost:8000/lobby/country/algeria' for
example, I get
 'http://localhost:8000/lobby/country/lobby/country/egypt'. Anyone
have an idea of why its adding the extra text onto the url? I've done
this before and have not have a problem. In fact the code and
templates are from another app and they work just fine.


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



Re: list to queryset

2009-04-14 Thread snorkel

Thanks a lot,
This works fine and is much nicer
I have been floundering around for what seems like weeks trying to
figure out how you're supposed to this

snorkel


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



Re: single queryset from multiple tables

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 10:50 AM, veearrsix  wrote:

>
> Thanks for the help so far guys, I've used that recipe suggested by
> Malcolm, where by I pass a number of querysets into the method. It
> works as expected I guess, BUT, I would like to be able to sort by the
> datetime field from each queryset, however the fieldnames for each of
> the date time fields from each queryset are different. Is there a way
> around this, should I actually be looking at a custom sql query?
>
> On Apr 11, 12:55 am, Alex Gaynor  wrote:
> > On Fri, Apr 10, 2009 at 7:52 PM, Malcolm Tredinnick <
> >
> >
> >
> > malc...@pointy-stick.com> wrote:
> >
> > > On Fri, 2009-04-10 at 19:44 -0400, Alex Gaynor wrote:
> >
> > > > On Fri, Apr 10, 2009 at 7:40 PM, Malcolm Tredinnick
> > > >  wrote:
> > > [...]
> >
> > > > Particularly with iterators, storing the (next head item,
> rest
> > > > of
> > > > iterator) pair in a heap leads to a very neat and fast way to
> > > > create a
> > > > combined iterator. Here's one professional-quality
> > > > implementation that I
> > > > would recommend:http://code.activestate.com/recipes/491285/
> >
> > > > It has one unfortunate failing(which is the fault of the heapq
> > > > library), it doesn't take a key/cmp function like sorted does.  It is
> > > > otherwise completely excellent though.
> >
> > > It's Python and so is the heap module! Modifying things is easy. I've
> > > used the same solution with custom comparison functions one a number of
> > > occasions. Even writing a small heap implementaiton with a custom
> > > comparison is only about two dozen lines. Come on, think a little bit
> > > outside the box!
> >
> > I'm not!  A heap sort is a great solution to this problem(but you already
> > knew that), it's just that the implementation in the python stdlib
> doesn't
> > work perfectly for this usecase(indeed I filed a ticket about this
> upsteam
> > several months ago, for reference it was rejected).  I did the same thing
> > you suggested for a blog post on this topic a number of months ago,
> however
> > it wasn't nearly as optimial as this(I believe you even commented to that
> > effect on the post).
> >
> >
> >
> > > Regards,
> > > Malcolm
> >
> > Alex
> >
> > --
> > "I disapprove of what you say, but I will defend to the death your right
> to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
> >
>
Well, if you use some sorting mechanism that takes a key function(like the
one sorted takes) you could write one up that's something like:

DATE_FIELD_MAPPING = {
Model1: 'date',
Model2: 'pubdate',
}

def my_key_func(obj):
return getattr(obj, DATE_FIELD_MAPPING[type(obj)])

And then sorted(chain(Model1.objects.all(), Model2.objects.all()),
key=my_key_func)

Or something similar using the heap sort method malcolm and I discussed.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: single queryset from multiple tables

2009-04-14 Thread veearrsix

Thanks for the help so far guys, I've used that recipe suggested by
Malcolm, where by I pass a number of querysets into the method. It
works as expected I guess, BUT, I would like to be able to sort by the
datetime field from each queryset, however the fieldnames for each of
the date time fields from each queryset are different. Is there a way
around this, should I actually be looking at a custom sql query?

On Apr 11, 12:55 am, Alex Gaynor  wrote:
> On Fri, Apr 10, 2009 at 7:52 PM, Malcolm Tredinnick <
>
>
>
> malc...@pointy-stick.com> wrote:
>
> > On Fri, 2009-04-10 at 19:44 -0400, Alex Gaynor wrote:
>
> > > On Fri, Apr 10, 2009 at 7:40 PM, Malcolm Tredinnick
> > >  wrote:
> > [...]
>
> > >         Particularly with iterators, storing the (next head item, rest
> > >         of
> > >         iterator) pair in a heap leads to a very neat and fast way to
> > >         create a
> > >         combined iterator. Here's one professional-quality
> > >         implementation that I
> > >         would recommend:http://code.activestate.com/recipes/491285/
>
> > > It has one unfortunate failing(which is the fault of the heapq
> > > library), it doesn't take a key/cmp function like sorted does.  It is
> > > otherwise completely excellent though.
>
> > It's Python and so is the heap module! Modifying things is easy. I've
> > used the same solution with custom comparison functions one a number of
> > occasions. Even writing a small heap implementaiton with a custom
> > comparison is only about two dozen lines. Come on, think a little bit
> > outside the box!
>
> I'm not!  A heap sort is a great solution to this problem(but you already
> knew that), it's just that the implementation in the python stdlib doesn't
> work perfectly for this usecase(indeed I filed a ticket about this upsteam
> several months ago, for reference it was rejected).  I did the same thing
> you suggested for a blog post on this topic a number of months ago, however
> it wasn't nearly as optimial as this(I believe you even commented to that
> effect on the post).
>
>
>
> > Regards,
> > Malcolm
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: list to queryset

2009-04-14 Thread Alex Gaynor
On Tue, Apr 14, 2009 at 9:03 AM, snorkel  wrote:

>
> I am new to Django and this is driving me crazy... excuse my
> inexperience
> anyway
>
> I have 3 classes
> class Job():
> . some stuff .
>
> class Sequence()
>... more stuff ...
>job=models.ForeignKey('Job')
>element_type=models.ManyToMany('ElementType')
>
> class ElementType()
>   ... some charfields etc .
>
> what I want to do is go to the job see what sequences it has and then
> return a queryset of all the element types belonging to each of the
> sequences ... I can't do it.
> Here is a list the returns what I want but I need a queryset
>
> def get_element_types(job):
>sequences=job.sequence.all()
>for s in sequences:
>et+=list(s.element_types.all())
>return et
>
> I need a queryset because I am using it in a ModelForm
>
> class SequenceForm(ModelForm):
>def __init__(self,*args,**kwargs)
>self.fields['element_types'].queryset = et
>super(SequenceForm,self).__init__(*args,**kwargs)
>
>class Meta:
>model=Sequence
>
>
> Am I doing this completely the wrong way?
>
>
> >
>
You can rewrite that query as:

ElementType.objects.filter(sequence__in=job.sequences.all())

Which is both a queryset, and more efficient since it will only do 1 SQL
query.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



list to queryset

2009-04-14 Thread snorkel

I am new to Django and this is driving me crazy... excuse my
inexperience
anyway

I have 3 classes
class Job():
 . some stuff .

class Sequence()
... more stuff ...
job=models.ForeignKey('Job')
element_type=models.ManyToMany('ElementType')

class ElementType()
   ... some charfields etc .

what I want to do is go to the job see what sequences it has and then
return a queryset of all the element types belonging to each of the
sequences ... I can't do it.
Here is a list the returns what I want but I need a queryset

def get_element_types(job):
sequences=job.sequence.all()
for s in sequences:
et+=list(s.element_types.all())
return et

I need a queryset because I am using it in a ModelForm

class SequenceForm(ModelForm):
def __init__(self,*args,**kwargs)
self.fields['element_types'].queryset = et
super(SequenceForm,self).__init__(*args,**kwargs)

class Meta:
model=Sequence


Am I doing this completely the wrong way?


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



Re: Custom Model Fields / Multi-table inheritance / get_db_prep_value / postgresql_psycopg2

2009-04-14 Thread gordyt

Howdy Daniel!

> I suspect you have not set the subclass's metaclass to
> models.SubfieldBase - see 
> here:http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#the-s...
>
> You need to do this to get any of the overridden methods to be called.

Thanks for the update, but that isn't the problem.  I am setting it:

__metaclass__ = models.SubfieldBase


I've gone through the page on writing custom fields several times
(http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-
custom-model-fields).

As far as I can tell the only place where this problem is occurring is
in the situation where:

(1) You have a custom model field as the primary key, and
(2) You are working with multi-table inheritance

My workaround for now is to just not use the postgresql_psycopg2
driver for now, but I suspect this is something that can cause more
significant problems.

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



Re: i18n translations

2009-04-14 Thread zayatzz

Thanks!

On Apr 14, 3:52 pm, matehat  wrote:
> Hi Alan,
>
> > Is this really meant to work so that you create translations in a file
> > manually and then create objects with names/descriptions that have
> > translation in the file or is there a more automatic way to do this?
>
> currently, Django's i18n system is made to translate static strings in
> a project. It is not meant to dynamically assign translations to model
> instances. For assignment of translated labels on a model, you can
> check youhttp://code.google.com/p/transdb/though I don't know how
> admin is supported and how stable is the project.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-14 Thread zayatzz



On Apr 14, 3:45 pm, matehat  wrote:
> Sorry about the last post (was a little tired from a sleepless night
> of solving problems in physics ...). I think you can solve the issue
> by putting "return unicode(self.name)" instead of "return self.name"
> in all of the __unicode__ method of your models. The things is that
> you must make sure to return unicode object in that method.
>
> Another thing that pops in my mind from inspecting your code is that
> line in TranslationInline,
>
> >class TranslationInline(generic.GenericTabularInline):
> >        model = Trans
> >        extra = len(lang.objects.all())
>
> where it would be more efficient to do :
>
> extra = lang.objects.count()
>
> But that's just optimization stuff...

Thanks for the info and tip :). I'll test it as soon as i get home.

Perhaps you can provide little more help about the django admin. That
extra there is meant to provide exactly right amount of fields for
each object, that i create, but if you use one saving option of django
admin you get more fields, which are completely unnecessary. Is there
a simple way to limit the amount of those fields and nothing more?

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



Re: i18n translations

2009-04-14 Thread matehat

Hi Alan,

> Is this really meant to work so that you create translations in a file
> manually and then create objects with names/descriptions that have
> translation in the file or is there a more automatic way to do this?

currently, Django's i18n system is made to translate static strings in
a project. It is not meant to dynamically assign translations to model
instances. For assignment of translated labels on a model, you can
check you http://code.google.com/p/transdb/ though I don't know how
admin is supported and how stable is the project.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n translations

2009-04-14 Thread matehat

Hi Alan,

> Is this really meant to work so that you create translations in a file
> manually and then create objects with names/descriptions that have
> translation in the file or is there a more automatic way to do this?

currently, Django's i18n system is made to translate static strings in
a project. It is not meant to dynamically assign translations to model
instances. For assignment of translated labels on a model, you can
check you http://code.google.com/p/transdb/ though I don't know how
admin is supported and how stable is the project.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic relations swamp

2009-04-14 Thread matehat

Sorry about the last post (was a little tired from a sleepless night
of solving problems in physics ...). I think you can solve the issue
by putting "return unicode(self.name)" instead of "return self.name"
in all of the __unicode__ method of your models. The things is that
you must make sure to return unicode object in that method.

Another thing that pops in my mind from inspecting your code is that
line in TranslationInline,

>class TranslationInline(generic.GenericTabularInline):
>model = Trans
>extra = len(lang.objects.all())

where it would be more efficient to do :

extra = lang.objects.count()

But that's just optimization stuff...


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



Python object maker for database result sets

2009-04-14 Thread Sebastian

Hello Django-Users,

The software development team at the Campbell-Lange Workshop (CLW) has
been using Django since 0.95. From the beginning we have been very
impressed with the URL dispatcher, form validation and templating
language. We have, however, found that the Django ORM occasionally
doesn't meet our requirements when writing complex web-services.

Having unsuccessfully scanned the Django-users list for a non-ORM
alternative, we decided to write our own Python object maker
middleware. This approach uses Python's psycopg module to initiate
calls to stored PL/pgSQL procedures and returns dynamically created
python objects.

A full length article, including source files (GPLv3), can be found
at:

http://campbell-lange.net/company/articles/dbwrapper/

This implementation allows us to keep writing complex database queries
in native SQL, with the additional benefit of returning ORM-like
python objects instead of psycopg's default 'list-of-lists'  data
structure.

Below is a small example of how we use this python wrapper:

»»» connection = psycopg.connect("dbname=test user=clw password=***")
»»» cursor = connection.cursor()
»»» cursor.execute("SELECT * FROM people WHERE id=%s, (1,))
»»» person = PyObject (cursor, "NewClass")
»»» person
»»» 
»»» print person.t_first_name
»»» sebastian
»»» print person.__dict__
»»» {'id':1, 't_first_name':'sebastian', 't_last_name':'ritter',
't_password':'password', 't_email':sebast...@test.com'}

Using the principles above, we have developed more complicated wrapper
methods to handle multi-row return sets (using generators), as well as
a grouping wrapper that returns multi-tiered objects.

We welcome any feedback or comments on this approach. It would also be
interesting to know why you would prefer to use an ORM over SQL
procedures. This will help fuel our internal debate as to which
approach is most suitable when dealing with complicated database
interactions.

Kindest regards,
Sebastian

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



Re: custom comment app migration

2009-04-14 Thread Eric

This has gone well so far -- I ended up pointing my new comment app
models at the old database tables using the db_table meta option, and
then manually altering the table definitions, that kept things a lot
simpler.

I'm getting an AlreadyRegistered exception for a custom CommentsAdmin
definition in my own custom comments admin.py. Looking at the code,
the builtin contrib admin should not be registered so long as I've got
a COMMENTS_APP defined in settings.py, and that comments app has a
get_model() method that returns something other than the default
Comment model. Both of those things are true, yet I'm
AlreadyRegistered. I see that the traceback goes through my
admin.autodiscover() statement, I wonder if that could have something
to do with it. I've also named my COMMENTS_APP 'comments' and the main
model Comment – could there be a clash somewhere? I'm running a newly-
updated django.

Traceback:
File "/Library/Python/2.5/site-packages/django-trunk/django/core/
handlers/base.py" in get_response
  83. request.path_info)
File "/Library/Python/2.5/site-packages/django-trunk/django/core/
urlresolvers.py" in resolve
  184. for pattern in self.url_patterns:
File "/Library/Python/2.5/site-packages/django-trunk/django/core/
urlresolvers.py" in _get_url_patterns
  208. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "/Library/Python/2.5/site-packages/django-trunk/django/core/
urlresolvers.py" in _get_urlconf_module
  203. self._urlconf_module = import_module
(self.urlconf_name)
File "/Library/Python/2.5/site-packages/django-trunk/django/utils/
importlib.py" in import_module
  35. __import__(name)
File "/dev/myproject/urls.py" in 
  17. admin.autodiscover()
File "/Library/Python/2.5/site-packages/django-trunk/django/contrib/
admin/__init__.py" in autodiscover
  56. import_module("%s.admin" % app)
File "/Library/Python/2.5/site-packages/django-trunk/django/utils/
importlib.py" in import_module
  35. __import__(name)
File "/dev/myproject/comments/admin.py" in 
  21. admin.site.register(Comment, MyCommentAdmin)
File "/Library/Python/2.5/site-packages/django-trunk/django/contrib/
admin/sites.py" in register
  80. raise AlreadyRegistered('The model %s is already
registered' % model.__name__)

Exception Type: AlreadyRegistered at /admin/
Exception Value: The model Comment is already registered

On Apr 9, 10:15 pm, Eric Abrahamsen  wrote:
> I'm planning on migrating an existing (django.contrib) comments setup  
> into a custom comment app, and I'm wondering if anyone's got any  
> experience to impart in this regard. I have done cross-app data  
> migration before, and cocked it up horribly. These are the steps I'm  
> considering; if anyone's got suggestions, or sees anything wrong here,  
> for god's sake speak up please.
>
> 1. Make my custom comment app, then copy all models, forms, peripheral  
> models, comment-related signals, etc etc, into it. Leave existing  
> stuff in place. Add the appropriate get_model() and get_form()  
> functions to __init__.py. Augment new models as necessary. Run syncdb  
> to make tables for the new app.
>
> 2. Add COMMENTS_APP to settings.py, pointing to my new app. Alter the  
> existing django_content_type table to also point to this new app. (I  
> see the existing app_label is just 'comments', if I call my custom app  
> 'comments' too, can I get away with not changing anything in this  
> table?).
>
> 3. Go into the shell and copy data from existing comment instances  
> (I've also got Commenter and CommentNotification models) into the new  
> app models.
>
> 4. Pull changes onto production server, run syncdb, repeat steps 2 and  
> 3 above, restart.
>
> 5. Delete old code and old db tables from both development and  
> production environments.
>
> 6. Golden.
>
> Does this seem right? I'm particularly worried about problems that  
> might arise from having the existing code pointing to a new app. Is  
> there anything besides django_content_type that needs to know what's  
> changed?
>
> If this works I hope it will be useful as a roadmap to others equally  
> frightened of databases.
>
> Thanks,
> Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Process multiple html forms in the same view

2009-04-14 Thread Bastien

Thank you Karen, that's exactly what I need "To give each Form its own
namespace".

On Apr 13, 10:57 pm, Karen Tracey  wrote:
> On Mon, Apr 13, 2009 at 2:11 PM, Bastien  wrote:
> > ... So my question is how could the
> > view know which POST data belongs to which form or how can I change
> > the form fields name like the profile tags and post tags would become
> > tags_profile and tags_post respectively?
>
> I think you want to specify a prefix for your individual forms:
>
> http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django and i18n what's wrong???

2009-04-14 Thread drakkan

Ok remain two minor issue:

1) http://code.djangoproject.com/ticket/5494
2) ugettext_lazy are not json serializable so when I use transaltion
to populate ajax widgets I have to explicitily convert to unicode, but
this is really a minor issue

any eta for 1)? will be in django 1.1, still the same issue with
django trunk

thanks
drakkan1000

On 13 Apr, 22:43, drakkan  wrote:
> ok I'll try it,
>
> thanks
> drakkan1000
>
> On 13 Apr, 22:39, Alex Gaynor  wrote:
>
> > On Mon, Apr 13, 2009 at 4:37 PM, drakkan  wrote:
>
> > > I'm using ugettext, I have to use the lazy variant?
>
> > > On 13 Apr, 21:53, Ramiro Morales  wrote:
> > > > On Mon, Apr 13, 2009 at 4:30 PM, drakkan  wrote:
>
> > > > > I found a workaround I have to do:
>
> > > > > 'status':_(u.get_status_display())
>
> > > > > even if I have already marked the string for translation in models:
>
> > > > > STATUS=(
> > > > >    (1,_('Active')),
> > > > >    (0,_('Inactive')),
> > > > > )
>
> > > > > this is a really strange behaviour ...
>
> > > > To which one of the *gettext* function(s) are the _ alias
> > > > defined in both models.py and views.py?
>
> > > > --
> > > > Ramiro Moraleshttp://rmorales.net
>
> > Yes, for any module level strings you need to use the lazy variant.
>
> > Alex
>
> > --
> > "I disapprove of what you say, but I will defend to the death your right to
> > say it." --Voltaire
> > "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---