Re: template problema in deployment system

2007-02-09 Thread Karen Tracey
This:

o /home/ivan/django-projects/immobilhouse/templates/home/index.html
> (File exists)


would appear to indicate the template loader was able to find the file but
not read it.  Are the permissions set on your template files/folder so that
the apache process can read the templates?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Running django with stackless

2007-02-09 Thread krypton

Guys I m using threads to use concurrecy in my webapps and I find it
to be needlessly slow, because most of the stuff thatI try to do with
the thread are like, send messages, update a long running thread,
update rss feeds etcc., ie they do not need context and Hence i do not
need threads

Upon researching I found an implementation of python that doesnt use C-
Stacks and hence supports Co-routines. Here is my question. I want to
use webpy with stackless python.

The problem I m facing is there are parts of webpy that are hacked
with frame operations. Is there any one who has webpy running on
stackless. If so please share the patch

Thanks a lot Krypton


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make a list of allowable arguments for filter()

2007-02-09 Thread abe

>
> I really tried hard to understand your problem, but then my brain
> started to leak out of my ears and I had to stop. :-(
>
> Could you post an example of how all these models are related? You seem
> to have Relmodl2, model2 and model1 and I'm not sure what all the
> linkages are.
>
> I think what you are asking is why does the reverse end of a ForeignKey
> show up in get_all_related_objects(), but the forward direction does
> not. If that is the question, the forward direction (the ForeignKey
> field itself), is just an object of class ForeignKey in the _meta.fields
> attribute on the model it is defined on. So you need to inspect the
> class types in _meta.fields to see which are the forwards relations.
>
> If that isn't your question, I apologise and ask only for a simple
> example to illustrate the problem.
>
> Regards,
> Malcolm



sorry, shouldn't post so late I guess...

I would like to make a list of allowable arguments for filter
to supply that as a selection list on a search page.

so I have to get a list of 'model__field' like strings
derived from  models (models.get_all_models())


class Poll(models.Model):
question = models.CharField(maxlength=200)
pub_date = models.DateTimeField('date published')


class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(maxlength=200)
votes = models.IntegerField()

relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
  for m in Poll._meta.get_all_related_objects()
  for f in m.model._meta.fields ]

relfieldargs:
['choice__id', 'choice__poll', 'choice__choice', 'choice__votes']

I can use these as (part of)arguments for filter

Poll.objects.filter(choice__votes__gt=0)


but the other way around doesn't work (from Choice->Poll)

relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
  for m in Choice._meta.get_all_related_objects()
  for f in m.model._meta.fields ]

relfieldargs:
[]

so I need some other way to get those.


Now you seem to say that the answer is in here,


In [18]: [f for f in Choice._meta.fields]
Out[18]:
[,
 ,
 ,
 ]

which I can see. but how do a make an expression to test for
foreignkey
(except for  'fields.related' in `f` which seems a bit clumsy)


and then of course I would like to find the 2nd (or higher) order
cases too

'model1__model2__field_of_model2'

any simple ways to find those?

thanks for your help.


abe


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Trouble with relations

2007-02-09 Thread Russell Keith-Magee

On 2/8/07, Henrik Lied <[EMAIL PROTECTED]> wrote:
>
> Hi there!
>
> I guess I'll have to call Entry.objects.filter(ARGS HERE), but exactly
> what args I should use I don't know.

The easiest way is to use the ``latest`` operator:

FrontPageEntry.objects.latest('added')

This will return the entry with the most recent 'added' date.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Inserting dummy content

2007-02-09 Thread Russell Keith-Magee

On 2/9/07, Henrik Lied <[EMAIL PROTECTED]> wrote:
>
> Hi there!
>
> I was wondering if there's an easy way to insert a lot of dummy
> content into a couple of models. Have anyone written something that
> does this?

Yes  - it's not quite in Django yet, but it will be soon (before v1.0).

Its the fixtures framework. A patch containing the code is attached to
ticket #2333; You may also need to apply the patches from tickets
#3390 and #2720 depending on the complexity of your data model and
your database backend.

The original intent was to allow developers to write unit tests, and
have data in the database during that test; however, it can also be
used to put a whole lot of initial data into the database.

It's not documented yet, but the modeltest that is part of ticket
#2333 should give you an example of how to use the fixtures framework
programatically. From the command line, its as simple as:
- creating a fixtures directory in your application directory
- putting mydata.json in the fixtures directory
- filling mydata.json with intialization data
- running ./manage.py loaddata mydata

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problem with a Class

2007-02-09 Thread xgdlm

Hello,

I found this very interesting post :

http://groups.google.com/group/django-users/browse_frm/thread/bb7f406bffd697f5

Then I tried to apply this modele to mine, but I have trouble !

Here is the class :

#
class VideoSeq(models.Model):
video = models.ForeignKey(Video,edit_inline=models.STACKED,
db_index=True)
Title =
models.CharField(maxlength=200,null=False,blank=False,core=True)
Number = models.IntegerField(maxlength=2,db_index=True)
Duration = models.IntegerField(maxlength=2,db_index=True)
has_lang = models.CharField(maxlength=2,null=False,
db_index=True,choices=HAS_LANG_CHOICES,)
has_thumb = models.BooleanField(db_index=True)
is_done = models.BooleanField(db_index=True)
updated_at = models.DateTimeField(auto_now=True)

def delete(self):
#
flv_path = "%s/seq%s.flv" % ("/home/vids",self.Number)
img_path = "%s/seq%s.jpg" % ("/home/vids",self.Number)
#
if os.path.isfile(flv_path):
os.remove(flv_path)
#
if os.path.isfile(img_path):
os.remove(img_path)
#
super(VideoSeq, self).delete()
#
def __str__(self):
return "Seq %s" % (self.Number)

class Admin:
  pass
##

I don't understand why I have the following errors while using it :

name 'flv_path' is not defined
name 'img_path' is not defined
name 'VideoSeq' is not defined

Any advice is appreciate :)

Regards,

xav


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Creating HTML emails

2007-02-09 Thread Tipan

I've been able to create Plain text emails to send to users with an
authentication link which work well, however I'd like to improve the
look of these by outputting in HTML with a logo. If I use the
send_mail function it simply incorporates the HTML in the plain text.

Can anyone point me in the right direction with the process required
for formatting and sending my emails from Django in HTML?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Installed apps settings, necessary?

2007-02-09 Thread voltron

Hi all, going bto install apps, one must add them to ty the book, the
INSTALLED_APPS tuple setting, I noticed however that one that one can
wire up views and in app directories and they work fine even if not
added to the tuple in the settings file.

My question:

what are the advantages of adding the apps to the settings file?


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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Trouble with models

2007-02-09 Thread DuncanM

Hi, I know this isn't necessarily a Django specific problem but I am
using django to develop my system so here goes.
Basically I am making a system for a football team (soccer for you
americans) and can't seem to get my head around a way of possibly
doing it.

I've left out some of the other stuff I don't need but what I'm trying
to model is:

Team (e.g. Senior Team 1st's, U7's etc)
Players which belong to a team/squad
Squad (which consists of players that are part of a team e.g. Senior
Team)


The confusion I am having is around the team/squad situation.

A team (say Senior Team) Isn't just one "team" it is a set of teams
e.g. Senior Team 1st's, Senior Team 2nds etc.

I don't want a player to be replicated but if they belong to a team
they also need to belong to the squad. (I hope I'm making sense)

For instance the situation below:

ManchesterUtd 1st Team consists of players (lets say paul scholes, rio
ferdinand, wayne rooney, christiano ronaldo)
The squad includes every player who no longer belongs to the youth
academy (obviously alot of players possibly up to 100)  But the team
is picked from the squad.  And if a player from the 1st team (wayne
rooney) was recovering from an injury or wasn't playing well he could
be dropped to the Reserve Team.

I am unsure of how to model this without having wayne rooney belong to
the 1st team, and have a duplicated one in the second team?

Any help is very very much appreciated.

Duncan


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



are the Installed apps settings necessary?

2007-02-09 Thread voltron

I posted this yesterday, but It did not show up, strange.

According to the manual, one has to add apps to the INSTALLED_APPS
setting tuple to make the usable in a project. I have created several
test apps with views wired to urls in the projects url conf file, I
was able to call up all urls without any problems.

What is the main advantage of listing the apps in the INSTALLED_APPS
variable? Not that I`m complaining, Im just curious, in fact if its
not a necessity, It makes my apps more portable, I just copy the apps
I need to another Project folder, wire up the urls  and they work, one
step less to take.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



[howto] Django profiling with hotshot and kcachegrind

2007-02-09 Thread [EMAIL PROTECTED]

The link: http://www.rkblog.rk.edu.pl/w/p/django-profiling-hotshot-and-
kcachegrind/
The cool screenshot: http://www.rkblog.rk.edu.pl/site_media/resources/
python.rk.edu.pl/images/djangoprof2.png

Kcachegrind can visualize profilers logs in many nice readable
"formats". Hotshot is a python profiler and django has a handler for
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to postpone HttpResponse but still get new requests

2007-02-09 Thread Dill0r

Hi,

i got a producer-consumer class which await new items from the
clients, does sth with them and provides them to all clients.

the url "getNewItems" is for getting the new Items and vice versa.

my problem is: when i wait for new items, i cant get new, cause this
stuff is all in one thread.
is there a way to save the request so i can send a response later
(when the are new items).
or maybe i could start 2 threads per client or sth ...!?

any idea?


from foo import producerConsumer

def getNewItems(request):
   p = producerConsumer()
   newItems = p.consume() # wating for new items here
   return HttpRespone(newItems)


def putNewItem(request):
   p = producerConsumer()
   p.produce(request.__getItem__("item")) # notifyAll here
   #no response needed here


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Inserting dummy content

2007-02-09 Thread Henrik Lied

Hi there!

I was wondering if there's an easy way to insert a lot of dummy
content into a couple of models. Have anyone written something that
does this?

The reason I'm asking is that I'm writing this social networking app,
and in a while I'm going to present it to a company. It would be nice
to have a bunch of dummy users and dummy content by then, just to
illustrate the power of the built in admin filtering possibilities.
I'm not to keen on creating fifty different users, and just as many
user profiles and content, if you know what I mean.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



oldforms, file upload, rename & save

2007-02-09 Thread sandro.dentella

Hi all,

  I spent the last 2 hours fighting with a model.FileField  that I
wanted to save the file with a custom name (job number of a hylafax
server).
  I found a related thread here: http://groups.google.com/group/django-
users/browse_frm/thread/f337faf5ef5d8f9a/3c183363b21b496d?
lnk=gst=file+upload+form=7=en#3c183363b21b496d
  so I tried to define a save as suggested:

 def save(self):
   oldname = self.file_field
   # rename & move file to new name if needed
   self.file_field = newname
   super(Fax, self).save()

this does not work for me.
It seems save method is called twice by the generic view create_update
within the call 'manipulator.save(new_data)'. The fist time self.file
is empty the second already has the automatically generated filename.
Why is it called twice? Now I call os.rename but wich should be the
correct way to do it?

Thanks in advance
sandro
*;-)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django Server Tools

2007-02-09 Thread Gacha

Hi, I made a small script that helps me to deal with many Django app
on the same server. Maybe somebody has similar script's or techniques
to do this job, please share with it. I just want to know, should I
develop it further or there are better ways to solve this.

link: http://gacha.id.lv/en/dstools/

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Creating HTML emails

2007-02-09 Thread Tipan

I've been able to create Plain text emails to send to users with an
authentication link which work well, however I'd like to improve the
look of these by outputting in HTML with a logo. If I use the
send_mail function it simply incorporates the HTML in the plain text.

Can anyone point me in the right direction with the process required
for formatting and sending my emails from Django in HTML?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



new forms - problem populating with data from a table

2007-02-09 Thread Tipan

I'm new to Django and a relatively inexperienced programmer. I've
started working with the new forms and have been able to take user
input, validate it and write it to the table. Really slick and with
minimal code. Great.

I now want to take an existing user record and create an edit account
form, where the data entered by the user in the registration form is
represented and available to edit. Seemed simple when I set out to do
it, but I can't seem to populate the form.

Should I define which data goes into the form fields using the
'initial' data in the Form definition? If so, how would I do this,
because I don't know the user_id and can't place a -
userid=request.user.id request in this definition.

This would suggest that I do the form population in the view
definition. At the moment it looks like this:

 if not request.user.is_authenticated():
return HttpResponseRedirect("/userlogin/")
else:
if request.method == 'POST':
form=UserAccountForm(request.POST)
if form.is_valid():
user_nm= form.clean_data['username']
# rest of form input and code validation
return render_to_response('account.html',
{''form':form})
else:
form=UserAccountForm()
return render_to_response('account.html',{'form':form})

However, all of the fields are empty (not surprisingly because I've
not linked with the data)
Can anyone give me a bit of guidance on populating the form from the
table?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



I checked out psycopg2 out of svn and installed it and got these errors

2007-02-09 Thread mobil

Hello guys

I checked out psycopg2 out of svn and installed it and got these
errors
any ideas on how to fix them

Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/psycopg2/__init__.py", line
60, in ?
from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /usr/lib/python2.4/site-packages/psycopg2/_psycopg.so:
undefined symbol: lo_create
>>> import psycopg2
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/psycopg2/__init__.py", line
55, in ?
from psycopg2 import tz
ImportError: cannot import name tz


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



python manage.py broken

2007-02-09 Thread Arnaud Delobelle

Hi all

Today I have moved a project that I have been working on to
subversion.
Prior to doing this I made a copy of the source tree and remove all
the *.pyc and the "dot something" files. I then imported the whole
tree to a subversion repository and checked it out again.  I worked on
it all day, and committed a few changes but tonight I realised that
python manage.py wasn't working anymore at all (even though the site
works fine through apache+mod_python) !  I include below the error
message when I try the shell.

daffodil:~/django/qmm arno$ python manage.py shell
Traceback (most recent call last):
  File "manage.py", line 11, in ?
execute_manager(settings)
  File "/opt/local/lib/python2.4/site-packages/django/core/
management.py", line 1447, in execute_manager
execute_from_command_line(action_mapping, argv)
  File "/opt/local/lib/python2.4/site-packages/django/core/
management.py", line 1348, in execute_from_command_line
translation.activate('en-us')
  File "/opt/local/lib/python2.4/site-packages/django/utils/
translation/trans_real.py", line 195, in activate
_active[currentThread()] = translation(language)
  File "/opt/local/lib/python2.4/site-packages/django/utils/
translation/trans_real.py", line 184, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/opt/local/lib/python2.4/site-packages/django/utils/
translation/trans_real.py", line 167, in _fetch
app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]),
appname[p+1:])
AttributeError: 'module' object has no attribute 'test'

And here is the information about my django installation

daffodil:~/django/django_src arno$ svn info
Path: .
URL: http://code.djangoproject.com/svn/django/trunk
Repository Root: http://code.djangoproject.com/svn
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 4463
Node Kind: directory
Schedule: normal
Last Changed Author: russellm
Last Changed Rev: 4463
Last Changed Date: 2007-02-07 22:56:53 + (Wed, 07 Feb 2007)
Properties Last Updated: 2006-11-06 18:18:59 + (Mon, 06 Nov 2006)

I have the same problem on my OSX laptop and debian Etch server so I
think it is something that I messed up when I cleaned up the tree
before importing it to my subversion repository but I can't figure out
why.

Any help would be greatly appreciated.

--
Arnaud


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template problema in deployment system

2007-02-09 Thread enrik

In development system the templates is ok, but in deployment it is not
ok. I use apache 2 and mod_python 3 in according with ufficials docs.

Follows the error page when I request the resource by url:

TemplateDoesNotExist at /
home/index.html
Request Method: GET
Request URL: http://ih.local/
Exception Type: TemplateDoesNotExist
Exception Value: home/index.html
Exception Location: /usr/lib/python2.4/site-packages/django/template/
loader.py in find_template_source, line 72
Template-loader postmortem

Django tried loading these templates, in this order:

* Using loader
django.template.loaders.filesystem.load_template_source:
o /home/ivan/django-projects/immobilhouse/templates/home/index.html
(File exists)
o /usr/local/src/django_src/django/contrib/home/index.html (File does
not exist)
* Using loader
django.template.loaders.app_directories.load_template_source:
o /usr/lib/python2.4/site-packages/django/contrib/admin/templates/home/
index.html (File does not exist)

[snip]

Follow the apache config file:

ServerName ih.local
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE immobilhouse.settings
PythonPath "sys.path+['/home/ivan/django-projects/']"
PythonInterpreter immobilhouse
PythonDebug On
Alias /media "/home/ivan/django-projects/immobilhouse/media"

SetHandler None


Why?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Trouble with relations

2007-02-09 Thread Henrik Lied

Hi there!

I'm currently working on a project which mixes user generated content
with journalistic content.
The system lets users vote on an article, and articles with many
positive votes will come up in the admin-panel, so that the moderators
can label the entry for front page status.

class FrontPageEntry(models.Model):
added = models.DateTimeField(auto_now_add=True)
entry_id = models.ForeignKey(Entry, raw_id_admin=True)


This model above is the one used to set the newest feature-article on
the front page.
What I'm a little confused about is how I'm going to get this
displayed!

I guess I'll have to call Entry.objects.filter(ARGS HERE), but exactly
what args I should use I don't know.


Can someone push me in the right direction? :-)


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



Sorting a query set

2007-02-09 Thread MerMer



Is it possible to sort a query set based on an integer in one of the
fields.

MerMer


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Derek Lee-Wo

> I took a look and traced the bottleneck to lines 125 and 127 in
> viewPlan.html. The problem was as Malcolm hinted -- you're
> doing a foreign key lookup ({{ workout.workoutType.name }})
> for each iteration of the for loop.
>
> I changed line 55 of views.py to use select_related() instead
> of all() and it solved the problem as now it no longer needs
> to hit the database for every iteration.
>
> - workouts = plan.workouts.all()
> + workouts = plan.workouts.select_related()

Thanks!!! I made the change and it works great.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Chris Nelson

Derek Lee-Wo wrote:
>  The app I have is pretty simply as I'm just beginning so I didn't
>  bother to try and make it any smaller.  I've ZIPped the entire
>  project directory and it can be downloaded here:
>
>  http://www.roadtoboston.com/media/RoadToBoston.zip
>
>

I took a look and traced the bottleneck to lines 125 and 127 in
viewPlan.html. The problem was as Malcolm hinted -- you're
doing a foreign key lookup ({{ workout.workoutType.name }})
for each iteration of the for loop.

I changed line 55 of views.py to use select_related() instead
of all() and it solved the problem as now it no longer needs
to hit the database for every iteration.

- workouts = plan.workouts.all()
+ workouts = plan.workouts.select_related()

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Use of post_save on newly created objects

2007-02-09 Thread Malcolm Tredinnick

On Fri, 2007-02-09 at 22:09 -0500, Benjamin Slavin wrote:
> Howdy all,
> 
> I was investigating post_save to perform some associated setup for an
> object after it's created.  My only concern is that I can't seem to
> find any way to check if the object was created on this call to
> save()... I only want to perform the setup the first time the object
> is saved.
> 
> So... Is it possible to perform a function (via post_save or some
> other mechanism) when a given object is saved for the first time?
> 
> Perhaps the addition of a post_create signal could be a solution, but
> I didn't want to bring that up on django-developers until I asked
> here.

Using the signal system might be overkill here. Can you achieve whatever
you want with your own save() method (remember that you can then call
the model's default save() method after doing your own stuff)?

If you can do that, then a common way to check if the model is being
created is to check the automatically created "id" (surrogate primary
key) attribute. If it's empty, the model hasn't been saved yet (since it
doesn't have a database-assigned primary key value). This doesn't work
in cases where you manually assign the primary key value, but it is
sufficient for many common uses.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Use of post_save on newly created objects

2007-02-09 Thread Benjamin Slavin

Howdy all,

I was investigating post_save to perform some associated setup for an
object after it's created.  My only concern is that I can't seem to
find any way to check if the object was created on this call to
save()... I only want to perform the setup the first time the object
is saved.

So... Is it possible to perform a function (via post_save or some
other mechanism) when a given object is saved for the first time?

Perhaps the addition of a post_create signal could be a solution, but
I didn't want to bring that up on django-developers until I asked
here.

Thanks,
  -Ben

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make a list of allowable arguments for filter()

2007-02-09 Thread Malcolm Tredinnick

On Sat, 2007-02-10 at 00:41 +, abe wrote:
> sorry for the previous post. accidentally pressed send too early.
> 
> I can find the models which have a certain model as a ForeignKey like
> this
> 
> modl=models.get_model('myapp','model1')
> 
> relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
>   for m in modl._meta.get_all_related_objects()
>   for f in m.model._meta.fields ]
> 
> relfieldargs
> Out[  ]:
> ['relmodl2__id',
>  'relmodl2__name',
>  'relmodl2__foo',
>  etc.
>  ]
> 
> where {relmodl2__name:value} etc can be use as argument
> to modl.objects.filter(...)
> 
> this works if model Relmodl2 has model2 as ForeignKey
> but not the other way round. is there an eay way to find
> those model and field names?
> 
> for example  relmodl2.objects.filter({'model1__nr__gt':5})
> 
> where I'm looking for the other allowed strings like  'model1__nr'
> 
> 
> or is there an alltogether easier way to do this.

I really tried hard to understand your problem, but then my brain
started to leak out of my ears and I had to stop. :-(

Could you post an example of how all these models are related? You seem
to have Relmodl2, model2 and model1 and I'm not sure what all the
linkages are.

I think what you are asking is why does the reverse end of a ForeignKey
show up in get_all_related_objects(), but the forward direction does
not. If that is the question, the forward direction (the ForeignKey
field itself), is just an object of class ForeignKey in the _meta.fields
attribute on the model it is defined on. So you need to inspect the
class types in _meta.fields to see which are the forwards relations.

If that isn't your question, I apologise and ask only for a simple
example to illustrate the problem.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problems with low level caching and locmem backend

2007-02-09 Thread Lawrence Oluyede

> In the future, please don't cross post. If you're unsure, ask on the
> users list first. The developers all read the users list too, so they
> will see your question. The discussion will get moved to the
> developers list if and when your problem raises an internal design

Ok thanks for the clarification

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing maxlength html attribute

2007-02-09 Thread Waylan Limberg

On 2/9/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:
>
> Btw, why is it called maxlength and in newforms
> max_length (or the other way around, not sure)?
> Shouldn't they be identcal?
>
maxlength is the old way and on the way out. My understanding is that
it will be replaced with max_length everywhere when oldforms are
dropped. As it'll be a backward-incompatible change it won't happen
until after 0.96 though.


-- 

Waylan Limberg
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing maxlength html attribute

2007-02-09 Thread Kai Kuehne

Btw, why is it called maxlength and in newforms
max_length (or the other way around, not sure)?
Shouldn't they be identcal?

Greetings
Kai

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing maxlength html attribute

2007-02-09 Thread Milan Andric

In the database it is 75, same here.  But the html widget was getting
rendered with maxlength=30.

I just realized I created a forms.py for it to define the html form.
It was in there, sorry for the dumb post.

Should move to newforms!

On Feb 9, 3:11 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> If you're having user registration, I think you're quickly going to
> want more than the builtin auth/user will give you.
> I'd take a look at extending the user 
> model:http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model
>
> Also, I'm not sure why it's giving you a maxlength of 30. In my
> database, email is 75 characters, and I don't recall changing that.
>
> On Feb 9, 4:56 pm, "Milan Andric" <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > I'm using contrib/auth User for my registration process like alot of
> > folks but the maxlength attr on the html form for the email is 30 and
> > that's too short.
>
> > I tried modifying contrib/auth/models.py and adding maxlength to
> > User.email but that doesn't seem to affect the form.
>
> > So I need to subclass the email form?  Where is that located?  Any
> > hints on a good way to do this?
>
> > --
> > Milan


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: use forloop.counter0 as index?

2007-02-09 Thread Brandon Warren

Thanks for the response Aidas! It was a big help to know that it was
not
possible. It got around the problem by writing a custom tag "ifin". So
I can do:

{{ ifin item list_of_items }}
  html to output if item is contained in the list
{{ endifin }}

This tag neatly solves my original problem.

In case this tag is useful to anyone else, here is the code in
mytags.py:
--- BEGIN -
# modified code from django/template/defaulttags.py

from django.template import Node, NodeList, Template, Context,
resolve_variable
from django.template import TemplateSyntaxError, VariableDoesNotExist,
BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END,
SINGLE_BRACE_START, SINGLE_BRACE_END
from django.template import get_library, Library,
InvalidTemplateLibrary
from django.conf import settings
import sys

register = Library()

class IfInNode(Node):
def __init__(self, var1, var2, nodelist_true, nodelist_false,
negate):
self.var1, self.var2 = var1, var2
self.nodelist_true, self.nodelist_false = nodelist_true,
nodelist_false
self.negate = negate

def __repr__(self):
return ""

def render(self, context):
try:
val1 = resolve_variable(self.var1, context)
except VariableDoesNotExist:
val1 = None
try:
val2 = resolve_variable(self.var2, context)
except VariableDoesNotExist:
val2 = None
if (self.negate and not (val1 in val2)) or (not self.negate
and val1 in val2):
return self.nodelist_true.render(context)
return self.nodelist_false.render(context)

def do_ifin(parser, token, negate):
"""
Output the contents of the block if the 1st arg is in the 2nd arg
(or NOT)

Examples::

{% ifin item item_list %}
...
{% endifin %}

{% ifnotin item item_list %}
...
{% else %}
...
{% endifnotin %}
"""
bits = list(token.split_contents())
if len(bits) != 3:
raise TemplateSyntaxError, "%r takes two arguments" % bits[0]
end_tag = 'end' + bits[0]
nodelist_true = parser.parse(('else', end_tag))
token = parser.next_token()
if token.contents == 'else':
nodelist_false = parser.parse((end_tag,))
parser.delete_first_token()
else:
nodelist_false = NodeList()
return IfInNode(bits[1], bits[2], nodelist_true, nodelist_false,
negate)

def ifin(parser, token):
return do_ifin(parser, token, False)
ifin = register.tag(ifin)

def ifnotin(parser, token):
return do_ifin(parser, token, True)
ifnotin = register.tag(ifnotin)
 END -

On Feb 2, 6:19 am, "Aidas Bendoraitis" <[EMAIL PROTECTED]>
wrote:
> I think, it's impossible to use forloop.counter0 as an index, because
> array.forloop already searches for array['forloop'], array[forloop],
> array.forloop, and similar combinations which don't exist. But maybe
> you could zip(items, array) in the view or merge items and array in
> some other way and to get all the necessary values from that merged
> list.
>
> Good luck!
> Aidas Bendoraitis aka Archatas
>
> On 2/1/07, Brandon Warren <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello,
>
> > Is it possible to use forloop.counter0 as an index into a list?
>
> > For example:
>
> > in my view I have:
>
> > array=[10,11,12,13]
>
> > in my template I have:
>
> > {% for item in items %}
> > counter = {{ forloop.counter0 }}
> > 1st val of array = {{ array.0 }}
> > nothing appears here: {{array.forloop.counter0 }}
> > ---
> > {% endfor %}
>
> > This is what comes out the browser:
> > counter = 0
> > 1st val of array = 10
> > nothing appears here:
> > ---
> > counter = 1
> > 1st val of array = 10
> > nothing appears here:
> > ---
>
> > Thanks in advance,
> > Brandon


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to make a list of allowable arguments for filter()

2007-02-09 Thread abe

sorry for the previous post. accidentally pressed send too early.

I can find the models which have a certain model as a ForeignKey like
this

modl=models.get_model('myapp','model1')

relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
  for m in modl._meta.get_all_related_objects()
  for f in m.model._meta.fields ]

relfieldargs
Out[  ]:
['relmodl2__id',
 'relmodl2__name',
 'relmodl2__foo',
 etc.
 ]

where {relmodl2__name:value} etc can be use as argument
to modl.objects.filter(...)

this works if model Relmodl2 has model2 as ForeignKey
but not the other way round. is there an eay way to find
those model and field names?

for example  relmodl2.objects.filter({'model1__nr__gt':5})

where I'm looking for the other allowed strings like  'model1__nr'


or is there an alltogether easier way to do this.


thanks-abe


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to make a list of allowable arguments for filter()

2007-02-09 Thread abe

I can find the models which have a certain model as a ForeignKey like
this


relfieldargs = ['%s__%s' % (m.model._meta.module_name,f.name)
for m in
models.get_model('zb','compound')._meta.get_all_related_objects() for
f in m.model._meta.fields]


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problems with low level caching and locmem backend

2007-02-09 Thread Russell Keith-Magee

On 2/9/07, Lawrence Oluyede <[EMAIL PROTECTED]> wrote:

> I'm not sure if it's right to post this also to the developer list
> because I'm not sure it's a Django problem.

In the future, please don't cross post. If you're unsure, ask on the
users list first. The developers all read the users list too, so they
will see your question. The discussion will get moved to the
developers list if and when your problem raises an internal design
issue that requires discussion.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing maxlength html attribute

2007-02-09 Thread [EMAIL PROTECTED]

If you're having user registration, I think you're quickly going to
want more than the builtin auth/user will give you.
I'd take a look at extending the user model:
http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model

Also, I'm not sure why it's giving you a maxlength of 30. In my
database, email is 75 characters, and I don't recall changing that.

On Feb 9, 4:56 pm, "Milan Andric" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm using contrib/auth User for my registration process like alot of
> folks but the maxlength attr on the html form for the email is 30 and
> that's too short.
>
> I tried modifying contrib/auth/models.py and adding maxlength to
> User.email but that doesn't seem to affect the form.
>
> So I need to subclass the email form?  Where is that located?  Any
> hints on a good way to do this?
>
> --
> Milan


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



changing maxlength html attribute

2007-02-09 Thread Milan Andric

Hello,

I'm using contrib/auth User for my registration process like alot of
folks but the maxlength attr on the html form for the email is 30 and
that's too short.

I tried modifying contrib/auth/models.py and adding maxlength to
User.email but that doesn't seem to affect the form.

So I need to subclass the email form?  Where is that located?  Any
hints on a good way to do this?

--
Milan


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do you pass a variable to a template tag?

2007-02-09 Thread [EMAIL PROTECTED]

I need to pass a user id to a template tag.
After reading this: http://groups.google.com/group/django-users/
browse_thread/thread/96fe34b4561415dc/b7aba25f22bdd261?
lnk=gst=template+tags+variable=1#b7aba25f22bdd261

I came up with:

class SongListNode(template.Node):
def __init__(self, artist, varname):
self.artist, self.varname  = artist, varname

def __repr__(self):
return ""

def render(self, context):
artist=self.artist.resolve(context)
context[self.varname] = Song.objects.filter(artist=artist)
#context[self.varname] = [self.artist]
return ''

class DoGetSongList:
"""
{% get_song_list as song_list %}
"""
def __init__(self, tag_name):
self.tag_name = tag_name

def __call__(self, parser, token):
bits = token.contents.split()
if len(bits) != 4:
raise template.TemplateSyntaxError, "'%s' tag takes three
arguments" % bits[0]
if bits[2] != "as":
raise template.TemplateSyntaxError, "second argument to
'%s' tag must be 'as'" % bits[0]
#return SongListNode(bits[1], bits[3])
return SongListNode(parser.compile_filter(bits[0]), bits[3])
register.tag('get_song_list', DoGetSongList('get_song_list'))


But no love. Suggestions?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Should newforms security fixes be posted to django-announce?

2007-02-09 Thread [EMAIL PROTECTED]


I agree it should be reported. For several reasons such as active
users of SVN code (particularly since it is recommended). Also, it's
better IMO to start now so ti is developed as the proper habit for
when it is "release" code that would "normally" be reported to the
list.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Derek Lee-Wo

The app I have is pretty simply as I'm just beginning so I didn't
bother to try and make it any smaller.  I've ZIPped the entire project
directory and it can be downloaded here:

http://www.roadtoboston.com/media/RoadToBoston.zip

I have a batch file called runserver.cmd that would run the local test
server.  It sets the PYTHONPATH to include reportlab which I'm using
(and is also incuded in the ZIP file).  Django is it my site-packages.

The top directory has an SQL file called roadtoboston_test.sql that
you can use to recreate my data.  I removed my MySQL database
credentials from the settings.py file

If you do manage to get it running, the URL:

http://localhost:8080/trainingPlans/viewPlan/1/

will take you to a page that takes anywhere from 17-19 seconds to render.

I'm running this in an Athlon X2 4600+ so it's a fast machine.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Malcolm Tredinnick

On Fri, 2007-02-09 at 16:06 -0600, Derek Lee-Wo wrote:
> > It may take a couple more days to work this out. It's only been 48 hours
> > since you posted the original problem and less than 24 hours since you
> > posted a portion of your code that causes the problem. It is very
> > unusual behaviour for Django; the templating code is normally very fast,
> > but this isn't a trivial thing to work out.
> >
> > Anybody working on this problem (including me), has to work up the
> > necessary wrapper code to try and replicate the problem and create some
> > test data and hope we see the same thing. If we don't, we have to bounce
> > it back to you to get some more information. So understand that this can
> 
> I'm sorry if I offended anyone by my post about trying another
> template engine.  

Don't worry. You didn't offend anybody (at least not me). I was just
trying to set some expectations about how fast you might expect a
solution (you got some quick responses, but not full solution). If you
want to move to another system, that really isn't going to bother
anybody either, but I was trying to suggest that then you have to learn
two new things and the time invested might match the time required to
see if we can unravel this one.

> I certainly wasn't expecting that anyone was going
> to spend a whole lot of time trying to figure out if I was doing
> something wrong, or if there was some kind of Django issue.
> 
> My original post was to really geared to finding any resources that
> might give some best-practice guidelines  Barring that, I was really
> only hoping for any quick or easy suggestions others may have.

We don't really have any guidelines like that because "do the obvious"
generally works very well. It really is surprising that you're seeing
this sort of behaviour and I'm sure I'm not the only person who read
your mail, sat up and thought "that looks very odd".

[...]
> Now that I'm aware that others are actually trying to reproduce my
> problem, I'll stick with it for now and also try and do some more
> digging on my own.

Anything you can do to reduce your code to a small example that exhibits
the same behaviour would definitely make things easier. Failing that,
the code you have now is a good substitute (we can untangle most things
with enough effort). Looking at the views.py file you provided earlier,
it looks like you are on the right track with inserting the timing
statements to split up the work, but it's not quite obvious where the
time is going yet. So if we have something we can replicate and then
pull on the strings to see what happens, that will be great.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Jeremy Dunck

On 2/9/07, Derek Lee-Wo <[EMAIL PROTECTED]> wrote:
...
> My original post was to really geared to finding any resources that
> might give some best-practice guidelines  Barring that, I was really
> only hoping for any quick or easy suggestions others may have.

In general, Django templating is very fast, and you're not doing
anything silly as far as I can see from the partial code available.
But yeah, we'd like to figure it out to see what needs to be improved.
 Perhaps you will teach us some best practices.  ;-)

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Derek Lee-Wo

> It may take a couple more days to work this out. It's only been 48 hours
> since you posted the original problem and less than 24 hours since you
> posted a portion of your code that causes the problem. It is very
> unusual behaviour for Django; the templating code is normally very fast,
> but this isn't a trivial thing to work out.
>
> Anybody working on this problem (including me), has to work up the
> necessary wrapper code to try and replicate the problem and create some
> test data and hope we see the same thing. If we don't, we have to bounce
> it back to you to get some more information. So understand that this can

I'm sorry if I offended anyone by my post about trying another
template engine.  I certainly wasn't expecting that anyone was going
to spend a whole lot of time trying to figure out if I was doing
something wrong, or if there was some kind of Django issue.

My original post was to really geared to finding any resources that
might give some best-practice guidelines  Barring that, I was really
only hoping for any quick or easy suggestions others may have.

Since no quick suggestions were forthcoming (I still have to look into
the issue mentioned by Karen Tracey) I was going to simply move on to
find the best solution for me.

Now that I'm aware that others are actually trying to reproduce my
problem, I'll stick with it for now and also try and do some more
digging on my own.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Derek Lee-Wo

I'll put together a zip file of my entire project directory along with
a MySQL dump of the test data I have.  That way, it should be easy for
anyone to play around with it.  I'll try do that later this evening


On 2/9/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>
> On Thu, 2007-02-08 at 20:21 -0600, Derek Lee-Wo wrote:
> > > One more idea: It looks like you're doing foreign-key lookups in the 
> > > rendering.
> > >
> > > {% for workoutWeek in workoutWeeks %}
> > > ...
> > > {% for workoutDay in workoutWeek.workouts %}
> >
> > workoutWeek isn't a table, but I'm pretty sure all my DB queries are
> > done by the time I go to render, but I could be wrong.  I've only been
> > using Django for a week now.
> >
> > > ... Of course, if you shared your view and original template, it'd be
> > > easier to help.  The template you included at the start of the thread
> > > was inline, which was garbled...
> >
> > I've attached a zip file of the template and the view.py file.  The
> > main method is __viewPlan() which starts at line 51
>
> Could you also please post the models you are using and the
> trainingplan_extras custom tags/filters, just in case they have any
> effect on things. It isn't possible to replicate the problem with the
> information you have provided so far.
>
> Thanks,
> Malcolm
>
>
>
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Malcolm Tredinnick

On Thu, 2007-02-08 at 20:21 -0600, Derek Lee-Wo wrote:
> > One more idea: It looks like you're doing foreign-key lookups in the 
> > rendering.
> >
> > {% for workoutWeek in workoutWeeks %}
> > ...
> > {% for workoutDay in workoutWeek.workouts %}
> 
> workoutWeek isn't a table, but I'm pretty sure all my DB queries are
> done by the time I go to render, but I could be wrong.  I've only been
> using Django for a week now.
> 
> > ... Of course, if you shared your view and original template, it'd be
> > easier to help.  The template you included at the start of the thread
> > was inline, which was garbled...
> 
> I've attached a zip file of the template and the view.py file.  The
> main method is __viewPlan() which starts at line 51

Could you also please post the models you are using and the
trainingplan_extras custom tags/filters, just in case they have any
effect on things. It isn't possible to replicate the problem with the
information you have provided so far.

Thanks,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Malcolm Tredinnick

On Fri, 2007-02-09 at 13:41 -0600, Derek Lee-Wo wrote:
> I incorporated ReportLib to generate a PDF of the same data that I'm
> trying to display on the web and the PDF gets created in about 2
> seconds as compared to the template via Django which is taking 16-18
> seconds.
> 
> Both routines share a common method that does all the data retrieval
> and manipulation before generating the output so I know the database
> and SQL is not a factor.
> 
> This is turning out to be very distressing.  I'm starting to look at
> other template options.  I may give Cheetah a try this weekend.

It may take a couple more days to work this out. It's only been 48 hours
since you posted the original problem and less than 24 hours since you
posted a portion of your code that causes the problem. It is very
unusual behaviour for Django; the templating code is normally very fast,
but this isn't a trivial thing to work out.

Anybody working on this problem (including me), has to work up the
necessary wrapper code to try and replicate the problem and create some
test data and hope we see the same thing. If we don't, we have to bounce
it back to you to get some more information. So understand that this can
take some time. I didn't have time to do that work during the week; I'm
hoping I might have time this weekend, since it is a problem worth
looking at and understanding.

If you were able to reduce your problem to a self-contained working
example, that would help a lot. How much can you remove from the
template before the problem goes away (i.e. are the for-loops the only
critical piece)? How small can the data set be before there is a major
change (does the time taken vary proportionally to the size of the data
or is there a catastrophic increase at some point)? 84 rows of data is
basically nothing, so that shouldn't have any effect, but it would be
interesting to check.

So if you really want to learn a new templating language, obviously go
for it. But it may be a reasonable option to just hang out for another
couple of days and give us a chance to look at the problem and get back
to you with any queries. Hard stuff sometimes takes some time to work
out.

Best wishes,
Malcolm


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Karen Tracey

At 02:41 PM 2/9/2007, you wrote:
>This is turning out to be very distressing.  I'm starting to look at
>other template options.  I may give Cheetah a try this weekend.

I'm not surprised you are considering alternatives, 16-18 seconds is 
an unacceptable amount of time for template rendering.  Did you 
verify that you are running with the fix for #3441?  I think you need 
to be at SVN revision 4461 or higher.  While #3441 sounds like a 
minor issue, when I hit it it had a huge impact due to the contents 
of my template context; there was a tremendous amount of work being 
done to build a humongous error string that was simply tossed away by 
the calling code.

Of course this may not be the problem that is causing your excessive 
times.  If it isn't I'm convinced it must be something similar, 
because I can't believe what you are seeing is expected.  It would be 
good for Django if we could track down what is going on.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Derek Lee-Wo

I incorporated ReportLib to generate a PDF of the same data that I'm
trying to display on the web and the PDF gets created in about 2
seconds as compared to the template via Django which is taking 16-18
seconds.

Both routines share a common method that does all the data retrieval
and manipulation before generating the output so I know the database
and SQL is not a factor.

This is turning out to be very distressing.  I'm starting to look at
other template options.  I may give Cheetah a try this weekend.

Derek

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



Re: Easy way to determine runtime environment?

2007-02-09 Thread Mike

Hello,

> Is there an easy way to adjust the media location based on the
> server environment?

Perhaps the following link will help. Check out the code from Mikko
Ohtamaa in the Comments section.

http://www.djangoproject.com/documentation/modpython/


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Easy way to determine runtime environment?

2007-02-09 Thread Tim Chase

I'm trying to find an easy way to check what the current runtime
environment is.  I deploy to mod_python, but do development
against runserver.  I'd like my settings.py file to tweak the
media settings based on whether I'm using mod_python (in which
case, it should use the ones I have working there) or if I'm
running the development server (in which case I want it to point
to my local repository's media directory).

Is there an easy way to adjust the media location based on the
server environment?

Thanks,

-tkc






--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best Practices for faster template rendering

2007-02-09 Thread Karen Tracey
This is a total shot in the dark but are you running with the fix for ticket
#3441?  If your template does anything to cause VariableDoesNotExist to be
raised during rendering, #3441 might apply.  Without the fix the entire
contents of your context is repr'd to build the exception message that is
then most likely thrown away.  With the fix the message is only built if the
exception message is actually needed.  The fix was made in the last few
days.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Shuffled Model selection

2007-02-09 Thread Kai Kuehne

Hi

On 2/9/07, Brett Parker <[EMAIL PROTECTED]> wrote:
> Err, why not use a random sort as...
>
> Obj.objects.order_by('?')
>
> ref: http://www.djangoproject.com/documentation/db_api/#order-by-fields

Becasue I didn't know it (a good reason, I think).

> Cheers,

Thanks Brett!
Kai

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Shuffled Model selection

2007-02-09 Thread Brett Parker

On Fri, Feb 09, 2007 at 03:11:57PM +0100, Kai Kuehne wrote:
> 
> Hey!
> I wanted to select all models, but in random order:
> 
> random.shuffle(Obj.objects.all())
> 
> This doesn't work, error message:
> 
> TypeError: object does not support item assignment

Err, why not use a random sort as...

Obj.objects.order_by('?')

ref: http://www.djangoproject.com/documentation/db_api/#order-by-fields

That way you don't use all the memory in the world, and you're letting
the database deal with the sorting.

Cheers,
-- 
Brett Parker

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Problems with low level caching and locmem backend

2007-02-09 Thread Lawrence Oluyede

I'm trying to put in the cache a simple Python list made of unicode
strings. The strange thing is locmem crashes badly during the first
retrieval of a cache hit. The same code with the simple backend is
like a breeze.

I looked into locmem.py and simple.py backends and as the traceback
states the problem seems to be locmem's get() which uses
copy.deepcopy() to avoid aliasing (see
http://code.djangoproject.com/ticket/599).

The whole thing seems a little wierd to me because I know deepcopy()
can handle a simple list made of unicode strings. I also tried to
print verbatim the content of the cache before the crash and there's
nothing strange in there.

The full traceback is here: http://dpaste.com/hold/5482/

I also found this ticket: http://code.djangoproject.com/ticket/3012
Basically the person wants to revert #599

I'm not sure if it's right to post this also to the developer list
because I'm not sure it's a Django problem.

I'm using Python 2.5 and Django SVN in development mode, by the way.

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Shuffled Model selection

2007-02-09 Thread Kai Kuehne

Sorry, I got it:
all = Obj.objects.all()
newlist = [x for x in all]
random.shuffle(newlist)

Not that beautiful, but it works. :)

Greetings
Kai

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Shuffled Model selection

2007-02-09 Thread Kai Kuehne

Hey!
I wanted to select all models, but in random order:

random.shuffle(Obj.objects.all())

This doesn't work, error message:

TypeError: object does not support item assignment


Anyony an idea in how to make it?
(It's for a blogroll, if you wonder where it could be used.)

Greetings :)
Kai

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Manoj Govindan


> the session information from the database, and you query the wrapper
> for individual session data.
>
> Does this help explain the process?
>

It certainly does.
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Russell Keith-Magee

On 2/9/07, Manoj  Govindan <[EMAIL PROTECTED]> wrote:
>
> Apologies for the flurry of messages.
> I just wanted to note that this worked:
>
> session =
> SessionWrapper( self.client.cookie.get( 'sessionid' ).value  )
>
> The above fragment returned me the session from the db that I was
> looking for.
> I am still confused. Russell, can I persuade you to explain what is
> going on here? :)

self.client.cookie (renamed to cookies in [4464]) is a SimpleCookie
object; this object wraps the ability to easily create HTTP headers
out of a cookie. You need to get the value attribute of the cookie to
return just the value of the session cookie, rather than the full
header information. That value, which is the session id stored as a
cookie, is passed to instantiate the SessionWrapper. SessionWrapper is
essentially a dictionary-like wrapper around Session.objects.get().
The session id instantiates the session wrapper, loading and decoding
the session information from the database, and you query the wrapper
for individual session data.

Does this help explain the process?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Russell Keith-Magee

On 2/9/07, Manoj  Govindan <[EMAIL PROTECTED]> wrote:
>
> Hi Russ,
> Thanks for your prompt reply.
>
> I tested the solution you suggested and came up with some questions.
> Here they are.
>
> > session =
> > SessionWrapper(self.cookies.get(settings.SESSION_COOKIE_NAME, None))
> > self.assertTrue(session['key'], value)
> >
>
> First of all, I could not find a SESSION_COOKIE_NAME in settings. I
> have a feeling that even though I am using a pretty recent SVN
> checkout of django, I might not have the correct settings file.

settings definitely has a SESSION_COOKIE_NAME; it may not be in your
settings file, but it will be inherited from the global default
settings. If you put

from django.conf import settings

at the top of your source file, you should have acess to
SESSION_COOKIE_NAME whether it is in your settings.py or not.

> Second, it would seem that the code fragment given above expects the
> test class to maintain a list of cookies. Pardon my ignorance, but
> should I explicitly create and maintain a list of cookies in the test
> class and use them as necessary?

Sorry - my mistake (I said I didn't run the example! :-)

You are completely correct. The client keeps track of the cookies, so
you need to use self.client.cookie.get(...)

That said - in [4464] I have checked in some changes to the test
client that automagically create the session wrapper for you. If you
update SVN, you will be able to do the following in a test case (as
long as you have the sessions middleware installed):

self.assertEqual(self.client.session['key'], value)

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Should newforms security fixes be posted to django-announce?

2007-02-09 Thread Fred

+1.

I switched halfway my first project to using newforms in new views/
forms I'm creating. The old manipulator functiosn for custom forms are
'cumbersome' to say it nicely  compared to the enlightened newforms
way of django life. :-)

Fred


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Manoj Govindan

Apologies for the flurry of messages.
I just wanted to note that this worked:

session =
SessionWrapper( self.client.cookie.get( 'sessionid' ).value  )

The above fragment returned me the session from the db that I was
looking for.
I am still confused. Russell, can I persuade you to explain what is
going on here? :)

> However this session does not have _any_ keys. I am presently checking
> my code ...


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Manoj Govindan

Addendum:
I tried the following and it did return a session.

session = SessionWrapper( self.client.cookie.get( 'id' )  )

However this session does not have _any_ keys. I am presently checking
my code ...

>
> Say something like this.
>
> session = SessionWrapper( self.client.cookie )
>


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Manoj Govindan

Hi Russ,
Thanks for your prompt reply.

I tested the solution you suggested and came up with some questions.
Here they are.

> session =
> SessionWrapper(self.cookies.get(settings.SESSION_COOKIE_NAME, None))
> self.assertTrue(session['key'], value)
>

First of all, I could not find a SESSION_COOKIE_NAME in settings. I
have a feeling that even though I am using a pretty recent SVN
checkout of django, I might not have the correct settings file.

Second, it would seem that the code fragment given above expects the
test class to maintain a list of cookies. Pardon my ignorance, but
should I explicitly create and maintain a list of cookies in the test
class and use them as necessary?
I am confused here, for as the test uses a test client, I thought the
cookie should probably come from the _client_.

Say something like this.

session = SessionWrapper( self.client.cookie )

Client does have a cookie attribute which is initialised to use a
django.http.SimpleCookie object.
Needless to say the above usage failed with a message which I thought
was aimed at me ;-)
" ProgrammingError: can't adapt "

Could you tell me what I am missing here/doing wrong?

Regards,
Manoj


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: tying custom queries back into the queryset / object model / paginator... ?

2007-02-09 Thread James Bennett

On 2/8/07, Sergey Kirillov <[EMAIL PROTECTED]> wrote:
> obj_list = klass._default_manager.in_bulk(oid_list)
>
> return [obj_list[oid] for oid in oid_list]

Just a quick note for those playing along with custom ORDER BY stuff
(e.g., ordering by a non-column value generated by another part of the
query, like a COUNT(*)):

Remember to use in_bulk or Russell's method of selecting full rows and
instantiating objects from them if you're using order_by -- you can
pass to an "id__in" lookup and get a QuerySet, but it'll usually
clobber your ordering.

-- 
"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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Admin not updating to reflect changes in database

2007-02-09 Thread James Bennett

On 2/8/07, Roboto <[EMAIL PROTECTED]> wrote:
> I've done everything (but the right thing) to try to get the admin
> interface to pick up the new charField that I've added to the class,
> but it's just not reflecting it.

Are you using a 'fields' list in your Admin class to specify which
fields it shows? And if so, did you add the new field there?

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

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



Filtering foreign items in admin

2007-02-09 Thread Rob Slotboom

For a several models I use a FK to photos. The drop down in admin to
choose from lists all photos.
Can this list be filtered so I can restrict the available photos for
some models?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Should newforms security fixes be posted to django-announce?

2007-02-09 Thread [EMAIL PROTECTED]

On Feb 9, 12:57 pm, Jon Colverson <[EMAIL PROTECTED]> wrote:

> Should newforms security fixes be posted to django-announce?

Yes +1 for this. Since basically everybody using Django on production
servers is using some svn code i believe and i'm about to do the same.

Thanks,
Lorenzo


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Should newforms security fixes be posted to django-announce?

2007-02-09 Thread Jon Colverson

Hello.

I sent a e-mail to the django security list last Friday about a XSS 
vulnerability in newforms. The bug was fixed on Monday in SVN revision 4460.

Adrian and Jacob didn't think that it was worth posting to 
django-announce about it, since it only affects newforms. The 
justification given was that newforms is mostly undocumented and 
bleeding-edge, so there won't be many people using it.

I'm disconcerted about this, because I'm planning to launch my own 
newforms-based app in a matter of weeks and I'd much rather not have to 
check the Subversion logs to find out about any security bugs.

I decided to use newforms for my project based on these two statements 
on the Django web site:

"The legacy forms/manipulators system described in this document is 
going to be replaced in the next Django release. If you're starting from 
scratch, we strongly encourage you not to waste your time learning this. 
Instead, learn and use the django.newforms system, which we have begun 
to document in the newforms documentation."

"Should I use the official version or development version?

The Django developers improve Django every day and are pretty good about 
not checking in broken code. We use the development code (from the 
Subversion repository) directly on our servers, so we consider it 
stable. With that in mind, we recommend that you use the latest 
development code, because it generally contains more features and fewer 
bugs than the "official" releases."

I wasn't able to convince the core developers that this is important, so 
I thought I'd solicit some opinions here:

Should newforms security fixes be posted to django-announce?

Thanks.

-- 
Jon

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Automated testing using Client - how to test/assert the value of session objects

2007-02-09 Thread Russell Keith-Magee

On 2/9/07, Manoj  Govindan <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I have written a small test making use of test.Client to simulate a
> 'POST' request to a view. The target view is expected to set a certain
> variable in the session on successful handling of the request. Can
> anyone suggest a suitable mechanism to check in the test if the
> session variable has been set correctly?
>

Sessions are saved in the database, so you could go straight to the
source, and pull the data from the database. However, you can cheat a
little bit and use the same infrastructure that Django uses in the
Sessions middleware:

from django.contrib.sessions.middleware import SessionWrapper

def MyTest(TestCase):
def testStuff(self):

... do stuff ...
session =
SessionWrapper(self.cookies.get(settings.SESSION_COOKIE_NAME, None))
self.assertTrue(session['key'], value)

Fair warning - I haven't tested this myself. It _should_ work. :-)

Your question does raise an interesting suggestion - the client
currently persists cookies, but it might be nice for the client to
have easy access to the session, too... The testing framework is still
under development, and we need the suggestions of people in the field
to tell us what we can do to make the test framework better.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Custom SQL - MySQL Dictcursor

2007-02-09 Thread Dirk Eschler

Hello,

is there a way to get a dictcursor from Django when using custom MySQL?

from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT [...]")
cursor.fetchall()

The above fetchall returns a tuple, while i need a dict, like it is built with 
MySQLdb.cursors.DictCursor(db).

Best Regards,
Dirk Eschler

-- 
Dirk Eschler 
http://www.krusader.org

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: possible bug when editing an object: foreign key "_id" part gone (SOLVED)

2007-02-09 Thread Benedict Verheyen

Benedict Verheyen schreef:
> Benedict Verheyen schreef:
>> Hi,
>>
>> i think i might have encountered a possible bug but i'm not sure though.
>> Editing an object and leaving a mandatory field empty results in the
>> form "forgetting" the foreign keys. It doesn't actually forget but it ommits 
>> the
>> "_id" part and thus the values are not displayed on the form.
>> The first time you edit, it works.
>>
>> I encountered it using this scenario:
>> 1. Edit object
>> 2. Delete/blank a mandatory field
>> 3. Save the object
>> 4. You get an error complaining that the field is mandatory
>>Note that the foreign key fields are now blank
>>


I found this comment
(http://www.djangoproject.com/documentation/forms/#using-the-changemanipulator)
This is exactly what happens in my code so this should solve my problem.
Thought i mention it here so other people can benefit from it.

= Quote ==
Les October 18, 2006 at 3:35 p.m.

In a Change Manipulator view we should always call
manipulator.do_html2python(new_data) before we check for errors. If
there are errors, FK and M2M field values will not be preserved when the
form reloads with the errors. Only data that is not populated from
external relationships will be maintained

BAD example:
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data) #BAD!!!
manipulator.save(new_data)

# Do a post-after-redirect so that reload works, etc.
return HttpResponseRedirect("/places/edit/%i/" % place.id)

GOOD example:
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data) #GOOD!!!
if not errors:
manipulator.save(new_data)

# Do a post-after-redirect so that reload works, etc.
return HttpResponseRedirect("/places/edit/%i/" % place.id)

= End Quote ==


Regards,
Benedict


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



custom validator or other way to avoid double bed bookings

2007-02-09 Thread Benedict Verheyen

Hi,

my app is used to manage patients of a ward in a hospital.
This ward has a number of beds available.
A patient has a room id referring to the room/bed where he's laying.

Now i would want to avoid being able to select a bed that is already in use.
I thought of using my own validator.
So ideally i would like to keep all fields and just change the room
field instead of defining them all.

I didn't find a clear way of only changing one field without
specifying them all.
I hacked it by first looking up the index of the field in the fields list
and replacing it with my own version:
fields[index] = forms.SelectField(field_name="room", choices =
room_choices, validator_list=[room_validator])

room_choices is simply a list of all the rooms and room_validator is
my room validator.
The problem i'm having with this approach is that the current room
isn't preselected in the dropdown list when i change the patient data.
Could be expected when you make your own.

How can i specify a selected room in forms.SelectField or is there
another way to make sure a user can't assign a bed that is already in
use?

Thanks,
Benedict

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---