Re: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Your model was not-so-good Python/Django code style so it was bit hard 
to read but...

Low Kian Seong kirjoitti:
> On Tue, Nov 3, 2009 at 3:07 PM, Jani Tiainen  wrote:
>> Low Kian Seong kirjoitti:
>>> On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
 Low Kian Seong kirjoitti:
> I have about 3k plus record in my db table and am trying to do a
> simple render_to_response of a template sending it the results of a
> query. I debugged this and found that the total time taken for an
> operation like this is 50 seconds! Is there anyway to speed this up?
>
 Answer is maybe.
>>> Model:
>>>
>> [clipped model code]
>>
>>> I isolated the code and ran the render_to_response by itself and
>>> measured the time.
>>>
 First you have to provide model, view and template code you're using to
 render your code, second the way you measured this 50 seconds.
>> How about view and template..? It seems that you have few foreign keys
>> at least that may cause extra roundtrips to db.



> 
> Template:
> 
> 
>   
>   
> {% if query %}
> {% load utils %}
> 
> 
>   
> 
>   Requestor
>   Country (User)
>   AD Domain
>   Company Name
>   Defender ID
>   First Name
>   Last Name
>   Token S/N
>   Token Pin
>   IT Mgr
>   HD Mgr
>   SR Approver
>   SR No. (Setup Cost)
>   SR No. (On Going Cost)
>   SR No. (Orange Cost)
>   Creation Date
>   Acct. Status
>   
> 
> {% for record in query %}
>   
>   {{record.requestor}}
>   {{record.country}}
>   {{record.ad_domain_group}}
>   {{record.company}}
>   {{record.defender_id}}
>   {{record.first_name}}
>   {{record.last_name}}
>   {{record.rsa_token_serial_number}}
>   {{record.token_initial_pin}}

>   {{record.it_manager_id.name}}
>   {{record.sr_manager_id.name}}
>   {{record.hd_manager_id.name}}

All these three might hit another roundtrip to database. Since you're 
using them, you might want to use select_related() method.

>   {{ record.ad_domain_group|defender_setup }}
>   {{ record.ad_domain_group|defender_on_going }}
>   {{ record.ad_domain_group|defender_orange }}
>   {{record.creation_date}}
>   {{ record.disable_date|show_status:end_date }}
>   
> {% endfor %}
>   
> {% endif %}
> 
> 
> 
> views.py:
> 
> def do_defender_advanced(request):
>   query = request.POST.get('query_text','')
>   entries = defender.objects.all()
>   query_text_string = request.POST['query_text']
>   start_date_string = request.POST.get('start_date','')
>   end_date_string = request.POST.get('end_date',str_today)
> 
>   if ('query_text' in request.POST) and 
> request.POST['query_text'].strip():
> 
>   query_text_string = request.POST['query_text']
>   start_date_string = request.POST.get('start_date','')
>   end_date_string = request.POST.get('end_date',str_today)
>   if len(start_date_string) == 0:
>   start_date_string = str_today
>   if len(end_date_string) == 0:
>   end_date_string = str_today
>   query_text_string = request.POST['query_text']
>   qset=(
>   Q(first_name__icontains=query_text_string)|
>   Q(last_name__icontains=query_text_string)|
>   Q(country__icontains=query_text_string)|
>   Q(existing_defender_id__icontains=query_text_string)
>   )
>   
>   if query_text_string.lower() == "all":
>   found_entries = defender.objects.all()
>   elif query_text_string.lower() != "all":
>   found_entries = defender.objects.filter(qset)
>   found_entries = found_entries.filter(
> # status = 'active',
>   
> creation_date__range=[start_date_string,
>   
> end_date_string]).values()
>   else:
>   found_entries = ''
>   if len(found_entries) > 0:

Note that this will fetch all entries in queryset from DB to memory. If 
you want just to know is there anything use .count(), not len().

Both features (len, count and select_related) are documented in : 


>   response = render_to_response("defender_advanced_report.html",
>   {"query":found_entries},
>  

Re: render_to_response taking 50 seconds!

2009-11-02 Thread James Bennett

On Tue, Nov 3, 2009 at 1:17 AM, Low Kian Seong  wrote:
> There is a query page where the start_date and end_date is being sent.
> Then the do_defender_advanced will process it and generate an Excel
> using the template.

For each object you are displaying the values of four foreign keys.
Each time you access one of those foreign keys, you're doing another
database query; with 3,000 objects and four foreign keys per object,
you'll be doing 12,000 database queries, which is almost certainly why
it's slow.

I suggest you read up on the select_related() method, which can
condense those 12,000 database queries into only one database query.


-- 
"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: render_to_response taking 50 seconds!

2009-11-02 Thread Low Kian Seong

On Tue, Nov 3, 2009 at 3:07 PM, Jani Tiainen  wrote:
>
> Low Kian Seong kirjoitti:
>> On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
>>> Low Kian Seong kirjoitti:
 I have about 3k plus record in my db table and am trying to do a
 simple render_to_response of a template sending it the results of a
 query. I debugged this and found that the total time taken for an
 operation like this is 50 seconds! Is there anyway to speed this up?

>>> Answer is maybe.
>>
>> Model:
>>
>
> [clipped model code]
>
>> I isolated the code and ran the render_to_response by itself and
>> measured the time.
>>
>>> First you have to provide model, view and template code you're using to
>>> render your code, second the way you measured this 50 seconds.
>
> How about view and template..? It seems that you have few foreign keys
> at least that may cause extra roundtrips to db.



Template:




{% if query %}
{% load utils %}




Requestor
Country (User)
AD Domain
Company Name
Defender ID
First Name
Last Name
Token S/N
Token Pin
IT Mgr
HD Mgr
SR Approver
SR No. (Setup Cost)
SR No. (On Going Cost)
SR No. (Orange Cost)
Creation Date
Acct. Status


{% for record in query %}

{{record.requestor}}
{{record.country}}
{{record.ad_domain_group}}
{{record.company}}
{{record.defender_id}}
{{record.first_name}}
{{record.last_name}}
{{record.rsa_token_serial_number}}
{{record.token_initial_pin}}
{{record.it_manager_id.name}}
{{record.sr_manager_id.name}}
{{record.hd_manager_id.name}}
{{ record.ad_domain_group|defender_setup }}
{{ record.ad_domain_group|defender_on_going }}
{{ record.ad_domain_group|defender_orange }}
{{record.creation_date}}
{{ record.disable_date|show_status:end_date }}

{% endfor %}

{% endif %}



views.py:

def do_defender_advanced(request):
query = request.POST.get('query_text','')
entries = defender.objects.all()
query_text_string = request.POST['query_text']
start_date_string = request.POST.get('start_date','')
end_date_string = request.POST.get('end_date',str_today)

if ('query_text' in request.POST) and 
request.POST['query_text'].strip():

query_text_string = request.POST['query_text']
start_date_string = request.POST.get('start_date','')
end_date_string = request.POST.get('end_date',str_today)
if len(start_date_string) == 0:
start_date_string = str_today
if len(end_date_string) == 0:
end_date_string = str_today
query_text_string = request.POST['query_text']
qset=(
Q(first_name__icontains=query_text_string)|
Q(last_name__icontains=query_text_string)|
Q(country__icontains=query_text_string)|
Q(existing_defender_id__icontains=query_text_string)
)

if query_text_string.lower() == "all":
found_entries = defender.objects.all()
elif query_text_string.lower() != "all":
found_entries = defender.objects.filter(qset)
found_entries = found_entries.filter(
#   status = 'active',

creation_date__range=[start_date_string,

end_date_string]).values()
else:
found_entries = ''
if len(found_entries) > 0:
response = render_to_response("defender_advanced_report.html",
{"query":found_entries},
Context( {'end_date':end_date_string } )
)
response['Content-Type'] = 'application/vnd.ms-excel'
response['Content-Disposition'] = 
'attachment;filename=DEFENDER.xls'

return response
else:

no_results=Context({'results':'No results'})
return render_to_response("user/defender_advanced.html",
{"no_results" : no_results})

There is a query page where the start_date and end_date is being sent.
Then the 

Re: install help please.

2009-11-02 Thread Low Kian Seong

On Tue, Nov 3, 2009 at 1:28 PM, paulmo  wrote:
>
> goal is to check out google appengine using python and django if
> possible. running xp, downloaded python 2.6 and django 1.1.1.tar. i'm
> familiar with auto-installing apps and have no idea how to run django.
> i've extracted the tar file to a folder in my downloads. tried running
> cmd prompt < setup py.install > and that did nothing. windows told me
> to add new prog in control panel (??) totally confused by django site
> instructions on running from a cd directory, etc.

Open up a msdos terminal, cd into the untar directory and run the
command 'python setup.py install'. Make sure though before this you
can run the 'python' command from the command line.
>
> can i handle this?? thanks
>
> >
>



-- 
Low Kian Seong
blog: http://lowkster.blogspot.com

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



Re: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Low Kian Seong kirjoitti:
> On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
>> Low Kian Seong kirjoitti:
>>> I have about 3k plus record in my db table and am trying to do a
>>> simple render_to_response of a template sending it the results of a
>>> query. I debugged this and found that the total time taken for an
>>> operation like this is 50 seconds! Is there anyway to speed this up?
>>>
>> Answer is maybe.
> 
> Model:
> 

[clipped model code]

> I isolated the code and ran the render_to_response by itself and
> measured the time.
> 
>> First you have to provide model, view and template code you're using to
>> render your code, second the way you measured this 50 seconds.

How about view and template..? It seems that you have few foreign keys 
at least that may cause extra roundtrips to db.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread delfick755



On Nov 3, 3:00 pm, Graham Dumpleton 
wrote:
> On Nov 3, 5:55 pm, Stephen Moore  wrote:
> All I can suggest is get rid of mod_python. It is a fair bit simpler
> in mod_wsgi to do these sorts of per setup overrides because the WSGI
> script file acts as an intermediary from which overrides can be
> applied.


fair enough.

I'll look into that one day.

Thankyou very much for your 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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Graham Dumpleton



On Nov 3, 5:55 pm, Stephen Moore  wrote:
> On Tue, Nov 3, 2009 at 2:31 PM, Graham Dumpleton
>
>  wrote:
> > Cant you just have different settings files and set
> > DJANGO_SETTINGS_MODULES different for each installation?
>
> The problem with that becomes let's say I have the two options
> production and internet, then that means that I have to have 4
> different settings.py for each combination.
>
> I did find an interesting idea 
> herehttp://www.modpython.org/pipermail/mod_python/2006-June/021316.html
> just then.
>
> basically you modify PythonPath depending on what features you want.
>
> For example, say I have a file hierarchy like so
>
> options/
>     debug/
>         production/
>             __init__.py
>             apacheSettings.py
>             #In here set PRODUCTION=True
>
>         dev/
>             __init__.py
>             apacheSettings.py
>             #In here set PRODUCTION=False
>
>     internet/
>         on/
>             __init__.py
>             apacheSettings.py
>             #In here set INTERNET=True
>
>         off/
>             __init__.py
>             apacheSettings.py
>             #In here set INTERNET=False
>
> then in settings.py
>
> PRODUCTION = True
> try:
>     import apacheSettings
>     PRODUCTION = apacheSettings.PRODUCTION
> except ImportError:
>     pass
>
> INTERNET = True
> try:
>     import internetSettings
>     INTERNET = internetSettings.INTERNET
> except ImportError:
>     pass
>
> and finally, in apache configuration
>
> PythonPath " \
>     [ \
>         '/home/iambob/web/options/debug/production', \
>         '/home/iambob/web/options/internet/on', \
>         '/home/iambob/web',  '/home/iambob/web/common', 
> '/home/iambob/web/home'\
>     ] + sys.path"
>
> or
>
> PythonPath " \
>     [ \
>         '/home/iambob/web/options/debug/dev', \
>         '/home/iambob/web/options/internet/off', \
>         '/home/iambob/web',  '/home/iambob/web/common', 
> '/home/iambob/web/home'\
>     ] + sys.path"
>
> which seems to work rather nicely
>
> :)

All I can suggest is get rid of mod_python. It is a fair bit simpler
in mod_wsgi to do these sorts of per setup overrides because the WSGI
script file acts as an intermediary from which overrides can be
applied.

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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Stephen Moore

On Tue, Nov 3, 2009 at 2:31 PM, Graham Dumpleton
 wrote:
> Cant you just have different settings files and set
> DJANGO_SETTINGS_MODULES different for each installation?
>

The problem with that becomes let's say I have the two options
production and internet, then that means that I have to have 4
different settings.py for each combination.

I did find an interesting idea here
http://www.modpython.org/pipermail/mod_python/2006-June/021316.html
just then.

basically you modify PythonPath depending on what features you want.

For example, say I have a file hierarchy like so

options/
debug/
production/
__init__.py
apacheSettings.py
#In here set PRODUCTION=True

dev/
__init__.py
apacheSettings.py
#In here set PRODUCTION=False

internet/
on/
__init__.py
apacheSettings.py
#In here set INTERNET=True

off/
__init__.py
apacheSettings.py
#In here set INTERNET=False

then in settings.py

PRODUCTION = True
try:
import apacheSettings
PRODUCTION = apacheSettings.PRODUCTION
except ImportError:
pass


INTERNET = True
try:
import internetSettings
INTERNET = internetSettings.INTERNET
except ImportError:
pass

and finally, in apache configuration


PythonPath " \
[ \
'/home/iambob/web/options/debug/production', \
'/home/iambob/web/options/internet/on', \
'/home/iambob/web',  '/home/iambob/web/common', '/home/iambob/web/home'\
] + sys.path"

or

PythonPath " \
[ \
'/home/iambob/web/options/debug/dev', \
'/home/iambob/web/options/internet/off', \
'/home/iambob/web',  '/home/iambob/web/common', '/home/iambob/web/home'\
] + sys.path"

which seems to work rather nicely

:)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



install help please.

2009-11-02 Thread paulmo

goal is to check out google appengine using python and django if
possible. running xp, downloaded python 2.6 and django 1.1.1.tar. i'm
familiar with auto-installing apps and have no idea how to run django.
i've extracted the tar file to a folder in my downloads. tried running
cmd prompt < setup py.install > and that did nothing. windows told me
to add new prog in control panel (??) totally confused by django site
instructions on running from a cd directory, etc.

can i handle this?? 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: render_to_response taking 50 seconds!

2009-11-02 Thread Low Kian Seong

On Tue, Nov 3, 2009 at 1:33 PM, Jani Tiainen  wrote:
>
> Low Kian Seong kirjoitti:
>> I have about 3k plus record in my db table and am trying to do a
>> simple render_to_response of a template sending it the results of a
>> query. I debugged this and found that the total time taken for an
>> operation like this is 50 seconds! Is there anyway to speed this up?
>>
>
> Answer is maybe.

Model:

class defender(models.Model):
STATUS_CHOICE=(
('active', 'Active'),
('disabled','Disabled'),)


requestor = models.CharField(max_length=50)
company = models.CharField(max_length=100)
country = models.CharField('Country (User)', max_length=50)
ad_domain_group = models.CharField('AD Domain',max_length=50)
first_name = models.CharField('First Name', max_length=40)
last_name = models.CharField('Last Name', max_length=50)
defender_id= models.CharField('Defender ID',
max_length=100,primary_key=True)
existing_defender_id = models.CharField(max_length=100,
editable=False)
wifi_password = models.CharField(max_length=100, editable=False)
rsa_token_serial_number = models.CharField('Token S/N',
max_length=100,null=True,blank=True)
token_initial_pin = models.CharField('Token PIN', max_length=10,
null=True,blank=True)
#vendor = models.ForeignKey('ext_company', verbose_name="Vendor 
Account")
security_question   = models.ForeignKey(Question,null=True,
blank=True)
security_answer = models.CharField(max_length=100,
null=True,blank=True)
it_manager_id = models.ForeignKey(contact_information,
related_name='bew it_manager',
verbose_name = ('IT Mgr'),
null=True,blank=True,max_length=50)
sr_manager_id = models.ForeignKey(contact_information,
null=True,blank=True,
verbose_name = ('SR Approver'),
related_name='bew sr_manager',max_length=50)
hd_manager_id = models.ForeignKey(contact_information,
related_name='bew hd_manager',
verbose_name = ('HD Mgr'),
null=True,blank=True,max_length=50)
creation_date = models.DateField(max_length=20,
db_index=True,
null=True,blank=True)
disable_date = models.DateField(max_length=20, null=True,blank=True)
migrate = models.CharField(max_length=30,editable=False)
status = models.CharField(max_length=20,
choices=STATUS_CHOICE,default="Active")

class Meta:
verbose_name_plural = "DEFENDER"

class Admin:
pass


I isolated the code and ran the render_to_response by itself and
measured the time.

>
> First you have to provide model, view and template code you're using to
> render your code, second the way you measured this 50 seconds.
>
> --
> Jani Tiainen
>
> >
>



-- 
Low Kian Seong
blog: http://lowkster.blogspot.com

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



Re: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Graham Dumpleton



On Nov 3, 4:49 pm, Stephen Moore  wrote:
> On Tue, Nov 3, 2009 at 1:31 PM, Graham Dumpleton
>
>  wrote:
> >http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_E...
>
> > You are experiencing environment variable leakage between Python sub
> > interpreters. Affects mod_wsgi as well as mod_python, or any embedded
> > solution using multiple Python interpreters for that matter.
>
> a
>
> that makes sense :)
>
>
>
> > Make sure you set PRODUCTION/INTERNET in all application
> > configurations. Ie., add:
>
> >        SetEnv PRODUCTION true
> >        SetEnv INTERNET true
>
> > or whatever it needs to be in other configurations.
>
> hmm, I'm not sure if that solves the problem or not.
> It seems less frequent but it does happen.
>
> is there a way to pass options to the site with mod_python without
> relying on environment variables?

Cant you just have different settings files and set
DJANGO_SETTINGS_MODULES different for each installation?

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: redirect or reload page after pdf file generation.

2009-11-02 Thread Jani Tiainen

jai_python kirjoitti:
> Hello every one,
> 
> I have a form which contains group of data and I can select some of
> them to take pdf file.  When I submit the form, it returns pdf file
> which contains the selected data. But i need to redirect or reload the
> present form after pdf file has been generated inorder to remove
> previous entry(i.e data included in the pdf file ) . Here goes my
> source
> 
> def getPDF(request):
>   if not request.POST:
>return to html form page
>   response = HttpResponse(mimetype='application/pdf')
>   #some content will be added to response with the use REPORTLAB
>   return response# will return pdf
> 
> This response will sent an pdf file to client side. same time i want
> to reload or refresh after pdf file generation.

I don't think that such a mechanism exists in HTTP protocol so what 
you're asking might not be really possible.

With little JS (ajax iframe download) you can achieve that kind of 
refresh like functionality. But it relies on ajax functionality.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Stephen Moore

On Tue, Nov 3, 2009 at 1:31 PM, Graham Dumpleton
 wrote:
> http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Environment_Variables
>
> You are experiencing environment variable leakage between Python sub
> interpreters. Affects mod_wsgi as well as mod_python, or any embedded
> solution using multiple Python interpreters for that matter.

a

that makes sense :)

>
> Make sure you set PRODUCTION/INTERNET in all application
> configurations. Ie., add:
>
>        SetEnv PRODUCTION true
>        SetEnv INTERNET true
>
> or whatever it needs to be in other configurations.

hmm, I'm not sure if that solves the problem or not.
It seems less frequent but it does happen.

is there a way to pass options to the site with mod_python without
relying on environment variables?

Regards
Stephen

--~--~-~--~~~---~--~~
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: render_to_response taking 50 seconds!

2009-11-02 Thread Javier Guerra

On Mon, Nov 2, 2009 at 10:44 PM, Low Kian Seong  wrote:
> I have about 3k plus record in my db table and am trying to do a
> simple render_to_response of a template sending it the results of a
> query. I debugged this and found that the total time taken for an
> operation like this is 50 seconds! Is there anyway to speed this up?

not sure if it would make any difference; but the first thing i would
try is to not directly use a template; instead create a response
object and write to it as a file-like object.

maybe you could load a single-record template, and render each db
record to the response, roughly:

template = load template
response = httpresponse()
for record in queryset:
response.write (template.rendertostring (record)
return response

i'm not sure; but this might let the response object stream the data,
greatly reducing ram pressure.

-- 
Javier

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



Re: render_to_response taking 50 seconds!

2009-11-02 Thread Jani Tiainen

Low Kian Seong kirjoitti:
> I have about 3k plus record in my db table and am trying to do a
> simple render_to_response of a template sending it the results of a
> query. I debugged this and found that the total time taken for an
> operation like this is 50 seconds! Is there anyway to speed this up?
> 

Answer is maybe.

First you have to provide model, view and template code you're using to 
render your code, second the way you measured this 50 seconds.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Graham Dumpleton

Arrgh, pressed send to quick.

Read:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Environment_Variables

You are experiencing environment variable leakage between Python sub
interpreters. Affects mod_wsgi as well as mod_python, or any embedded
solution using multiple Python interpreters for that matter.

Make sure you set PRODUCTION/INTERNET in all application
configurations. Ie., add:

SetEnv PRODUCTION true
SetEnv INTERNET true

or whatever it needs to be in other configurations.

Graham

On Nov 3, 4:28 pm, Graham Dumpleton 
wrote:
> Sorry, I should just follow your pastebin links shouldn't I. :-)
>
> On Nov 3, 4:21 pm, Graham Dumpleton 
> wrote:
>
>
>
> > Which of the many ways of hosting under Apache are you using?
>
> > mod_python? mod_wsgi? mod_fcgid? mod_fastcgi? mod_cgi(d)? mod_scgi?
> > other?
>
> > SetEnv does not set os.environ in a number of these.
>
> > Graham
>
> > On Nov 3, 4:14 pm, delfick755  wrote:
>
> > > Hello,
>
> > > I have a setup where a django's debug setting is changed depending on
> > > whether os.environ['PRODUCTION'] is true or false.
>
> > > Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
> > > a site as production.
>
> > > I then have /etc/hosts setup so thathttp://homeandhttp://cecpoint
> > > to localhost.
>
> > > Then in apache I have dev versions of my two sites (home and cec) as
> > > followshttp://pastebin.com/m56aab2f1andhttp://pastebin.com/m537594e6
>
> > > This works fine. However I also want it so when people access my
> > > computer from outside  (i.e.http://delfick.servehttp.com) then debug
> > > isn't turned on. For this I havehttp://pastebin.com/m28abffd5
>
> > > This also works fine.
>
> > > However it seems this solution isn't a very good one and it will
> > > alternate between versions. so if I refreshhttp://cecthensometimes
> > > it's the production version, sometimes development version and same
> > > forhttp://delfick.servehttp.com.
>
> > > is there a way to get around this or will I just have to create copies
> > > of the sites to be used for the production version?
>
> > > Thankyou
>
> > > Regards
> > > Stephen
--~--~-~--~~~---~--~~
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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Graham Dumpleton

Sorry, I should just follow your pastebin links shouldn't I. :-)

On Nov 3, 4:21 pm, Graham Dumpleton 
wrote:
> Which of the many ways of hosting under Apache are you using?
>
> mod_python? mod_wsgi? mod_fcgid? mod_fastcgi? mod_cgi(d)? mod_scgi?
> other?
>
> SetEnv does not set os.environ in a number of these.
>
> Graham
>
> On Nov 3, 4:14 pm, delfick755  wrote:
>
>
>
> > Hello,
>
> > I have a setup where a django's debug setting is changed depending on
> > whether os.environ['PRODUCTION'] is true or false.
>
> > Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
> > a site as production.
>
> > I then have /etc/hosts setup so thathttp://homeandhttp://cecpoint
> > to localhost.
>
> > Then in apache I have dev versions of my two sites (home and cec) as
> > followshttp://pastebin.com/m56aab2f1andhttp://pastebin.com/m537594e6
>
> > This works fine. However I also want it so when people access my
> > computer from outside  (i.e.http://delfick.servehttp.com) then debug
> > isn't turned on. For this I havehttp://pastebin.com/m28abffd5
>
> > This also works fine.
>
> > However it seems this solution isn't a very good one and it will
> > alternate between versions. so if I refreshhttp://cecthensometimes
> > it's the production version, sometimes development version and same
> > forhttp://delfick.servehttp.com.
>
> > is there a way to get around this or will I just have to create copies
> > of the sites to be used for the production version?
>
> > Thankyou
>
> > Regards
> > Stephen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



redirect or reload page after pdf file generation.

2009-11-02 Thread jai_python

Hello every one,

I have a form which contains group of data and I can select some of
them to take pdf file.  When I submit the form, it returns pdf file
which contains the selected data. But i need to redirect or reload the
present form after pdf file has been generated inorder to remove
previous entry(i.e data included in the pdf file ) . Here goes my
source

def getPDF(request):
  if not request.POST:
   return to html form page
  response = HttpResponse(mimetype='application/pdf')
  #some content will be added to response with the use REPORTLAB
  return response# will return pdf

This response will sent an pdf file to client side. same time i want
to reload or refresh after pdf file generation.


Thanks & Regards,
Jai
--~--~-~--~~~---~--~~
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: apache gets confused with difference between dev and production version of site

2009-11-02 Thread Graham Dumpleton

Which of the many ways of hosting under Apache are you using?

mod_python? mod_wsgi? mod_fcgid? mod_fastcgi? mod_cgi(d)? mod_scgi?
other?

SetEnv does not set os.environ in a number of these.

Graham

On Nov 3, 4:14 pm, delfick755  wrote:
> Hello,
>
> I have a setup where a django's debug setting is changed depending on
> whether os.environ['PRODUCTION'] is true or false.
>
> Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
> a site as production.
>
> I then have /etc/hosts setup so thathttp://homeandhttp://cecpoint
> to localhost.
>
> Then in apache I have dev versions of my two sites (home and cec) as
> followshttp://pastebin.com/m56aab2f1andhttp://pastebin.com/m537594e6
>
> This works fine. However I also want it so when people access my
> computer from outside  (i.e.http://delfick.servehttp.com) then debug
> isn't turned on. For this I havehttp://pastebin.com/m28abffd5
>
> This also works fine.
>
> However it seems this solution isn't a very good one and it will
> alternate between versions. so if I refreshhttp://cecthen sometimes
> it's the production version, sometimes development version and same
> forhttp://delfick.servehttp.com.
>
> is there a way to get around this or will I just have to create copies
> of the sites to be used for the production version?
>
> Thankyou
>
> Regards
> Stephen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



apache gets confused with difference between dev and production version of site

2009-11-02 Thread delfick755

Hello,

I have a setup where a django's debug setting is changed depending on
whether os.environ['PRODUCTION'] is true or false.

Which means when I setup apache, I do "SetEnv PRODUCTION true" to mark
a site as production.

I then have /etc/hosts setup so that http://home and http://cec point
to localhost.

Then in apache I have dev versions of my two sites (home and cec) as
follows
http://pastebin.com/m56aab2f1 and http://pastebin.com/m537594e6

This works fine. However I also want it so when people access my
computer from outside  (i.e. http://delfick.servehttp.com) then debug
isn't turned on. For this I have
http://pastebin.com/m28abffd5

This also works fine.

However it seems this solution isn't a very good one and it will
alternate between versions. so if I refresh http://cec then sometimes
it's the production version, sometimes development version and same
for http://delfick.servehttp.com.

is there a way to get around this or will I just have to create copies
of the sites to be used for the production version?

Thankyou

Regards
Stephen
--~--~-~--~~~---~--~~
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: Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-02 Thread Christophe Pettus


On Nov 2, 2009, at 2:14 PM, Bill Freeman wrote:
> My presumption is that the older PostgreSQL, expecting to have to
> decide whether unquoted things are strings (e.g.; "status" in the
> query samples above), used to look at the context and decided that we
> had meant the 8 as a string.

In particular, as of PostgreSQL 8.3 (and thus 8.4), non-text types are  
not automatically cast to text.  You can find the details in the 8.3  
release notes:

http://www.postgresql.org/docs/8.3/static/release-8-3.html

The relevant section is E.9.2.1.

> Thoughts?  Workaround suggestions?

I'm not completely sure why the ORM is generating SQL that compares a  
number with a character string in the first place; that sounds like a  
bug in either the ORM or the client code, to me.

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


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



render_to_response taking 50 seconds!

2009-11-02 Thread Low Kian Seong

I have about 3k plus record in my db table and am trying to do a
simple render_to_response of a template sending it the results of a
query. I debugged this and found that the total time taken for an
operation like this is 50 seconds! Is there anyway to speed this up?

-- 
Low Kian Seong
blog: http://lowkster.blogspot.com

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



Re: Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-02 Thread Karen Tracey
On Mon, Nov 2, 2009 at 5:14 PM, Bill Freeman  wrote:

>
> It occurs to me that the ORM could fix this.  It knows that status is
> a CharField.  For anything but None (which it should try to store as
> null) it should be reasonable to apply str() (or unicode()) to the
> field value before storing it.  str(8) -> '8' (and unicode(8) ->
> u'8'), while str() applied to a string (or unicode() applied to a
> unicode string) leaves it unchanged (doesn't even copy in, in a few
> quick tests in python 2.6.2).  Then the backend will know to quote it.
>
> Thoughts?  Workaround suggestions?
>
> I believe this issue came up when the PostgreSQL version that made the
change first came out.

http://code.djangoproject.com/ticket/6523

made some change to help, although I don't recall exactly what was done.
You probably want to look at that and the discussions linked form that
ticket (I have a vague feeling there might have been other tickets) to get a
feel for the history of the change PostgreSQL made and what was ultimately
changed in Django to help adjust.  I have a vague feeling that at the time
there was not much support for continuing to allow apps to compare apples to
oranges willy-nilly after PostgreSQL itself decided to be more strict about
the matter, but I don't use PostgreSQL much myself so don't have a good feel
for how things ultimately turned out.

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: Lookup column value in external dictionary

2009-11-02 Thread Phil Edwards

Phil Edwards wrote:
> 
> This all works as expected. The final step that I'm not able to figure 
> out is what to put in either the view or the template so that I can do a 
> lookup of the 'package.rating' value (which will be 1, 2, 3 or 4) 
> against the 'ratingChoices' data so that the final output shows 
> something like 'Rating: Important' rather than 'Rating: 2'.
> 
> I'd thought of putting these ratings into their own table, although this 
> seems a bit of a waste for a short list of data points that will never 
> change.
> 

As is always the case, 5 more minutes of Googling after posting my query 
and I have the solution!

The answer of course is to replace:

Rating: {{ package.rating }}

with this:

Rating: {{ package.get_rating_display 
}}

Onwards and upwards!


-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Lookup column value in external dictionary

2009-11-02 Thread Phil Edwards

I've been using Python for some time but I'm new to Django. In one of my 
pet projects to help me up the learning curve, I have a model defined thus:

class Program(models.Model):

 ratingChoices = (
 (1, 'Essential'),
 (2, 'Important'),
 (3, 'Nice to Have'),
 (4, 'Geeks Only'),
 )

 category = models.IntegerField(choices = categoryChoices)
 rating = models.IntegerField(choices = ratingChoices)
 name = models.CharField(max_length = 50)
 version = models.CharField(max_length = 15)
 description = models.TextField()
 mainURL = models.URLField(verify_exists = False)
 downloadURL = models.URLField(verify_exists = False)
 installerPath = models.FileField(upload_to = 'downloads')

This is part of a database of categorised software, the categories being 
1 for 'security', 2 for 'office apps', 3 for programming tools, etc.

I have a simple URL scheme such that '/category/1' pulls up all the 
security related apps, '/category/2' all the office apps and so on.

In the views.py function which deals with this table, I'm using a 
straightforward 'package_list = Program.objects.filter(category = 
thisCategory)' call to pull out the rows I'm interested in for a given 
category.

In addition, each application is rated according to the list defined in 
the 'ratingChoices' tuple in the class definition.

The part of my template which displays the information looks like this:

{% block content %}
 
 {% for package in package_list %}
 
 
 
 
 Website
 Install
 Rating: {{ package.rating 
}}
 
 
 
 {{ package.name }} v{{ package.version 
}}
 {{ package.description }}
 
 
 
 {% endfor %}
{% endblock %}

This all works as expected. The final step that I'm not able to figure 
out is what to put in either the view or the template so that I can do a 
lookup of the 'package.rating' value (which will be 1, 2, 3 or 4) 
against the 'ratingChoices' data so that the final output shows 
something like 'Rating: Important' rather than 'Rating: 2'.

I'd thought of putting these ratings into their own table, although this 
seems a bit of a waste for a short list of data points that will never 
change.

Any help or advice greatly appreciated.

-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500


--~--~-~--~~~---~--~~
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: debug toolbar problem

2009-11-02 Thread bax...@gretschpages.com

Thanks Rob, that makes complete sense. Nothing like a response
straight from the source!

--~--~-~--~~~---~--~~
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: debug toolbar problem

2009-11-02 Thread Rob Hudson

It's looking like you have DEBUG=False and rely on
request.user.is_superuser to enable the toolbar.  Which mostly works,
except...

The Django Debug Toolbar monkey patches the CursorDebugWrapper class
to collect its data about what SQL queries are being executed:
http://github.com/robhudson/django-debug-toolbar/blob/master/debug_toolbar/panels/sql.py#L130

And this only gets used as a database cursor within Django when
settings.DEBUG=True:
http://code.djangoproject.com/browser/django/trunk/django/db/backends/__init__.py#L82

So when DEBUG=False, it uses a normal cursor which doesn't track SQL
queries.

-Rob

On Nov 2, 5:38 am, "bax...@gretschpages.com" 
wrote:
> > Are you caching your pages?
>
> Yes, but only for anonymous users
>
> > Are you using Django ORM?
>
> Yes
>
> > Have you added the DebugToolbarMiddleware to your MIDDLEWARE_CLASSES
> > in settings.py?
>
> Yes. In settings:
>
> MIDDLEWARE_CLASSES = (
>     'django.middleware.common.CommonMiddleware',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.middleware.doc.XViewMiddleware',
>     'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
>     'django.middleware.cache.CacheMiddleware',
>     'utils.lastseen.LastSeen',
>     'utils.ban_middleware.IPBanMiddleware',
>     'debug_toolbar.middleware.DebugToolbarMiddleware',
> )
>
> 
>
> DEBUG_TOOLBAR_PANELS = (
>             #'debug_toolbar.panels.version.VersionDebugPanel',
>             'debug_toolbar.panels.timer.TimerDebugPanel',
>             #'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
>             'debug_toolbar.panels.headers.HeaderDebugPanel',
>             'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
>             'debug_toolbar.panels.template.TemplateDebugPanel',
>             'debug_toolbar.panels.sql.SQLDebugPanel',
>             'debug_toolbar.panels.signals.SignalDebugPanel',
>             'debug_toolbar.panels.logger.LoggingPanel',
>         )
>
> 
>
> def custom_show_toolbar(request):
>             if request.user.is_superuser:
>                return True # Always show toolbar, for example purposes only.
>             return False
>
> DEBUG_TOOLBAR_CONFIG = {
>             'INTERCEPT_REDIRECTS': False,
>             'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
>            # 'EXTRA_SIGNALS': ['myproject.signals.MySignal'],
>             'HIDE_DJANGO_SQL': False,
>         }
>
> INSTALLED_APPS = (
>     ...
>     'debug_toolbar',
> )
>
> I see the bars, and most appear to be working ( like version, for
> example, before I turned it off), but nothing on SQL
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Fwd: InlineModelAdmin paging

2009-11-02 Thread Jay Coulter
Hi all,



Django documentation states that the inlines inherit same functionality as
modeladmin so I want to enable paging on an inline but it doesn’t appear to
work.



This is the code for my inline, is the syntax incorrect??



class CustomerCardsInline(admin.TabularInline):

model = CustomerCards

verbose_name = 'Account Cards'

ordering = ('cc_number',)

extra = 0

list_per_page  = 50

fields = ['account', 'cc_number', 'cc_effective_dt',
'cc_expire_dt', 'cc_closed_dt', 'cc_frozen_dt', 'cc_card_printed']



Thanks!



Jay

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



Re: model-validation: Excessive (and weird) queries during validation

2009-11-02 Thread Mark L.



On Nov 2, 10:27 pm, Karen Tracey  wrote:
> On Mon, Nov 2, 2009 at 1:41 PM, Mark L.  wrote:
>
> > As the subject states, I am using the model-validation branch at the
> > moment, which allows me to do, well, validation in the models.
>
> > I've however, noticed a very strange behaviour of the validation
> > logic, - any time  the clean() method is fired on the
> > "materialized" (saved or retrieved from the database) model, that
> > contains unique fields, the following query is fired (let me just give
> > you an example):
>
> > from django.db import models
>
> > class A(models.Model):
> >    pass
>
> > a = A.objects.create()
> > a.clean()
>
> > a.clean() results, among everything, in this: 'SELECT (1) AS "a" FROM
> > "val_a" WHERE ("val_a"."id" = 1 AND NOT ("val_a"."id" = 1 ))'
>
> > I might be missing something vital, but what is that "where" clause
> > there for? What is it supposed to check?
>
> It's trying to verify the uniqueness of the supposed-to-be-unique field id.
> The query makes sense for fields other than the primary key, where the WHERE
> clause turns out more like:
>
> WHERE model.unique_field = proposed_value AND NOT model.id =
> current_instance.pk
>
> That is, it's asking "Is there any other instance in the DB, besides this
> one I'm looking at, that has the proposed_value for this
> supposed-to-be-unique field?"  If the answer is no, then all is fine, the
> proposed value doesn't violate the unique constraint.  If the answer is yes,
> then the validation check needs to fail because saving this model instance
> to the DB would violate the unique constraint.
>
> Of course, it doesn't make sense for the primary key field.  For that field,
> when you exclude the current instance from the search the WHERE clause
> becomes impossible to satisfy.  The model validation code, I'd guess, has
> been moved from where it was initially implemented (ModelForms).  In its
> original place the primary key field would not ordinarily have been included
> in the list of unique fields to check because it wouldn't ordinarily be on
> the form, and only values on the form are checked for uniqueness.
>
> The code in the new place likely needs to realize the primary key field
> shouldn't be checked for uniqueness.  You could check to see if this has
> been reported in trac and if not open a ticket for it.  I don't recall it
> having been brought up by anyone else but I could have missed it.
>
> Karen

Thanks for the quick reply, Karen

I've investigated a bit and it seems, that the problem is just what
you've said - the logic, that decides whether the field needs to be
checked for uniqueness or not, just doesn't take into account the
fact, that the field might be a primary key. Should be an easy fix,
especially since it doesn't seem to affect the ModelForm validation.

I've created a ticket on the issue tracker with a demonstration of the
problem and the fix.

Either way, it should be noted, that adding unique fields to the
models (besides the obvious pk field), can cause extreme performance
drops. Imagine cleaning a collection of 200 or objects causing 200 db
queries to be run (I'll benchmark it later). Perhaps the uniqueness
check for the Model could be moved to save() instead of clean() just
for this one reason?

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



Newer PostgreSQL breaks django_friends, maybe deserves ORM fix.

2009-11-02 Thread Bill Freeman

I've been developing a Django 1.0 project (using Pinax, actaully) on a
machine that has PostgreSQL 8.1.11 (Linux), where things work just
fine.  Now I've deployed to a (still development) customer visible
server that has an 8.4 PostgreSQL (also on Linux), which throws errors
complaining that equals doesn't know how to compare a character
varying with an integer.

Not much analysis reveals that that folks are accustomed to treating
the FriendInvitation.status field, a models.CharField with
max_length=1 and a set of choices whose DB side representation is a
string composed of a single decimal digit, with literal ints (e.g.;
self.status = 5 in the FriendInvitation.accept()).  This is
django_friends version 0.1.2.  I'm hitting the problem on a queryset
with exclude(status=8).

Some testing with psql shows that of:

  select * from friends_friendshipinvitation where status = '8' ;

and

  select * from friends_friendshipinvitation where status = 8 ;

work fine on pg8.1.11, but only the first works on pg8.4 (the column
is character varying(1) in both databases).

My presumption is that the older PostgreSQL, expecting to have to
decide whether unquoted things are strings (e.g.; "status" in the
query samples above), used to look at the context and decided that we
had meant the 8 as a string.  That probably led to difficult to
diagnose errors, and they have tightend up in 8.4.  I can still get
away with not quoting the table and field names (so long as they don't
have funny characters), but things that look like numbers now are
numbers unless quoted.

I can make myself a copy of django_friends that won't get updated when
Pinax does, and patch it to work, but since I found my failure in a
profiles app that uses friends, I wonder how many other places I'll
have to patch.

It occurs to me that the ORM could fix this.  It knows that status is
a CharField.  For anything but None (which it should try to store as
null) it should be reasonable to apply str() (or unicode()) to the
field value before storing it.  str(8) -> '8' (and unicode(8) ->
u'8'), while str() applied to a string (or unicode() applied to a
unicode string) leaves it unchanged (doesn't even copy in, in a few
quick tests in python 2.6.2).  Then the backend will know to quote it.

Thoughts?  Workaround suggestions?

Bill

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



Re: how to exclude DateTime that are None

2009-11-02 Thread Brian Neal

On Nov 2, 3:44 pm, Felipe Reyes  wrote:
> Hi everybody,
>
> I'm using django 0.96, one of my models has a DateTimeField, I'm
> trying to exclude the from the queryset the rows that have null in the
> datetimefield, I'm using something like this:
>
> MyObject.objects.exclude(somedatecol=None)

I think you want the isnull field lookup:
http://docs.djangoproject.com/en/dev/ref/models/querysets/#isnull

Best,
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
-~--~~~~--~~--~--~---



how to exclude DateTime that are None

2009-11-02 Thread Felipe Reyes

Hi everybody,

I'm using django 0.96, one of my models has a DateTimeField, I'm
trying to exclude the from the queryset the rows that have null in the
datetimefield, I'm using something like this:

MyObject.objects.exclude(somedatecol=None)

that line gave me the following error

DataError: invalid input syntax for type timestamp with time zone: "None"


does somebody have some clue?

the database engine is a postgresql 8.3 using psycopg2 connector

thanks in advance

regards,

--~--~-~--~~~---~--~~
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: Migrating a Wordpress website to Django

2009-11-02 Thread John K

Thanks. Django redirect looks very useful. I'm hoping for a 1 to 1
conversion of URL's and avoid redirects all together. The redirect app
would be a great last resort.

On Nov 2, 2:32 pm, Antoni Aloy  wrote:
> 2009/11/2 John K :
>
>
>
> > Hey thanks for the links. It would be great to discuss personal
> > experiences with the group.
>
> > On Nov 2, 1:47 pm, creecode  wrote:
> >> Hello John,
>
> >> A quick search on Google shows some folks have done WP to Django
> >> migrations.  Following are a few links.
>
> >>http://www.nbrightside.com/blog/2007/10/14/how-to-migrate-a-wordpress...
>
> >>http://code.google.com/p/django-wordpress-admin/
>
> >>http://www.eriksmartt.com/blog/archives/306
>
> I migrated my own blog (trespams) from Wordpress to Django. The main
> difficult was to take care of tags and html conversions. You can
> mantain url with Django Redirect and hardcondig some of the others in
> urls.py.
>
> I had to create a migration script but this was just a matter of hours
> with a little bit of manual work.
>
> --
> Antoni Aloy López
> Blog:http://trespams.com
> Site:http://apsl.net
--~--~-~--~~~---~--~~
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 Interview Questions

2009-11-02 Thread Skylar Saveland

Doesn't work on my mobile browser.

Dimitri Gnidash wrote:
> Hey guys,
>
> For all those of you interviewing or being interviewed, I created a
> quick list of sample interview questions.
> While not comprehensive, it is a good start to review these before the
> interview, if anything, to gain a perspective on how other people
> might be using Django.
>
>
> http://blog.lightsonsoftware.com/django-interview-questions-0
>
>
> Dimitri Gnidash
> www.lightsonsoftware.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Migrating a Wordpress website to Django

2009-11-02 Thread Skylar Saveland

inspectdb might be of some interest

John K wrote:
> Hello all,
>
> We are auditing several web frameworks and will ultimately choose one
> that will replace Wordpress (Wordpress hosted on our servers). So far,
> Django fits the bill.
>
> Has anyone had any experience migrating a Wordpress site to a Django
> solution? If so, it would be great to hear how your experience went,
> and any tips that may help the migration go smoothly.
>
> Our 2 big tickets are content migration and user migration.
>
> • We currently have tens of thousands of articles and thousands of
> user accounts. Are there any automated tools for importing Wordpress
> data into Django? What content migration strategy did you use?
>
> • Any issues with porting pre-existing URLs into Django? How did you
> handle URL routing? (old Wordpress URLs into Django)?
>
> • Were there any problems or pitfalls during your migration that were
> not immediately apparent in the beginning of the migration process?
>
> Thanks in advance
> John
--~--~-~--~~~---~--~~
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: Marking usernames as not for use dynamically

2009-11-02 Thread Javier Guerra

On Mon, Nov 2, 2009 at 2:00 PM, Max Battcher  wrote:
> I'm rather fond of using URLs of the form:
>
> http://example.com/~username/

+1

-- 
Javier

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



Re: Migrating a Wordpress website to Django

2009-11-02 Thread Antoni Aloy

2009/11/2 John K :
>
> Hey thanks for the links. It would be great to discuss personal
> experiences with the group.
>
> On Nov 2, 1:47 pm, creecode  wrote:
>> Hello John,
>>
>> A quick search on Google shows some folks have done WP to Django
>> migrations.  Following are a few links.
>>
>> http://www.nbrightside.com/blog/2007/10/14/how-to-migrate-a-wordpress...
>>
>> http://code.google.com/p/django-wordpress-admin/
>>
>> http://www.eriksmartt.com/blog/archives/306
>>
I migrated my own blog (trespams) from Wordpress to Django. The main
difficult was to take care of tags and html conversions. You can
mantain url with Django Redirect and hardcondig some of the others in
urls.py.

I had to create a migration script but this was just a matter of hours
with a little bit of manual work.

-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

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



Re: model-validation: Excessive (and weird) queries during validation

2009-11-02 Thread Karen Tracey
On Mon, Nov 2, 2009 at 1:41 PM, Mark L.  wrote:

>
> As the subject states, I am using the model-validation branch at the
> moment, which allows me to do, well, validation in the models.
>
> I've however, noticed a very strange behaviour of the validation
> logic, - any time  the clean() method is fired on the
> "materialized" (saved or retrieved from the database) model, that
> contains unique fields, the following query is fired (let me just give
> you an example):
>
> from django.db import models
>
> class A(models.Model):
>pass
>
> a = A.objects.create()
> a.clean()
>
> a.clean() results, among everything, in this: 'SELECT (1) AS "a" FROM
> "val_a" WHERE ("val_a"."id" = 1 AND NOT ("val_a"."id" = 1 ))'
>
> I might be missing something vital, but what is that "where" clause
> there for? What is it supposed to check?


It's trying to verify the uniqueness of the supposed-to-be-unique field id.
The query makes sense for fields other than the primary key, where the WHERE
clause turns out more like:

WHERE model.unique_field = proposed_value AND NOT model.id =
current_instance.pk

That is, it's asking "Is there any other instance in the DB, besides this
one I'm looking at, that has the proposed_value for this
supposed-to-be-unique field?"  If the answer is no, then all is fine, the
proposed value doesn't violate the unique constraint.  If the answer is yes,
then the validation check needs to fail because saving this model instance
to the DB would violate the unique constraint.

Of course, it doesn't make sense for the primary key field.  For that field,
when you exclude the current instance from the search the WHERE clause
becomes impossible to satisfy.  The model validation code, I'd guess, has
been moved from where it was initially implemented (ModelForms).  In its
original place the primary key field would not ordinarily have been included
in the list of unique fields to check because it wouldn't ordinarily be on
the form, and only values on the form are checked for uniqueness.

The code in the new place likely needs to realize the primary key field
shouldn't be checked for uniqueness.  You could check to see if this has
been reported in trac and if not open a ticket for it.  I don't recall it
having been brought up by anyone else but I could have missed it.

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: Marking usernames as not for use dynamically

2009-11-02 Thread Max Battcher

> Not really answering your question, but a couple simple workarounds:
> 
> - put your user profiles under http://domain.com/profiles/username

I'm rather fond of using URLs of the form:

http://example.com/~username/

It's an old tradition (well, old in internet/unix years), but I think 
sometimes the tilde as a sign of a user page is forgotten/under-rated in 
modern URL planning.

--
--Max Battcher--
http://worldmaker.net


--~--~-~--~~~---~--~~
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: Formwizard and customizing the template layout

2009-11-02 Thread Mark L.

> Is there any way to have individual templates for each form

To define, which template should be used for which step, you can
override the get_template(self, step) method of the wizard (it must
return the name of the template), that way you can use separate
templates for certain steps (step numbers).

def get_template(self, step):

last_step = self.num_steps()-1

if step == last_step:

return 'confirm.html'

elif step == 1:

return "generic_wizard_step.html"

> and be able to perform the following
>
> 1. control the placement of fields
> 2. Allow for additional text inbetween fields
> 3. Control how check boxes are shown i.e. not one over another but
> side by side.

As for this, yes, this can be done by accessing the inner attributes
(and methods) of the "form" variable, that is passed to the template.
The best way to see it in action is to, actually, check the docs on
the forms (http://docs.djangoproject.com/en/dev/topics/forms/
#customizing-the-form-template). Sorry for not including the example,
but the documentation has those examples a-plenty.

Hope that helped.


--~--~-~--~~~---~--~~
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: Migrating a Wordpress website to Django

2009-11-02 Thread John K

Hey thanks for the links. It would be great to discuss personal
experiences with the group.

On Nov 2, 1:47 pm, creecode  wrote:
> Hello John,
>
> A quick search on Google shows some folks have done WP to Django
> migrations.  Following are a few links.
>
> http://www.nbrightside.com/blog/2007/10/14/how-to-migrate-a-wordpress...
>
> http://code.google.com/p/django-wordpress-admin/
>
> http://www.eriksmartt.com/blog/archives/306
>
> Toodle-looo...
> creecode
--~--~-~--~~~---~--~~
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: Migrating a Wordpress website to Django

2009-11-02 Thread creecode

Hello John,

A quick search on Google shows some folks have done WP to Django
migrations.  Following are a few links.

http://www.nbrightside.com/blog/2007/10/14/how-to-migrate-a-wordpress-blog-to-django

http://code.google.com/p/django-wordpress-admin/

http://www.eriksmartt.com/blog/archives/306

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



model-validation: Excessive (and weird) queries during validation

2009-11-02 Thread Mark L.

As the subject states, I am using the model-validation branch at the
moment, which allows me to do, well, validation in the models.

I've however, noticed a very strange behaviour of the validation
logic, - any time  the clean() method is fired on the
"materialized" (saved or retrieved from the database) model, that
contains unique fields, the following query is fired (let me just give
you an example):

from django.db import models

class A(models.Model):
pass

a = A.objects.create()
a.clean()

a.clean() results, among everything, in this: 'SELECT (1) AS "a" FROM
"val_a" WHERE ("val_a"."id" = 1 AND NOT ("val_a"."id" = 1 ))'

I might be missing something vital, but what is that "where" clause
there for? What is it supposed to check? The stacktrace for the query
is the following:
787  clean django/db/models/base.py
619   validate django/db/models/base.py
624   validate_unique django/db/models/base.py
683   _perform_unique_checks django/db/models/base.py
112   __nonzero__ django/db/models/query.py
106   _result_iter django/db/models/query.py
692   _fill_cache django/db/models/query.py
756   iterator django/db/models/query.py
287   results_iter django/db/models/sql/query.py
2369 execute_sql django/db/models/sql/query.py

Apparently, it is happening inside the uniqueness check. Anyway, the
most strange thing, is that calling clean() results in a query. I've
noticed it when I was displaying a set of a few hundred objects (each
of them has to be cleaned before sending the data to template), which
resulted in a few hundred of queries (for a single request), which
brought my dev-machine to the knees. It becomes worse if the cleaned
model is a part of a table-inheritance hierarchy, - clean() is called
sequentially for every model "up" the hierarchy, which results in a
tremendous number of queries executed per single request.

I must say, however, that I, at this moment, have no idea how to check
for uniqueness *without* issuing a query and, from what I see, django
doesn't like to assume things, so the db hits *will* be made.

Obviously, I can swindle Django into not checking uniqueness on clean
(by rolling my own clean method in models.Model subclasses), however,
that doesn't sound like a very good idea (if alternatives exist).

Sorry if this is an inappropriate list/group for this question. Maybe
I should instead address it to the django-developers or the issue
tracker.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



custom view decorator with parameter

2009-11-02 Thread nostradamnit

I'm trying to write a custom view decorator that takes a parameter,
and I can't for the life of me figure out how to pass the parameter.
I've tried the nested function pattern, the class with __init__ and
__call__ methods pattern, and I always run into the same basic error.
It either says I have to many parameters (professional_only expects 1
param but got 2) or too few parameters (expects only 1 but got 2) or
in it's current state, says that NoneType or the view function is not
callable?!?

Here's a dpaste dump - http://dpaste.org/azgn/

and the current form:

def professional_only(active):
""" Decorator that verifies user is professional, and implicitly
that he is logged in."""

def _check_status(view_func):
def _dec(request, *args, **kwargs):
if request.user.is_authenticated():
profil = request.user.profile
if profil.is_professional_member():
if active:
try:
entreprise_statut = Entreprise.objects.get
(administrateur=request.user).statut
if entreprise_statut == 'AC':
return view_func(request, *args,
**kwargs)
except:
pass
else:
return view_func(request, *args, **kwargs)
return HttpResponseRedirect(reverse
('pro_access_only'))
else:
url = '%s?%s=%s' % (settings.LOGIN_URL,
REDIRECT_FIELD_NAME, urllib.quote(request.get_full_path()))
return HttpResponseRedirect(url)
return _check_status


Thanks in advance for your help,
Sam
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Formwizard and customizing the template layout

2009-11-02 Thread txranger

I am implementing a nine part questionnaire that is dynamic. By
dynamic I mean the user may answer Part 1 and Part 2 but based on the
answers to Part 2 may be directed to Part 8 then Part 9. I have that
figured out but I need to have little more control over the look and
feel of the each form.

The wizard.html only has the {{ form }} variable. Is there any way to
way to have individual templates for each form and be able to perform
the following

1. control the placement of fields
2. Allow for additional text inbetween fields
3. Control how check boxes are shown i.e. not one over another but
side by side.

Would love to see some example code or be pointed in right direction.

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
-~--~~~~--~~--~--~---



Migrating a Wordpress website to Django

2009-11-02 Thread John K

Hello all,

We are auditing several web frameworks and will ultimately choose one
that will replace Wordpress (Wordpress hosted on our servers). So far,
Django fits the bill.

Has anyone had any experience migrating a Wordpress site to a Django
solution? If so, it would be great to hear how your experience went,
and any tips that may help the migration go smoothly.

Our 2 big tickets are content migration and user migration.

• We currently have tens of thousands of articles and thousands of
user accounts. Are there any automated tools for importing Wordpress
data into Django? What content migration strategy did you use?

• Any issues with porting pre-existing URLs into Django? How did you
handle URL routing? (old Wordpress URLs into Django)?

• Were there any problems or pitfalls during your migration that were
not immediately apparent in the beginning of the migration process?

Thanks in advance
John

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Pagination - django.views.generic.list_detail.object_detail

2009-11-02 Thread Mario

Hello,

Which Pagination tag do you all recommend for handling
django.views.generic.list_detail.object_detail? I have an existing
article which requires pagination. I don't want the user to keep
scrolling down the web page.

_Mario
--~--~-~--~~~---~--~~
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: Form that updates a list of items?

2009-11-02 Thread Nick Arnett
On Mon, Nov 2, 2009 at 3:30 AM, Julien Petitperrin <
julien.petitper...@gmail.com> wrote:

> Hello,
>
> I had this kind of issue a few days ago. I found this:
>
>
> http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/
>
> I hope this helps you to find a way to do your multiple items edit form.



Ah, that does look helpful and I wondered it I might do better to create one
form per line, as it suggests.

Nick

--~--~-~--~~~---~--~~
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: Form that updates a list of items?

2009-11-02 Thread Mark (Nosrednakram)

Hello,

I'm not sure if I understand your problem but if I do you could name
your fields the same in both tables, which I believe you may have
done.  Then your view could generate your input form using form =
RoleUpDataFrom() and if you have POST data you could use form =
RealDataForm(reques.POST).  This is just a thought and I haven't done
it but is what I'd try before making it complex with loops etc..

Mark

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



Django Interview Questions

2009-11-02 Thread Dimitri Gnidash

Hey guys,

For all those of you interviewing or being interviewed, I created a
quick list of sample interview questions.
While not comprehensive, it is a good start to review these before the
interview, if anything, to gain a perspective on how other people
might be using Django.


http://blog.lightsonsoftware.com/django-interview-questions-0


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



Re: Marking usernames as not for use dynamically

2009-11-02 Thread Sean Brant

Thanks Ethan.

bruno you are right moving stuff under the /profiles/ namespace would
solve everything.

Moving the pattern last but allowing users to still create the
username of "login" would prevent there username from working.

You are also right about "whenever you add any other url..." this will
defiantly become a problem. Say someone creates a username of
"my_super_cool_promotion" and in 3 months i want to create a page at
the url "my_super_cool_promotion" promoting something. They would
effectively take my url.

Let me revise my question some. Anyone have user profiles living at
http://domain.com/username/ and if so how are you handling the above
problems? I guess you could run a query against usernames before
creating a new page, making sure that path is not taken.

Thoughts welcome.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Marking usernames as not for use dynamically

2009-11-02 Thread bruno desthuilliers

On 2 nov, 16:05, Sean Brant  wrote:
> So i have user profiles at http://domain.com/username. I'd like to
> prevent a user from signing up with a username that is the same as a
> page on my site (ie: /login/, /blog/, etc). I was thinking I could
> inspect my url patterns to determine what pages exist  so I can
> prevent that from being a username. Although I'm not sure how
> expensive that will be. I'd rather not have to maintain a list in my
> settings file. Anyone know of a solution for this? Seems like a fairly
> common use case.


Not really answering your question, but a couple simple workarounds:

- put your user profiles under http://domain.com/profiles/username
- move the corresponding url patterns last, so any other "conflicting"
url will have precedence

FWIW, checking the user's profile url - based on username - won't
conflict with an existing one is mostly a sound concern, but (sorry
for being that dumb) this will only prevent conflicts with *existing*
urls - whenever you add any other url (flatpage anyone ?) at the same
level as your user profiles, you have a potential for conflicts...

My 2 cents...
--~--~-~--~~~---~--~~
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: Marking usernames as not for use dynamically

2009-11-02 Thread Ethan Jucovy
I haven't tried this, but it looks like you can use
`django.core.urlresolvers.resolve(path_string)` to figure out if a view
exists with a given path.

http://docs.djangoproject.com/en/dev/topics/http/urls/#django.core.urlresolvers.resolve
http://docs.djangoproject.com/en/dev/topics/http/urls/#resolve

I glanced at the code.  It looks like this method will return None if there
are no URLconf regex matches for the given path string.  If a URLconf does
match, it might potentially raise an exception.  For your use case you
probably want to treat the exceptions as matches/collisions and only
validate successfully if None is returned.

Again, I haven't tried this, but I'd guess it won't have any performance
problems, since it's using Django's own (fast) URL routing infrastructure.

Hope this helps,
Ethan

On Mon, Nov 2, 2009 at 10:05 AM, Sean Brant  wrote:

>
> So i have user profiles at http://domain.com/username. I'd like to
> prevent a user from signing up with a username that is the same as a
> page on my site (ie: /login/, /blog/, etc). I was thinking I could
> inspect my url patterns to determine what pages exist  so I can
> prevent that from being a username. Although I'm not sure how
> expensive that will be. I'd rather not have to maintain a list in my
> settings file. Anyone know of a solution for this? Seems like a fairly
> common use case.
>
> Sean
>
> >
>

--~--~-~--~~~---~--~~
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: Template processing/pre-processing

2009-11-02 Thread bruno desthuilliers



On 2 nov, 12:37, rd-london  wrote:
> Not worry, found work-a-round using MEDIA_URL.

Actually, that's what MEDIA_URL is for - so it's not a "workaround".
Now if you want more control (or custom stuff), writing a context
processor that exposes whatever setting (builtin or custom) you want
isn't really rocket science - just read the source code for
django.core.context_processors.media...

> On Oct 30, 4:39 pm, rd-london  wrote:
>
> > Hi,
>
> > I'd like to write some code, probably middleware, that look at various
> > types of HTML in templates and prepends a setting from settings.py.
>
> > For example, I'd like to pickup all .js, .css, .jpg, .png, .gif - and
> > stick a custom setting from settings.py on the front - effectively a
> > path.
>
> > Ideally, I'd like to do this by-project, so one project will have one
> > such setting in a settings.py, another project will have nother.
>
> > I'm not looking for a solution (although one would certainly be
> > welcome), but where to start looking would be handy. Feels like its
> > some kind of template pre-processing middleware - but anyone any
> > pointers/tips?
>
> > Many thanks for any help,
> > R
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Multi-db support

2009-11-02 Thread David De La Harpe Golden

David De La Harpe Golden wrote:

> Here's something further pared down I'm currently testing with django
> 1.1.1 to tide us over until true multi-db for our own simple
> multi-postgresql-database case. It "seems to work", though doesn't
> address a bunch of stuff true multi-db would cover 

> class ExtDBManager(models.Manager):
...

Hmph. In case some poor soul stumbles on this thread in the archives-
Turns out that didn't quite work as it was for many to many fields, as
they try to construct a further subclass of the manager.  So, a factory
function that churns out instances of subclasses with the extra
connection as a class field so that the further subclassing inherits the
connection - i.e.

def make_extdbmanager(conn, *args, **kwargs):
if isinstance(conn, basestring):
c = get_connection(conn) # just a convenience function
else:
c = conn
class _ExtDBManager(models.Manager):
connection = c
def get_query_set(self):
qs = super(_ExtDBManager, self).get_query_set()
qs.query.connection = self.connection
return qs
return _ExtDBManager(*args, **kwargs)

Yeah, this is probably all not the best idea ever, but all just to tide
us over.






--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Marking usernames as not for use dynamically

2009-11-02 Thread Sean Brant

So i have user profiles at http://domain.com/username. I'd like to
prevent a user from signing up with a username that is the same as a
page on my site (ie: /login/, /blog/, etc). I was thinking I could
inspect my url patterns to determine what pages exist  so I can
prevent that from being a username. Although I'm not sure how
expensive that will be. I'd rather not have to maintain a list in my
settings file. Anyone know of a solution for this? Seems like a fairly
common use case.

Sean

--~--~-~--~~~---~--~~
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 1.1.1 - Can't get form validation working

2009-11-02 Thread Lakshman Prasad
To add to all the helpful messages above, for forms with standard fields,
django comes loaded with inbuilt forms.

A quick scan of the source shows (django.contrib.auth.forms) following
inbuilt forms:

AdminPasswordChangeForm
AuthenticationForm
PasswordChangeForm
PasswordResetForm
SetPasswordForm
UserChangeForm
*UserCreationForm*(Similar to RegistrationForm of your example.)

Also, if you need to, eventually, you may as well extend the above forms, to
add/remove fields.
While we are at it, worth mentioning, the django.contrib.auth.views also
contains views for all standard operations, like login, register, change
password etc.

Best!

On Mon, Nov 2, 2009 at 8:09 PM, Andrew  wrote:

>
> Thanks Guys,
> I understand about the form issues...I was just tinkering...
> However yes it was the comma's I had at the end of the fields in my
> form. They didn't throw errors for the face its a sequence as you said
> Karen.
> Thanks Karen and David for such a quick response...
> Andrew
>
> On Nov 2, 2:08 pm, Karen Tracey  wrote:
> > On Mon, Nov 2, 2009 at 9:57 AM, David De La Harpe Golden <
> >
> >
> >
> > david.delaharpe.gol...@ichec.ie> wrote:
> >
> > > Karen Tracey wrote:
> > > > Commas are good on the ends of elements in a sequence, they are not
> > > > good here.
> >
> > > Indeed, a comma at the end actively denotes a kind of sequence, a
> matter
> > > of python syntax. There won't be an immediate error as "blah," means
> > > "1-element tuple" as per
> > >
> http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
> >
> > > i.e.
> > > username = forms.CharField(),
> > > means
> > > username = (forms.CharField(),)
> >
> > > So the assignment succeeds without error but django later won't do
> > > anything especially useful with username during inspection of the form
> > > definition as it'll look at it and go "nope, this ain't a django
> > > formfield, just some tuple"
> >
> > Ah, right.  Thanks for pointing out the explanation.  Doing something to
> > make Django fail loudly for stuff like this (I recall it tripping up
> someone
> > once on a model definition as well) might be worthwhile.  The current
> > no-error-but-really-confusing-results behavior is not ideal.
> >
> > Karen
> >
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

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



Re: Django 1.1.1 - Can't get form validation working

2009-11-02 Thread Andrew

Thanks Guys,
I understand about the form issues...I was just tinkering...
However yes it was the comma's I had at the end of the fields in my
form. They didn't throw errors for the face its a sequence as you said
Karen.
Thanks Karen and David for such a quick response...
Andrew

On Nov 2, 2:08 pm, Karen Tracey  wrote:
> On Mon, Nov 2, 2009 at 9:57 AM, David De La Harpe Golden <
>
>
>
> david.delaharpe.gol...@ichec.ie> wrote:
>
> > Karen Tracey wrote:
> > > Commas are good on the ends of elements in a sequence, they are not
> > > good here.
>
> > Indeed, a comma at the end actively denotes a kind of sequence, a matter
> > of python syntax. There won't be an immediate error as "blah," means
> > "1-element tuple" as per
> >http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
>
> > i.e.
> > username = forms.CharField(),
> > means
> > username = (forms.CharField(),)
>
> > So the assignment succeeds without error but django later won't do
> > anything especially useful with username during inspection of the form
> > definition as it'll look at it and go "nope, this ain't a django
> > formfield, just some tuple"
>
> Ah, right.  Thanks for pointing out the explanation.  Doing something to
> make Django fail loudly for stuff like this (I recall it tripping up someone
> once on a model definition as well) might be worthwhile.  The current
> no-error-but-really-confusing-results behavior is not ideal.
>
> 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 1.1.1 - Can't get form validation working

2009-11-02 Thread David De La Harpe Golden

Karen Tracey wrote:

> Ah, right.  Thanks for pointing out the explanation.  Doing something to
> make Django fail loudly for stuff like this (I recall it tripping up someone
> once on a model definition as well) might be worthwhile.  The current
> no-error-but-really-confusing-results behavior is not ideal.

Kinda tricky because assigning some tuple to some class field for some
other not-a-django-formfield purpose is probably a reasonable thing to do.

class MyForm(forms.Form):
   MYCHOICES = ("foo", "bar", "baz")
   myfield = forms.ChoiceField(choices=MYCHOICES)





--~--~-~--~~~---~--~~
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: debug toolbar problem

2009-11-02 Thread David De La Harpe Golden

FWIW, djangologging can also show you any sql queries during
request-response, with LOGGING_LOG_SQL = True in settings.py
http://code.google.com/p/django-logging/wiki/Overview

I don't know if or how debugtoolbar and djangologging are related,
but djangologging is working  nicely for my show-me-sql
needs.



--~--~-~--~~~---~--~~
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 1.1.1 - Can't get form validation working

2009-11-02 Thread Karen Tracey
On Mon, Nov 2, 2009 at 9:57 AM, David De La Harpe Golden <
david.delaharpe.gol...@ichec.ie> wrote:

>
> Karen Tracey wrote:
> > Commas are good on the ends of elements in a sequence, they are not
> > good here.
>
> Indeed, a comma at the end actively denotes a kind of sequence, a matter
> of python syntax. There won't be an immediate error as "blah," means
> "1-element tuple" as per
> http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
>
> i.e.
> username = forms.CharField(),
> means
> username = (forms.CharField(),)
>
> So the assignment succeeds without error but django later won't do
> anything especially useful with username during inspection of the form
> definition as it'll look at it and go "nope, this ain't a django
> formfield, just some tuple"
>
>
>
Ah, right.  Thanks for pointing out the explanation.  Doing something to
make Django fail loudly for stuff like this (I recall it tripping up someone
once on a model definition as well) might be worthwhile.  The current
no-error-but-really-confusing-results behavior is not ideal.

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 1.1.1 - Can't get form validation working

2009-11-02 Thread David De La Harpe Golden

Karen Tracey wrote:
> On Mon, Nov 2, 2009 at 8:55 AM, Andrew  wrote:

>> I have a form... as you can see I have "required=True" on the username
>> to test validation
>> class RegistrationForm(forms.Form):
>>username = forms.CharField(required=True),
>>email = forms.EmailField(required=True),
>>password1 = forms.CharField(required=True),
>>password2 = forms.CharField(required=True),
>>
> 
> You do not need all the required=True, that is the default.  Also you have
> commas on the end of all these lines, get rid of them. 
> For reasons I do not
> have time to figure out, they cause problems.  They are not supposed to be
> there. 

> Commas are good on the ends of elements in a sequence, they are not
> good here.

Indeed, a comma at the end actively denotes a kind of sequence, a matter
of python syntax. There won't be an immediate error as "blah," means
"1-element tuple" as per
http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences

i.e.
username = forms.CharField(),
means
username = (forms.CharField(),)

So the assignment succeeds without error but django later won't do
anything especially useful with username during inspection of the form
definition as it'll look at it and go "nope, this ain't a django
formfield, just some tuple"


--~--~-~--~~~---~--~~
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: debug toolbar problem

2009-11-02 Thread bax...@gretschpages.com

> Are you caching your pages?

Yes, but only for anonymous users

> Are you using Django ORM?

Yes

> Have you added the DebugToolbarMiddleware to your MIDDLEWARE_CLASSES
> in settings.py?

Yes. In settings:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.cache.CacheMiddleware',
'utils.lastseen.LastSeen',
'utils.ban_middleware.IPBanMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
)



DEBUG_TOOLBAR_PANELS = (
#'debug_toolbar.panels.version.VersionDebugPanel',
'debug_toolbar.panels.timer.TimerDebugPanel',
#'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
'debug_toolbar.panels.headers.HeaderDebugPanel',
'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
'debug_toolbar.panels.template.TemplateDebugPanel',
'debug_toolbar.panels.sql.SQLDebugPanel',
'debug_toolbar.panels.signals.SignalDebugPanel',
'debug_toolbar.panels.logger.LoggingPanel',
)



def custom_show_toolbar(request):
if request.user.is_superuser:
   return True # Always show toolbar, for example purposes only.
return False

DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
   # 'EXTRA_SIGNALS': ['myproject.signals.MySignal'],
'HIDE_DJANGO_SQL': False,
}

INSTALLED_APPS = (
...
'debug_toolbar',
)


I see the bars, and most appear to be working ( like version, for
example, before I turned it off), but nothing on SQL
--~--~-~--~~~---~--~~
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: Display a value from another table

2009-11-02 Thread Tom Evans
On a Book instance, the 'authors' attribute is a manager, so Tim's examples
should read:

  {% for book in books %}
{{ book.name }}
{% for author in book.authors.all %}
  {{ author }}
  {% endfor %}

  {% endfor %}

or in Python code:

  book = Book.objects.get(id=42)
  for author in book.authors.all():
print author

On Mon, Nov 2, 2009 at 1:21 PM, Tim Chase wrote:

>
> > class Author(models.Model):
> > name = models.CharField(max_length=100)
> > title = models.CharField(max_length=3, choices=TITLE_CHOICES)
> > birth_date = models.DateField(blank=True, null=True)
> >
> > def __unicode__(self):
> > return self.name
> >
> > class Book(models.Model):
> > name = models.CharField(max_length=100)
> > authors = models.ManyToManyField(Author)
> >
> > What i want is that, if i need to display the book detail it should give
> me
> > who is the other for a particular book.
>
> According to your model, a book can have more than one author,
> accessed via the "authors":
>
>   {% for book in books %}
> {{ book.name }}
> {% for author in book.authors %}
>   {{ author }}
>   {% endfor %}
> 
>   {% endfor %}
>
> or in Python code:
>
>   book = Book.objects.get(id=42)
>   for author in book.authors:
> print author
>
> You can also slice the authors to just get the first one:
>
>   arbitrary_author = book.authors[0]
>
> -tim
>
>
>
>
> >
>

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



Re: Django 1.1.1 - Can't get form validation working

2009-11-02 Thread Karen Tracey
On Mon, Nov 2, 2009 at 8:55 AM, Andrew  wrote:

>
> [snip]
> Here is the scenario
> I am doing a simple registration form...
>
> I have a form... as you can see I have "required=True" on the username
> to test validation
> class RegistrationForm(forms.Form):
>username = forms.CharField(required=True),
>email = forms.EmailField(required=True),
>password1 = forms.CharField(required=True),
>password2 = forms.CharField(required=True),
>

You do not need all the required=True, that is the default.  Also you have
commas on the end of all these lines, get rid of them. For reasons I do not
have time to figure out, they cause problems.  They are not supposed to be
there.  Commas are good on the ends of elements in a sequence, they are not
good here.



>
> I have a pattern in my url.py as you do...
>(r'^register/$','myproject.views.register'),
>
> I have a method in my view that takes the post...
> def register(request):
>if request.user.is_authenticated():
>return HttpResponseRedirect("/")
>result = ""
>if request.method == 'POST':
>form = RegistrationForm(request.POST)
>if form.is_valid():
>result = True
>else:
>result = False
>
>else:
>form = RegistrationForm()
>form = RegistrationForm()
>

Get rid of this last form = RegistrationForm().  It's causing an empty
unbound form to get sent to the template for rendering, regardless of what
path you went through above.  As a result you will never be able to see what
errors caused form validation to fail (and it will fail when you get rid of
the commas above).


>return render_to_response('pages/account/account.html', {'form':
> form,'result':result,})
>
>
>From the template, you do not need all of the {% if %} blocks like this:

   {% if form.username.errors %}
   {{ form.username.html_error_list }}
   {% endif %}

Where did html_error_list come from?  Near as I can tell bound fields don't
have this attribute, so this will print nothing even when errors exist.
These blocks should all just be like:

{{ form.username.errors }}

which will print nothing if there are no errors, and an HTML unordered list
of errors if there are any.

Also, {% if form.error_dict %} should be simply {% if form.errors %}.

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
-~--~~~~--~~--~--~---



Calling Database functions into Django Application.

2009-11-02 Thread Geobase Isoscale
Hi all,

Does anyone have an idea of how to call the functions created in the
database into Django application  ?

I'm working with Postgresql database. I have created a function using a
server-sided programming language called Pl/pgsql that will help me in
handling complex spatial business logic that I cannot define within Django.
How do I call such functions?

I'm informed that django supports triggers and function though it cannot
create them . Thats why I have defined then in the Database..

Many Thanks

Isoscale.

--~--~-~--~~~---~--~~
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: Display a value from another table

2009-11-02 Thread Tim Chase

> class Author(models.Model):
> name = models.CharField(max_length=100)
> title = models.CharField(max_length=3, choices=TITLE_CHOICES)
> birth_date = models.DateField(blank=True, null=True)
> 
> def __unicode__(self):
> return self.name
> 
> class Book(models.Model):
> name = models.CharField(max_length=100)
> authors = models.ManyToManyField(Author)
> 
> What i want is that, if i need to display the book detail it should give me
> who is the other for a particular book.

According to your model, a book can have more than one author, 
accessed via the "authors":

   {% for book in books %}
 {{ book.name }}
 {% for author in book.authors %}
   {{ author }}
   {% endfor %}
 
   {% endfor %}

or in Python code:

   book = Book.objects.get(id=42)
   for author in book.authors:
 print author

You can also slice the authors to just get the first one:

   arbitrary_author = book.authors[0]

-tim




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



Re: Django 1.1.1 - Can't get form validation working

2009-11-02 Thread Andrew


I forgot to add my form post...here it is  ...


{% if form.error_dict %}
Please correct the errors below.
{% endif %}


{% if form.username.errors %}
{{ form.username.html_error_list }}
{% endif %}
Username:



{% if form.email.errors %}
{{ form.email.html_error_list }}
{% endif %}
Email:



{% if form.password1.errors %}
{{ form.password1.html_error_list }}
{% endif %}
Password: 



{% if form.password2.errors %}
{{ form.password2.html_error_list }}
{% endif %}
Password (again):






On Nov 2, 12:55 pm, Andrew  wrote:
> Hi,
> I am well used to working with Django, however I am stuck on a basic
> issue at present if anyone can spread some light. Note I have no
> compile errors and it runs fine. I have put in a variable "result" to
> check the value of form.is_valid() which is showing as always True.  I
> have tried everyting initially thinking it was my Ubuntu dev
> environment but I ran it on debian etch with django version 1.0.3 and
> got the same thing. Any help greatly appreciated.
> Thanks
> Andrew
>
> Here is the scenario
> I am doing a simple registration form...
>
> I have a form... as you can see I have "required=True" on the username
> to test validation
> class RegistrationForm(forms.Form):
>     username = forms.CharField(required=True),
>     email = forms.EmailField(required=True),
>     password1 = forms.CharField(required=True),
>     password2 = forms.CharField(required=True),
>
> I have a pattern in my url.py as you do...
>     (r'^register/$','myproject.views.register'),
>
> I have a method in my view that takes the post...
> def register(request):
>     if request.user.is_authenticated():
>         return HttpResponseRedirect("/")
>     result = ""
>     if request.method == 'POST':
>         form = RegistrationForm(request.POST)
>         if form.is_valid():
>             result = True
>         else:
>             result = False
>
>     else:
>         form = RegistrationForm()
>     form = RegistrationForm()
>     return render_to_response('pages/account/account.html', {'form':
> form,'result':result,})
--~--~-~--~~~---~--~~
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 1.1.1 - Can't get form validation working

2009-11-02 Thread Andrew

Hi,
I am well used to working with Django, however I am stuck on a basic
issue at present if anyone can spread some light. Note I have no
compile errors and it runs fine. I have put in a variable "result" to
check the value of form.is_valid() which is showing as always True.  I
have tried everyting initially thinking it was my Ubuntu dev
environment but I ran it on debian etch with django version 1.0.3 and
got the same thing. Any help greatly appreciated.
Thanks
Andrew

Here is the scenario
I am doing a simple registration form...

I have a form... as you can see I have "required=True" on the username
to test validation
class RegistrationForm(forms.Form):
username = forms.CharField(required=True),
email = forms.EmailField(required=True),
password1 = forms.CharField(required=True),
password2 = forms.CharField(required=True),

I have a pattern in my url.py as you do...
(r'^register/$','myproject.views.register'),

I have a method in my view that takes the post...
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect("/")
result = ""
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
result = True
else:
result = False

else:
form = RegistrationForm()
form = RegistrationForm()
return render_to_response('pages/account/account.html', {'form':
form,'result':result,})

--~--~-~--~~~---~--~~
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: Template processing/pre-processing

2009-11-02 Thread rd-london

Not worry, found work-a-round using MEDIA_URL.


On Oct 30, 4:39 pm, rd-london  wrote:
> Hi,
>
> I'd like to write some code, probably middleware, that look at various
> types of HTML in templates and prepends a setting from settings.py.
>
> For example, I'd like to pickup all .js, .css, .jpg, .png, .gif - and
> stick a custom setting from settings.py on the front - effectively a
> path.
>
> Ideally, I'd like to do this by-project, so one project will have one
> such setting in a settings.py, another project will have nother.
>
> I'm not looking for a solution (although one would certainly be
> welcome), but where to start looking would be handy. Feels like its
> some kind of template pre-processing middleware - but anyone any
> pointers/tips?
>
> Many thanks for any help,
> R
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: debug toolbar problem

2009-11-02 Thread Daniel Roseman

On Nov 1, 9:27 pm, "bax...@gretschpages.com" 
wrote:
> I finally installed the django debug toolbar, which looks like a very
> nice piece of work, but it's not reporting sql queries for me. Every
> page: 0 queries, 0 seconds.
>
> Any suggestions on where the problem may lie?

Have you added the DebugToolbarMiddleware to your MIDDLEWARE_CLASSES
in settings.py?
--
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: Form that updates a list of items?

2009-11-02 Thread Julien Petitperrin
Hello,

I had this kind of issue a few days ago. I found this:

http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/

I hope this helps you to find a way to do your multiple items edit form.

Have a nice day,
Julien.

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



Re: Distributing a Django site along with Apache and MySQL

2009-11-02 Thread pjrhar...@gmail.com

I've done this exact thing before, I had to package apache, django, my
project and a ton of other packages that I needed. I found the easiest
way in the end was using nsis(1). I packaged django up as an msi(2),
got python and apache as msi installers, mod_python as an exe and then
just had it copy my project directory and the apache configuration
files to the correct places.

One really annoying problem I came across was some dll problems on
windows where it wouldn't work on every computer, so sometimes you
also need the Microsoft visual C++ runtime. I can't remember now if
this was because of python or because of one of the other packages I
needed.

I can mail you the nsis script file I used if it helps, but it was
fairly basic.

Pete


1. http://nsis.sourceforge.net
2. http://code.djangoproject.com/ticket/11236
--~--~-~--~~~---~--~~
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: Display Certain Fields of the Model Formset As Text

2009-11-02 Thread David De La Harpe Golden

Preston Holmes wrote:

> When using widget.attr how does one specify a attr that is name only,
> not key/value.
> 
> The disabled key is not a k/v attr:
> 
> 
> 

In xhtml 1 (fwiw) it is, you are required to write disabled="disabled"
(I think) and it is also allowed to do so in html 4
See section "attribute minimisation" and
"boolean attributes" in xhtml 1.0
http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.5
http://www.w3.org/TR/2002/REC-xhtml1-20020801/#C_10

I imagine they'll grandfather in allowing such "unminimized"
attributes into html 5, even if xhtml has fallen by the wayside.


--~--~-~--~~~---~--~~
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: Display a value from another table

2009-11-02 Thread Denis Bahati
Here is my model.

TITLE_CHOICES = (
('MR', 'Mr.'),
('MRS', 'Mrs.'),
('MS', 'Ms.'),
)

class Author(models.Model):
name = models.CharField(max_length=100)
title = models.CharField(max_length=3, choices=TITLE_CHOICES)
birth_date = models.DateField(blank=True, null=True)

def __unicode__(self):
return self.name

class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)

class AuthorForm(ModelForm):
class Meta:
model = Author

class BookForm(ModelForm):
class Meta:
model = Book

What i want is that, if i need to display the book detail it should give me
who is the other for a particular book.

On Mon, Nov 2, 2009 at 9:25 AM, Rishabh Manocha  wrote:

> On Mon, Nov 2, 2009 at 1:43 PM, Denis Bahati  wrote:
>
>> Hi All,
>> Am developing an application where by it links two tables author and book,
>> the id of author is a foreign key to book table. How can i display the name
>> of the author when am displaying the book list.
>>
>>
>>
> I'm not sure how you the id of an author can be a ForeignKey to a Book. Can
> you paste your models so that we can get a clearer picture. Assuming your
> Book model looks something like the below:
>
> class Book(models.Model):
> ...
> author = models.ForeignKey(Author)
>
> You would do:
>
> >>> my_author = Author.objects.create('James Joyce')
> >>> my_book = Book.objects.create(..., author = my_author)
> >>> my_book.author
> 
>
> --
>
> Best,
>
> R
>
> >
>

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



Re: Remote developer opportunity

2009-11-02 Thread Russell Keith-Magee

On Mon, Nov 2, 2009 at 6:19 PM, Kenneth Gonsalves  wrote:
>
> On Monday 02 Nov 2009 3:37:38 pm Chris Withers wrote:
>> Kenneth Gonsalves wrote:
>> > On Monday 02 Nov 2009 1:17:01 pm Kashif Azeem wrote:
>> >> I am interested. If you can write a little bit about yourself, type of
>> >>  work, how to apply?
>> >
>> >
>> > please take this offlist
>>
>> It was probably a mistake. Google groups is pretty annoying in the way
>> it sets the Reply-To header to the list address...
>>
>
> it is not google groups - the list admins have done this

Yes. And we have done it for a reason. In 99% of cases, the right way
to respond to a message on Django-users is to respond to Django-users.
We want to encourage community discussion, not drive discussions into
the private realm. The need for private responses is the exception,
not the rule.

To this end, we rely upon the discretion of individuals to determine
when a private response is appropriate.

We also rely on the patience of the remainder of the group when
someone posts a public message that should be private. A public
request for information that should be private is mildly annoying. A
thread arguing about whether a post was appropriate or not is much
more annoying.

Believe it or not, the list admins actually read the list. If someone
makes a habit of posting publicly when they should be posting
privately, we will take the matter up with them. There's no need to
fill over 15000 inboxes with noise in the interim.

Yours,
Russ Magee %-)

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



Re: Making the case for Django (vs. Drupal)

2009-11-02 Thread Dougal Matthews
2009/10/31 shacker 

>
> Things like the announcement that
> whitehouse.gov switched to Drupal just cement the deal in many
> managers' minds.
>
>
I can't find the source for this (the original tweeter has protected tweets)
but if true its an interesting stat.

http://twitter.com/pydanny/status/5263754707

Plone not Django, but its closer than Drupal.

Cheers,
Dougal

--~--~-~--~~~---~--~~
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: Remote developer opportunity

2009-11-02 Thread Oli Warner
Personally, I think Kashif's information request is pertinent to the opening
post and should be replied to in the clear so anybody interested in the
first post can also read 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: Remote developer opportunity

2009-11-02 Thread Sam Lai

2009/11/2 Chris Withers :
>
> It was probably a mistake. Google groups is pretty annoying in the way
> it sets the Reply-To header to the list address...

Isn't that a generally desired option though? The likelihood of me
wanting to reply privately is much smaller than me wanting to reply to
the entire list. It would be very annoying if I had to manually enter
the address of the list every time I wanted to respond.

And people don't seem to like having private off-list discussions
unless they requested it or if it is definitely only applicable to you
and the recipient (e.g. in this case).

--~--~-~--~~~---~--~~
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: Remote developer opportunity

2009-11-02 Thread Kenneth Gonsalves

On Monday 02 Nov 2009 3:37:38 pm Chris Withers wrote:
> Kenneth Gonsalves wrote:
> > On Monday 02 Nov 2009 1:17:01 pm Kashif Azeem wrote:
> >> I am interested. If you can write a little bit about yourself, type of
> >>  work, how to apply?
> >
> > 
> > please take this offlist
> 
> It was probably a mistake. Google groups is pretty annoying in the way 
> it sets the Reply-To header to the list address...
> 

it is not google groups - the list admins have done this
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

--~--~-~--~~~---~--~~
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: Remote developer opportunity

2009-11-02 Thread Chris Withers

Kenneth Gonsalves wrote:
> On Monday 02 Nov 2009 1:17:01 pm Kashif Azeem wrote:
>> I am interested. If you can write a little bit about yourself, type of
>>  work, how to apply?
> 
> please take this offlist

It was probably a mistake. Google groups is pretty annoying in the way 
it sets the Reply-To header to the list address...

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

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

2009-11-02 Thread Kenneth Gonsalves

On Monday 02 Nov 2009 9:54:11 am Kenneth Gonsalves wrote:
> On Monday 02 Nov 2009 9:36:23 am Graham Dumpleton wrote:
> > > these are usually user generated - they love to put spaces. I can
> > > handle spaces, but would like to know how the spaces become %20 and how
> > > to prevent this.
> >
> > 
> > As someone else pointed out, likely from the browser.
> 
> it is not from the browser - I have not changed my browser recently, and
>  it  was not converting the strings. The change has come when I shifted to
>  nginx+tornado - one of these is doing it.
> 

on further testing it is not nginx that is doing it. Either tornado or django 
itself (which means it is due to the weekly svn up - but I would guess it is 
tornado)
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

--~--~-~--~~~---~--~~
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: Remote developer opportunity

2009-11-02 Thread Kenneth Gonsalves

On Monday 02 Nov 2009 1:17:01 pm Kashif Azeem wrote:
> I am interested. If you can write a little bit about yourself, type of
>  work, how to apply?
> 

please take this offlist
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---