Prefetch user profiles

2009-07-27 Thread Andrew Fong

Hi all,

I'm using contrib.auth and have set up my own Profile model, linked to
the User model with OneToOneField. There are a lot of times when I'd
like to prefetch the Profile model when getting the User model -- e.g.
User.objects.all().select_related('profile')

However, select_related does not seem to follow the OneToOneField back
to the User though. It appears to be a one-way relationship. Does
anyone have any ideas on how to make this happen short of directly
modifying the User model in contrib.auth?

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



Re: TransactionMiddleware not working

2009-07-21 Thread Andrew Fong

Just double checking, but are you using a DB that supports
transactions?

On Jul 21, 8:16 am, Parag Shah  wrote:
> Hello,
>
> Hello,
>
> I am using TransactionMiddleware to get per request transactions working in
> my Django project. However, it does not seem to be working.
>
> I have a view in which I save an object and when I try to save a related
> object there is an Exception. However, the first object is still saved.
> Please find my code at:http://pastebin.com/f5b498b16
>
> The topic_add(...) method is a view method which results in adding 3 rows
> when a topic is added to a course:
> 1. Add the topic to the courses_topic table
> 2. Add a row to the courses_topic_courses table (because there is a
> many-to-many relationship between Topic and Course)
> 3. Add a row to the courses_topicorder table
>
> I deliberately introduced an error before step 3, yet step 1 and 2 were
> carried out successfully.
>
> Any help is appreciated.
>
> --
> Thanks & Regards
> Parag Shah
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django site on Apache

2009-07-21 Thread Andrew Fong

The documentation is distribution agnostic, so I'm not sure what
you're referring to. It sounds as if you just dropped a Django project
into /var/www and expected it to work. Unfortunately, Django is not
PHP. I'm going to assume you're unfamiliar with how Django works, so
apologies if you already read this, but I recommend starting here.

http://www.djangobook.com/en/2.0/chapter02/

And then reading the chapter on deployment here:

http://www.djangobook.com/en/2.0/chapter12/


-- Andrew



On Jul 21, 9:19 am, Kannan  wrote:
> >Only you can help yourself, and you do that by reading the
> >documentation:
> >http://docs.djangoproject.com/en/dev/howto/deployment/
>
>         I read the documentation of that and configure  all the settings.
> that settings work in Fedora 10 but not work in Debian Lenny.
> help me
>
> With regards,
>
> Kannan. R. P,
>
> On Tue, Jul 21, 2009 at 6:06 PM, Daniel Roseman wrote:
>
>
>
>
>
> > On Jul 21, 12:16 pm, Kannan  wrote:
> > > Hi friends...
> > >              I have downloaded the source of thehttp://
> > in.pycon.org/2009/fromherehttp://bitbucket.org/lawgon/fossconf/downloads/.
> > > I try to run the site in my Apache server.
> > > So i copy the extracted file to my /var/www/ directory named fossconf.
>
> > > My apache2 conf file is herehttp://dpaste.com/69137/
>
> > > when i try the urlhttp://localhost/fossconf/it gives error that "cannot
> > > import the settings [Is this is in system path?"
>
> > > Help me to solve this error.
>
> > > With regards,
>
> > > Kannan. R. P,
>
> > Only you can help yourself, and you do that by reading the
> > documentation:
> >http://docs.djangoproject.com/en/dev/howto/deployment/
> > --
> > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How I run background processes

2009-07-21 Thread Andrew Fong

>> I was worried by potential caching issues with the database that
>> may prevent my cron script to retrieve the latest boolean value.

It sounds as if you're worried about a race condition when scale up --
e.g. let's say you need to run a lot of background processes and
decide to split them up among several machines, each with their own
cron jobs. If Machine A's cron job and Machine B's cron job both check
the database at the same time, they'll both see that the process isn't
running and start it up -- resulting in two copies of the process
instead of just one.

Am I correct in saying that's what you're concerned about?

If so, a simple solution would be to just wrap that part of the code
in a transaction. This will ensure Machine B doesn't get a response
back from the database until Machine A finishes updating it.

Aside from that, this seems fine.

-- Andrew

On Jul 21, 9:10 am, Philippe Josse  wrote:
> Hi there,
>
> I would like to have your feedback on the way I am running daemon scripts
> for my Django/ Python app. I know this is definitely not the "one best way",
> but this is a solution I came up with that seemed simple to implement. (I am
> a real newbie!)
>
> My constraints:
>  - getting a few processs constantly repeating themselves
>  - getting an email notification if one of the process crashes
>
> I set up a cron job that is launching a "daemon manager" script every
> minute. This script is querying a PostGreSQL database to retrieve boolean
> values associated to the state of my background processes (running / not
> running).  If the database indicates the process is not running, then the
> cron script launches it.
>
> Boolean values are updated by each process when it starts and finishes.
> Currently, it seems to work fine - but my background processes are very
> quick to execute. When my user base will grow, they may last longer and it
> will be essential that background processes do not run concurrently.
>
> Would that solution work? I was worried by potential caching issues with the
> database that may prevent my cron script to retrieve the latest boolean
> value. Is there any real risk?
>
> Thanks for your feedback!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django charset problem

2009-07-20 Thread Andrew Fong

Well, you already set the character set correctly on the database, so
thing should just work now. If it's not, you probably just need to
restart MySQL. Lemme know if you're still having trouble.

-- Andrew

On Jul 20, 6:58 pm, Larry <yuelizh...@gmail.com> wrote:
> Hi Andrew,
>
> Thank you very much. I have changed the settings as you said.
> Just one more question: for the tables and databases that I already
> have,
> is there any way in which I can make changes in place so that things
> will look right? I want to do this because the tables I have are quite
> large
> and it will take a long time to recreate and reload them.
>
> Thanks!!
> -Larry
>
> On Jul 20, 10:58 am, Andrew Fong <fongand...@gmail.com> wrote:
>
>
>
> > Yeah, that output doesn't look correct. You're getting back two
> > characters for ø when there should be just one.
>
> > One possibility is that while you've set up the database server to
> > store things as utf8, the client hasn't been set to read them. You can
> > do this manually from the client, but if you have no need for any
> > other encoding, you should probably just edit the my.cnf and have it
> > use utf8 as the default for everything.
>
> > Relevant code 
> > here:http://andrewfong.wordpress.com/2009/06/07/utf8-unicode-in-mysql/
>
> > -- Andrew
>
> > On Jul 20, 10:25 am,Larry<yuelizh...@gmail.com> wrote:
>
> > > HI Andrew,
>
> > > Thanks for your reply. I tried it via Django's shell, one message
> > > which
> > > appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
> > > in the
> > > Django shell. Is this normal or there is already something wrong?
>
> > > The way I configure MySQL is that I use some parameters when creating
> > > the
> > > database, like this
>
> > > create database db_name default character set utf8 collate
> > > utf8_general_ci;
>
> > > I haven't changed the my.cnf file, could you tell me which is the best
> > > way to
> > > configure the MySQL or Django?
>
> > > Thanks a lot!
> > > -Larry
>
> > > On Jul 17, 5:43 pm, Andrew Fong <fongand...@gmail.com> wrote:
>
> > > > Try fetching the data via Django's shell. What do you get then?
>
> > > > Also, how did you configure MySQL to work with UTF-8? Did you modify
> > > > your my.cnf file so UTF-8 is the default? Or did you change your
> > > > database's settings manually? Or something else?
>
> > > > -- Andrew
>
> > > > On Jul 17, 5:33 pm,Larry<yuelizh...@gmail.com> wrote:
>
> > > > > Hi,
>
> > > > > I have a database with messages stored and utf-8 encoded. The messages
> > > > > look OK in the database, i.e, when I am in MySQL client the messages
> > > > > with special characters (e.g., Korean) are correctly displayed.
> > > > > However, in the web page, the special characters become
> > > > > irrecognizable, like this
>
> > > > > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > > > > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > > > > I read the django documentation it says django handles the coding
> > > > > automatically, but apparently this is not the case. Could anyone tell
> > > > > me what could wrong, is it the problem of the database of the django
> > > > > setting or other problem?
>
> > > > > Any help would be appreciated. Thanks in advance.
> > > > > -Larry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django charset problem

2009-07-20 Thread Andrew Fong

Yeah, that output doesn't look correct. You're getting back two
characters for ø when there should be just one.

One possibility is that while you've set up the database server to
store things as utf8, the client hasn't been set to read them. You can
do this manually from the client, but if you have no need for any
other encoding, you should probably just edit the my.cnf and have it
use utf8 as the default for everything.

Relevant code here: 
http://andrewfong.wordpress.com/2009/06/07/utf8-unicode-in-mysql/

-- Andrew

On Jul 20, 10:25 am, Larry <yuelizh...@gmail.com> wrote:
> HI Andrew,
>
> Thanks for your reply. I tried it via Django's shell, one message
> which
> appears "Isbjørn" in the MySQL client is displayed as "Isbj\xc3\xb8rn"
> in the
> Django shell. Is this normal or there is already something wrong?
>
> The way I configure MySQL is that I use some parameters when creating
> the
> database, like this
>
> create database db_name default character set utf8 collate
> utf8_general_ci;
>
> I haven't changed the my.cnf file, could you tell me which is the best
> way to
> configure the MySQL or Django?
>
> Thanks a lot!
> -Larry
>
> On Jul 17, 5:43 pm, Andrew Fong <fongand...@gmail.com> wrote:
>
>
>
> > Try fetching the data via Django's shell. What do you get then?
>
> > Also, how did you configure MySQL to work with UTF-8? Did you modify
> > your my.cnf file so UTF-8 is the default? Or did you change your
> > database's settings manually? Or something else?
>
> > -- Andrew
>
> > On Jul 17, 5:33 pm,Larry<yuelizh...@gmail.com> wrote:
>
> > > Hi,
>
> > > I have a database with messages stored and utf-8 encoded. The messages
> > > look OK in the database, i.e, when I am in MySQL client the messages
> > > with special characters (e.g., Korean) are correctly displayed.
> > > However, in the web page, the special characters become
> > > irrecognizable, like this
>
> > > ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> > > €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> > > I read the django documentation it says django handles the coding
> > > automatically, but apparently this is not the case. Could anyone tell
> > > me what could wrong, is it the problem of the database of the django
> > > setting or other problem?
>
> > > Any help would be appreciated. Thanks in advance.
> > > -Larry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

Unfortunately, it looks the aggregation / sum stuff is in the SVN
version only for now.

I'm not aware of any other way to do this with the Django 1.0 ORM
though. As a fallback, you could rely on raw SQL I suppose.
http://docs.djangoproject.com/en/1.0/topics/db/sql/

Sorry I couldn't be more helpful here.

-- Andrew

On Jul 20, 10:30 am, The Danny Bos <danny...@gmail.com> wrote:
> I'm not able to use anything over Django 1.0.2.
> Does SUM work for this version, I'm getting the error:
>
> Could not import #.views. Error was: cannot import name Sum
>
> Is there another way around this?
> Thanks for your time and energy guys,
>
> d
>
> On Jul 21, 12:22 am, Andrew Fong <fongand...@gmail.com> wrote:
>
>
>
> > The relevant documentation btw:
>
> >http://docs.djangoproject.com/en/dev/topics/db/aggregation/http://doc..
>
> > On Jul 20, 10:18 am, Andrew Fong <fongand...@gmail.com> wrote:
>
> > > Assuming your models are like this:
>
> > > class Book(models.Model):
> > >     name = models.CharField(max_length=128)
>
> > > class User(models.Model):
> > >     is_staff = models.BooleanField(default=False)
>
> > > class Rating(models.Model):
> > >     user = models.ForeignKey(User)
> > >     score = models.IntegerField(default=3)
> > >     book = models.ForeignKey(Book)
>
> > > Try this:
>
> > > from django.db.models import Sum
> > > Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> > > ('rating__score')).order_by('-score')[0:10]
>
> > > -- Andrew
>
> > > On Jul 20, 9:22 am, The Danny Bos <danny...@gmail.com> wrote:
>
> > > > Hey there,
>
> > > > I'm looking at getting a Top 10 of all Books on a site, but only where
> > > > rated by users of a certain Group.
> > > > Here's what I've got so far:
>
> > > >         book = Book.objects.all()
>
> > > > Somewhat impressive, hey?
>
> > > >  - So, my tables/models are Book, Rating, User.
> > > >  - I save all ratings in Rating like so "rating | user | book"
> > > >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > > > Hope that helps,
> > > > I'm really stuck on how to get this moving.
>
> > > > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

The relevant documentation btw:

http://docs.djangoproject.com/en/dev/topics/db/aggregation/
http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

On Jul 20, 10:18 am, Andrew Fong <fongand...@gmail.com> wrote:
> Assuming your models are like this:
>
> class Book(models.Model):
>     name = models.CharField(max_length=128)
>
> class User(models.Model):
>     is_staff = models.BooleanField(default=False)
>
> class Rating(models.Model):
>     user = models.ForeignKey(User)
>     score = models.IntegerField(default=3)
>     book = models.ForeignKey(Book)
>
> Try this:
>
> from django.db.models import Sum
> Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
> ('rating__score')).order_by('-score')[0:10]
>
> -- Andrew
>
> On Jul 20, 9:22 am, The Danny Bos <danny...@gmail.com> wrote:
>
>
>
> > Hey there,
>
> > I'm looking at getting a Top 10 of all Books on a site, but only where
> > rated by users of a certain Group.
> > Here's what I've got so far:
>
> >         book = Book.objects.all()
>
> > Somewhat impressive, hey?
>
> >  - So, my tables/models are Book, Rating, User.
> >  - I save all ratings in Rating like so "rating | user | book"
> >  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> > Hope that helps,
> > I'm really stuck on how to get this moving.
>
> > d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get Top 10 Books by Rating and User

2009-07-20 Thread Andrew Fong

Assuming your models are like this:

class Book(models.Model):
name = models.CharField(max_length=128)

class User(models.Model):
is_staff = models.BooleanField(default=False)

class Rating(models.Model):
user = models.ForeignKey(User)
score = models.IntegerField(default=3)
book = models.ForeignKey(Book)


Try this:

from django.db.models import Sum
Book.objects.filter(rating__user__is_staff=True).annotate(score=Sum
('rating__score')).order_by('-score')[0:10]

-- Andrew

On Jul 20, 9:22 am, The Danny Bos  wrote:
> Hey there,
>
> I'm looking at getting a Top 10 of all Books on a site, but only where
> rated by users of a certain Group.
> Here's what I've got so far:
>
>         book = Book.objects.all()
>
> Somewhat impressive, hey?
>
>  - So, my tables/models are Book, Rating, User.
>  - I save all ratings in Rating like so "rating | user | book"
>  - I'd just like the Top 10 as rated by users in the group "Staff".
>
> Hope that helps,
> I'm really stuck on how to get this moving.
>
> d
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Flushing the cache during testing

2009-07-17 Thread Andrew Fong

I'm playing around with some low-level caching of model instances.
During testing, it's necessary for me to flush out the cache so cached
whatnot from one test doesn't pollute another.

To my knowledge, Django's currently doesn't offer support for
resetting the cache after each testcase in the same way it does for
the test database (via the custom testcase class).

The options I'm looking at:
> Manually (re)starting a separate cache process
> Adding a prefix to my cache keys and changing them for each test case

Ideally, I'd just like to flush the cache but after poking around in
Django's caching code, I haven't seen any explicit support for
flushing. Does anyone have any ideas?

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



Re: Django charset problem

2009-07-17 Thread Andrew Fong

Try fetching the data via Django's shell. What do you get then?

Also, how did you configure MySQL to work with UTF-8? Did you modify
your my.cnf file so UTF-8 is the default? Or did you change your
database's settings manually? Or something else?

-- Andrew

On Jul 17, 5:33 pm, Larry  wrote:
> Hi,
>
> I have a database with messages stored and utf-8 encoded. The messages
> look OK in the database, i.e, when I am in MySQL client the messages
> with special characters (e.g., Korean) are correctly displayed.
> However, in the web page, the special characters become
> irrecognizable, like this
>
> ã‚°ãƒ¼ã‚°ãƒ«ã ®æœ€æ–°ã ®ãƒ‡ãƒ¼ã‚¿ã‚»ãƒ³ã‚¿ãƒ¼ã ¯é žå¸¸è­˜ã ªã »ã ©é
> €²åŒ–㠗㠦㠄る ï¼  Blog on Publickey
>
> I read the django documentation it says django handles the coding
> automatically, but apparently this is not the case. Could anyone tell
> me what could wrong, is it the problem of the database of the django
> setting or other problem?
>
> Any help would be appreciated. Thanks in advance.
> -Larry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: using domain name as parameter..

2009-07-07 Thread Andrew Fong

request.get_host()

On Jul 7, 9:42 am, Mirat Can Bayrak  wrote:
> i am building a site that like  blogger.com i mean i have to use subdomains 
> as parameters :\ Is there any docs about django about doing this? or any 
> ideas? thank you very much.
>
> --
> Mirat Can Bayrak 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic views problem

2009-07-07 Thread Andrew Fong

Do you have any Poll objects in the database? If not, add some using
the admin interface.

Assuming you do however, can we see your index view function? The one
from step 3 of the tutorial under "Write views that actually do
something".

-- Andrew

On Jul 7, 6:39 am, "Owen Jeremiah"  wrote:
> I'm following the tutorial from django documentation and got to part 4 about 
> generic views. But I can't get the Poll objects in my dictionary, and the 
> result is 'No polls are available.'
>
> I'm running this in Ubuntu 9.04 with Python 2.6 and Django 1.0.2 installed. I 
> would appreciate it if somebody can point me into the right direction.
>
> TIA
>
> OJ
>
> Sent from my BlackBerry® smartphone from Sinyal Bagus XL, Nyambung 
> Teruuusss...!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic App Creation

2009-07-07 Thread Andrew Fong

Generally speaking, dynamically altering the DB schema is difficult
and dangerous. SQL databases are not spreadsheets -- that is, you
shouldn't be frequently adding or removing columns to them. It makes
optimization difficult and it's very likely you'll accidentally lose
data in the process. AFAIK, the only way to get this working in Django
is to manually write your own SQL.

Google App Engine might work better this for though. You can run a
tweaked version of Django on GAE I believe, and its non-SQL datastore
is more friendly to spreadsheet-like applications. Amazon's SimpleDB
might work too.

-- Andrew

On Jul 7, 8:37 am, Darren Mansell  wrote:
> Hello. I'm looking into making a Django app that allows you to create Django
> models.
>
> The idea is that you should be able to add fields and user workflows using a
> web page that then creates a model, view, template and syncs the DB. Users
> can then access these newly created apps separately.
>
> An example:
>
> An accounts department of a company wants to replace their Excel files that
> they currently use for expenses, claims etc. with a web-based system. The
> web based system will have a page where you can create fields such as a
> field for name, field for dept, field for expense, tax etc. The page then
> creates a Django app with a model, view and template from this for employees
> to fill in to submit expenses.
> The employees DB will have info about who is who's manager and will then
> allow the page creator to include workflows - e.g. employees enters details
> and submits, their manager gets a mail to request authorisation, they
> authorise and their director then has to authorise etc.
>
> I think if something like this were to exist it would allow lots of
> businesses to replace static documents for workflow with web based systems.
>
> Does anyone know of anything out there that already does this kind of thing?
>
> Darren
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing apache mod python

2009-07-07 Thread Andrew Fong

Something else just crossed my mind as well. The issue, AFAIK, is that
older versions of Ubuntu / Python 2.5 stored third-party libraries
(e.g. stuff you easy_install) in /usr/lib/python2.5/site-packages.
With the upgrade to Ubuntu 9.04 / Python 2.6, these packages are now
stored in /usr/lib/python2.6/dist-packages. Note that the old site-
packages path is missing from your PythonPath. It's not just as simple
as adding the old site-packages directory to your python path though.
The compiled pyc files (and possibly other things) in that directory
are specific to the version they were compiled with and will likely
cause more headaches.

If Deportista is a third-party library that you used setup.py or
easy_install to install, you might just want to try re-installing it
using the same method.

If, on the other hand, Deportista is something you manually plunked
down into the site-packages dir (or symlinked into), then you'll just
manually have to move it to some other directory in your Python path
(e.g. /usr/lib/python2.6/dist-packages). Make sure to remove all the
old pyc files in there though!

-- Andrew

On Jul 7, 9:10 am, Andrew Fong <fongand...@gmail.com> wrote:
> Don't know if you tried this already, but the Ubuntu 9.04 Release
> Notes mention something about this:
>
> http://www.ubuntu.com/getubuntu/releasenotes/904#python%20ImportError...
>
> """
> A bug in the python packages present in jaunty prior to the Ubuntu
> 9.04 release candidate caused python modules to fail to be registered
> for use with the current python version, python 2.6. This problem
> appears as an import error, e.g:
>
> ImportError: No module named foo
> even though the package providing the module package is installed.
>
> To correct this, run the command:
>
> sudo dpkg-reconfigure python-foo
> for each python-foo package providing an affected module.
>
> """
>
> -- Andrew
>
> On Jul 7, 7:43 am, Miguel <migue...@gmail.com> wrote:
>
>
>
> > Thank you Aaron. I will try to follow your pieces of advices. Fortunately it
> > is not my production enviroment.
>
> > Miguel
>
> > On Thu, Jul 2, 2009 at 12:47 AM, Aaron Maxwell <a...@redsymbol.net> wrote:
>
> > > Hm.  It involves this module Deportista.  I haven't heard of it, so I'm
> > > assuming it's either a third-party library you are using, or one a module
> > > made in house.
>
> > > You might try this: (assuming unixy environment)
>
> > > 1) At a shell prompt, set PYTHONPATH to the value you included in the
> > > attached
> > > error report page.  (you know how to do this?  If not, look up setting and
> > > exporting environment variables.)
> > > 2) Also set DJANGO_SETTINGS_MODULE
> > > 3) Start a python interpreter
> > > 4) type in "import entrenatech.views"
>
> > > Does this reproduce the Deportista importerror?  If so, that is a good
> > > clue.
>
> > > On Wednesday 01 July 2009 12:55:05 am Miguel wrote:
> > > > The error is:
> > > > ViewDoesNotExist at / Could not import entrenatech.views. Error was: No
> > > > module named Deportista
> > > > As you said, Django .96 might be incompatible somehow, but I have to 
> > > > keep
> > > > it becasuse it is a little messy to updgrade the django version. Too 
> > > > much
> > > > production code.
>
> > > --
> > > Aaron Maxwell
> > >http://redsymbol.net/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: changing apache mod python

2009-07-07 Thread Andrew Fong

Don't know if you tried this already, but the Ubuntu 9.04 Release
Notes mention something about this:

http://www.ubuntu.com/getubuntu/releasenotes/904#python%20ImportError%20with%20systems%20upgraded%20before%20Ubuntu%209.04%20release%20candidate

"""
A bug in the python packages present in jaunty prior to the Ubuntu
9.04 release candidate caused python modules to fail to be registered
for use with the current python version, python 2.6. This problem
appears as an import error, e.g:

ImportError: No module named foo
even though the package providing the module package is installed.

To correct this, run the command:

sudo dpkg-reconfigure python-foo
for each python-foo package providing an affected module.

"""

-- Andrew

On Jul 7, 7:43 am, Miguel  wrote:
> Thank you Aaron. I will try to follow your pieces of advices. Fortunately it
> is not my production enviroment.
>
> Miguel
>
>
>
> On Thu, Jul 2, 2009 at 12:47 AM, Aaron Maxwell  wrote:
>
> > Hm.  It involves this module Deportista.  I haven't heard of it, so I'm
> > assuming it's either a third-party library you are using, or one a module
> > made in house.
>
> > You might try this: (assuming unixy environment)
>
> > 1) At a shell prompt, set PYTHONPATH to the value you included in the
> > attached
> > error report page.  (you know how to do this?  If not, look up setting and
> > exporting environment variables.)
> > 2) Also set DJANGO_SETTINGS_MODULE
> > 3) Start a python interpreter
> > 4) type in "import entrenatech.views"
>
> > Does this reproduce the Deportista importerror?  If so, that is a good
> > clue.
>
> > On Wednesday 01 July 2009 12:55:05 am Miguel wrote:
> > > The error is:
> > > ViewDoesNotExist at / Could not import entrenatech.views. Error was: No
> > > module named Deportista
> > > As you said, Django .96 might be incompatible somehow, but I have to keep
> > > it becasuse it is a little messy to updgrade the django version. Too much
> > > production code.
>
> > --
> > Aaron Maxwell
> >http://redsymbol.net/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Best way to handle HEAD method

2009-07-07 Thread Andrew Fong

The exception is very definitely being raised by me trying to
distinguish things based on REQUEST_METHOD type. Here's the traceback:

Traceback (most recent call last):

 File "/usr/lib/python2.6/dist-packages/django/core/handlers/base.py",
line 92, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/andrew/djprj/helpers/request_handler.py", line 77, in
__call__
   raise NoMethodError(request.method)

NoMethodError: The HEAD method is not allowed for this path



The relevant code in helpers/request_handler.py is this:

class RestHandler(object):
def __call__(self, request, *args, **kwargs):
method = request.method.upper()
if hasattr(self, method):
return getattr(self, method)(request, *args, **kwargs)
raise NoMethodError(request.method)

class NoMethodError(Exception):
def __init__(self, method):
super(Exception, self).__init__(
"The %s method is not allowed for this path" % method)

---

Graham, are you suggesting that if I receive a HEAD request, I should
behave exactly the same as if I received a GET request? That is, I
should assume Apache / mod_wsgi will take care of translating my
response into one appropriate for a HEAD request?


-- Andrew



On Jul 6, 7:28 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> On Jul 7, 2:14 am, Andrew Fong <fongand...@gmail.com> wrote:
>
> > Thanks for the response. I'm using Apache/mod_wsgi and getting error
> > messages in production because my handlers don't know how to handle a
> > HEAD request. If the server is supposed to automatically translate the
> > HEAD requests into GETs, then I probably have something set up
> > incorrectly. Any idea where to start looking?
>
> As I described, it doesn't always translate HEAD to GET and that
> shouldn't matter. Neither should it really matter in the Django layers
> either. If you in your code are trying to distinguish things based on
> REQUEST_METHOD type, then it is more likely to be in your code.
>
> I would suggest you post the Python traceback so others can say
> whether it is an issue in Django layers to eliminate that, and then
> perhaps point at where problem may lie. Ie., in your code or
> elsewhere.
>
> Graham
>
>
>
> > -- Andrew
>
> > On Jul 2, 7:16 pm, Graham Dumpleton <graham.dumple...@gmail.com>
> > wrote:
>
> > > On Jul 3, 4:55 am, Andrew Fong <fongand...@gmail.com> wrote:
>
> > > > How exactly should I handle a HEAD request in Django?
>
> > > > So ... assuming my view looks like this...
>
> > > > def handle_request(request):
> > > >     if request.method == 'POST': return do_post(request)
> > > >     elif request.method == 'GET': return do_get(request)
> > > >     elif request.method == 'HEAD': return do_head(request)
>
> > > > ... what should the do_head method return?  The W3 standard says "The
> > > > HEAD method is identical to GET except that the server MUST NOT return
> > > > a message-body in the response".
>
> > > > How exactly do I not return a message body though? Do I just return
> > > > None? Do I return the response I would for a GET and then modify it
> > > > somehow?
>
> > > You generally don't need to do anything different, the standard says
> > > 'the ***server***'.
>
> > > So, for sane web servers, the underlying server will deal with this
> > > and the application doesn't need to. You should just do exactly what
> > > you would normally do for a GET request. The web server would then
> > > return all the headers but just throw the response content away and
> > > not return it to the client.
>
> > > If you do act differently, you potentially break the requirement that
> > > response headers for the HEAD should match what would be returned for
> > > a GET request against same resource. Thus, the suggestion of returning
> > > an empty string could stuff up returned content length for a start.
>
> > > FWIW, in Apache/mod_wsgi it will deliberately at times translate a
> > > HEAD into a GET when it is passed into the WSGI application. This will
> > > occur when there are Apache output filters registered that may want to
> > > change response headers and modify the content. For example,
> > > mod_deflate, which would compress the response. If this isn't done and
> > > the application acted differently for a HEAD, then the data received
> > > by Apache output filter would not be the same as for the GET and
> > > result returned to client would be different than what it should be.
>
> > > Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SQLite and Null Character

2009-07-06 Thread Andrew Fong

The SQLite shell doesn't like the null character either. Not sure how
to escape it though. For that matter, I'm not sure how to escape
anything in SQLite. The only way I could enter in unicode was to pass
it in directly (e.g as opposed to some ASCII representation to
unicode) or to use a binary blob literal.

At any rate, this looks like an SQLite (or possibly a Python-SQLite
adapter) question, not a Django one. Thanks for the help though.

-- Andrew

On Jul 6, 12:54 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Mon, Jul 6, 2009 at 11:52 AM, Andrew Fong <fongand...@gmail.com> wrote:
>
> > I'm using a SQLite3 backend on Python 2.6 and saving a unicode string
> > with the null character (u'\x00') results in everything after that
> > character being truncated.
>
> > For example:
>
> > m = MyModel(name=u'abc\x00def')
> > m.save()
> > MyModel.objects.get(pk=m.pk).name # => u'abc'
>
> > I've tried using both the sqlite3 library included with Python and the
> > pysqlite2, but I still get this error. I'm not sure whether this error
> > is specific to SQLite3, the python-interface, or Django. This all
> > seems to work fine in MySQL however.
>
> > -- Andrew
>
> I'd try performing the same operations at the SQLite shell and see if you
> get the same behavior.  If you do I'd guess that either it's a bug in
> SQLite, or you need to escape the NULL character (which would make sense if
> they're using C strings).
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



SQLite and Null Character

2009-07-06 Thread Andrew Fong

I'm using a SQLite3 backend on Python 2.6 and saving a unicode string
with the null character (u'\x00') results in everything after that
character being truncated.

For example:

m = MyModel(name=u'abc\x00def')
m.save()
MyModel.objects.get(pk=m.pk).name # => u'abc'

I've tried using both the sqlite3 library included with Python and the
pysqlite2, but I still get this error. I'm not sure whether this error
is specific to SQLite3, the python-interface, or Django. This all
seems to work fine in MySQL however.

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



Re: Best way to handle HEAD method

2009-07-06 Thread Andrew Fong

Thanks for the response. I'm using Apache/mod_wsgi and getting error
messages in production because my handlers don't know how to handle a
HEAD request. If the server is supposed to automatically translate the
HEAD requests into GETs, then I probably have something set up
incorrectly. Any idea where to start looking?

-- Andrew

On Jul 2, 7:16 pm, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:
> On Jul 3, 4:55 am, Andrew Fong <fongand...@gmail.com> wrote:
>
>
>
>
>
> > How exactly should I handle a HEAD request in Django?
>
> > So ... assuming my view looks like this...
>
> > def handle_request(request):
> >     if request.method == 'POST': return do_post(request)
> >     elif request.method == 'GET': return do_get(request)
> >     elif request.method == 'HEAD': return do_head(request)
>
> > ... what should the do_head method return?  The W3 standard says "The
> > HEAD method is identical to GET except that the server MUST NOT return
> > a message-body in the response".
>
> > How exactly do I not return a message body though? Do I just return
> > None? Do I return the response I would for a GET and then modify it
> > somehow?
>
> You generally don't need to do anything different, the standard says
> 'the ***server***'.
>
> So, for sane web servers, the underlying server will deal with this
> and the application doesn't need to. You should just do exactly what
> you would normally do for a GET request. The web server would then
> return all the headers but just throw the response content away and
> not return it to the client.
>
> If you do act differently, you potentially break the requirement that
> response headers for the HEAD should match what would be returned for
> a GET request against same resource. Thus, the suggestion of returning
> an empty string could stuff up returned content length for a start.
>
> FWIW, in Apache/mod_wsgi it will deliberately at times translate a
> HEAD into a GET when it is passed into the WSGI application. This will
> occur when there are Apache output filters registered that may want to
> change response headers and modify the content. For example,
> mod_deflate, which would compress the response. If this isn't done and
> the application acted differently for a HEAD, then the data received
> by Apache output filter would not be the same as for the GET and
> result returned to client would be different than what it should be.
>
> Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileField/ImageField and the sites framework

2009-07-02 Thread Andrew Fong

Need more data here. This ventures from strictly Django into
deployment setups. Why exactly can't you just use a common MEDIA_ROOT?
Are your sites on different boxes?

-- Andrew

On Jul 2, 2:19 pm, smcoll  wrote:
> i have a project running multiple sites.   One of the apps in the
> project has a model with a FileField and an M2M to `Site`.  Since each
> site has its own MEDIA_ROOT, a model instance saved from SiteA
> (publishing on both SiteA and SiteB) can only display the file from
> SiteA, because the file only exists within its MEDIA_ROOT.
>
> How is this typically dealt with?  Is there any way aside from sharing
> a common MEDIA_ROOT?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Tracking a bad import

2009-07-02 Thread Andrew Fong

Ignoring thread hijacking there and responding to the OP.

The next time you have an import error, try using the -v option, like
this: python -v manage.py syncdb

That'll print every module being imported as it's being imported -- it
might help identify what's missing.

Alternatively, use pdb (http://docs.python.org/library/pdb.html)

-- Andrew

On Jul 2, 12:00 am, goodwinb  wrote:
> Fixed it by reinstalling all of my packages.
>
> On Jul 1, 8:48 pm, goodwinb  wrote:
>
>
>
> > I am setting up a server and when I run manage.py syncdb I get the
> > error 'cannot import name pre_delete'.  How can I get more trace
> > information about where the bad pre_delete is?
>
> > Python 2.6; Django 1.1-beta; using comments, markdown, statlib
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Best way to handle HEAD method

2009-07-02 Thread Andrew Fong

How exactly should I handle a HEAD request in Django?

So ... assuming my view looks like this...

def handle_request(request):
if request.method == 'POST': return do_post(request)
elif request.method == 'GET': return do_get(request)
elif request.method == 'HEAD': return do_head(request)

... what should the do_head method return?  The W3 standard says "The
HEAD method is identical to GET except that the server MUST NOT return
a message-body in the response".

How exactly do I not return a message body though? Do I just return
None? Do I return the response I would for a GET and then modify it
somehow?

Thanks in advance!

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



Escaping forward slashes in URLs

2009-06-25 Thread Andrew Fong

Question: When is it necessary to escape a forward slash? I'm dealing
with these two situations in my templates -- assume the next context
variable is a URL of some sort.



http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Testing Django Templates

2009-06-08 Thread Andrew Fong

I'm trying to get into a better testing flow with Django. One of
things I'm trying to figure out how to test are templates. Using the
Django Test Client works fine, for instance, in detecting whether I
have a missing template tag (because it'll explode) or if I don't pass
a particular variable to the context (using the response's context
attribute).

There are a couple of other things I'd like to automate testing of
however.

1) Has a template variable been used? Sometimes I'll have a piece of
template code like this : {% if a %}{{ b }}{% else %}{{ c }}{% end %},
and I'd like to see whether b or c has been rendered.

2) Were there any attribute errors? E.g. if variable x has no
attribute y, I should be able to detect something wrong with
{{ x.y.z }}. This is currently hidden by Django's silent failure when
dealing with template variables.

Currently, I'm doing a bit of testing using this pattern:

assert "something" in response.content, response.content

That's somewhat messy however -- and I'd like to avoid having to scan
through html in my test output just to find a bug if there's a simpler
method. Does anyone have any suggestions?

-- Andrew


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



Re: Bulk get

2009-06-06 Thread Andrew Fong

Was hoping not to have to loop back through it -- but I guess I'll
just have to suck it up and do it. Thanks.

On Jun 6, 11:04 am, Michael <newmani...@gmail.com> wrote:
> On Sat, Jun 6, 2009 at 10:55 AM, Andrew Fong <fongand...@gmail.com> wrote:
>
> > Hi all,
>
> > I'm trying to figure out how to do this and can't seem to wrap my head
> > around it today. I have currently have a piece of code like this:
>
> > x = [MyModel.objects.get(pk=pk) for pk in model_pk_list]
>
> x = MyModel.objects.filter(pk__in=model_pk_list)
>
> Does this in one db call, returns a queryset so it is lazy. As for the
> order, this will come back as the default ordering of the model. You can
> change the ordering based on something else by using the .order_by on the
> queryset. otherwise you would have to loop through it and create an ordered
> list based on your arbitrary ordering.
>
> Hope that helps,
>
> Michael
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to deal with object that have out of date querysets

2009-06-06 Thread Andrew Fong

What you're dealing with is called a "race condition". Transactions
ensure that a set of database operations occur together in a single
uninterrupted unit. That's not quite the exact definition, but if
you're picky, see this: http://en.wikipedia.org/wiki/Database_transaction

You can find documentation of Django's support for transactions here:
http://docs.djangoproject.com/en/dev/topics/db/transactions/

Note that this is dependent on your database supporting transactions.
If whatever reason your DB doesn't (e.g. using MySQL's MyISAM tables),
I think using Django's update call will work. Calling
MyModel.objects.filter(value=10, id=my_id).update(value=15) will
update the record with the given id to have a value of 15 if and only
if it's current value is already 10. It returns the number of records
it successfully modifies, so if there was no conflict, it'll return 1.
If it returns 0, you know that another process changed the value first
and that you'll need to get the new value to increment from the
database again.

-- Andrew

On Jun 6, 10:26 am, Masklinn  wrote:
> On 6 juin 09, at 15:34, AlexM  wrote:
>
>
>
> > In one of my views i am using a custom manager , the custom manager
> > finds a user , alters his "balance" (where balance is an integer
> > value) , and then saves the user with the new balance.
>
> > The problem occurs when http requests coming really fast on that
> > view.
>
> > Lets say the "original" value of a users balance is 10 .
> > Two requests are made , each one asking for the users balance to be
> > credited plus 5 of the original one.
> > The "perfect" solution would be the first requests to be
> > processed ,saved and then the second to do the same.
>
> > However what happens is that the first request will come , it will do
> > its query and load the object , and the second request will also do
> > the query before the first request was able to complete the process of
> > saving the new balance, because of that the second request will have
> > and "out of date" balance which it will then save . So in the end the
> > user will have 10 (origina ballance) + 5 (second request) = 15 on his
> > balance when he should have 20.
>
> > What could i do to prevent this from happening ?
>
> Use transactions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bulk get

2009-06-06 Thread Andrew Fong

Hi all,

I'm trying to figure out how to do this and can't seem to wrap my head
around it today. I have currently have a piece of code like this:

x = [MyModel.objects.get(pk=pk) for pk in model_pk_list]

I want to modify this such that ...
* Everything is done with one call to the DB instead len
(model_pk_list) calls
* x is lazily-evaluated (e.g. like a QuerySet object)
* The results come back in the same order as they are in model_pk_list

Is this possible? Thanks in advance!


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



Re: Customizing extends template tag for mobile version of site

2009-06-06 Thread Andrew Fong

I thought about doing that, but the problem with that approach is it
sort of violates the distinction between developer and designer that
the Django template system establishes. I'm not sure having the
designer muck around in Python to change which template their design
extends is a good idea.

I've come up with a somewhat hackish approach to this though. There
are three pieces to this:
1) You adopt a naming convention with mobile templates -- e.g. the
mobile version of bob.html would bob.html.m. Or something. Your
choice.
2) Instead of setting a mobile variable in the context, set it in some
global.
3) Write a custom template loader that checks said global variable and
gets a modified template according to naming convention if the mobile
variable evaluates to True.

I'm not a huge fan of that -- first, not a fan of forced naming
conventions that the designer can't easily change. Second, that global
variable could potentially pollute other requests. You basically have
to ensure it's reset for every request (e.g. using middleware) and
mark that piece of code as not thread safe.

Any suggestions?

-- Andrew

On Jun 6, 6:29 am, Matthias Kestenholz <matthias.kestenh...@gmail.com>
wrote:
> On Fri, Jun 5, 2009 at 6:35 PM, Andrew Fong <fongand...@gmail.com> wrote:
>
> > I was hoping someone could explain to me what the exact behavior would
> > be if the Extends Node in the template was not first.
>
> > Here's my use-case scenario: I need to maintain separate mobile and
> > desktop templates for my site. I'm finding out that 90% of my
> > templates would be identical -- the only difference would be which
> > templates they extended from -- e.g. {% extends 'base.html' %} vs. {%
> > extends 'm_base.html' %}.
>
> > My views insert a mobile variable into the context if they think the
> > user-agent is a mobile device. So I want behavior like this:
>
> > {% if mobile_var %}
> >  {% extends 'm_base.html' %}
> > {% else %}
> >  {% extends 'base.html' %}
> > {% endif %}
>
> > This won't work because the the extends tag doesn't really understand
> > the {% if %} tag above it and just throws up when it comes to the {%
> > else %} tag. So as an alternative, I plan to encapsulate that logic in
> > a custom extends tag -- e.g. {% mextends mobile_var 'm_base.html'
> > 'base.html' %} that wraps the existing do_extends function.
>
> > When going over the ExtendNode source code however, I noticed it has
> > to be first. However, in order to use my custom tag, I need to call {%
> > load %}, and that call means any ExtendNode created after that can't
> > be first. I'm tempted to simply disable that, but I'm not really sure
> > what will happen if I do. Are there any problems with calling a load
> > tag before an extends?
>
> I don't know the answer to your question, but here is a suggestion how
> you might accomplish using a different base template for the mobile
> version of your site. The extends tag accepts a variable too, so you
> could just use a context processor to pass the base template into the
> renderer, something like this (in pseudo-code):
>
> def base_template(request):
>      return {'base_template': is_mobile(request) and 'm_base.html' or
> 'base.html'}
>
> And inside your templates, use:
> {% extends base_template %}
>
> Matthias
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Customizing extends template tag for mobile version of site

2009-06-05 Thread Andrew Fong

I was hoping someone could explain to me what the exact behavior would
be if the Extends Node in the template was not first.

Here's my use-case scenario: I need to maintain separate mobile and
desktop templates for my site. I'm finding out that 90% of my
templates would be identical -- the only difference would be which
templates they extended from -- e.g. {% extends 'base.html' %} vs. {%
extends 'm_base.html' %}.

My views insert a mobile variable into the context if they think the
user-agent is a mobile device. So I want behavior like this:

{% if mobile_var %}
  {% extends 'm_base.html' %}
{% else %}
  {% extends 'base.html' %}
{% endif %}

This won't work because the the extends tag doesn't really understand
the {% if %} tag above it and just throws up when it comes to the {%
else %} tag. So as an alternative, I plan to encapsulate that logic in
a custom extends tag -- e.g. {% mextends mobile_var 'm_base.html'
'base.html' %} that wraps the existing do_extends function.

When going over the ExtendNode source code however, I noticed it has
to be first. However, in order to use my custom tag, I need to call {%
load %}, and that call means any ExtendNode created after that can't
be first. I'm tempted to simply disable that, but I'm not really sure
what will happen if I do. Are there any problems with calling a load
tag before an extends?

Thanks!

-- Andrew


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



Re: Custom urlconfs in django.contrib.auth tests failing when reverse is used in templates

2009-05-21 Thread Andrew Fong

Figured this out somewhat: To get around this, you can do something
like this when referencing external apps in auth templates:

{% url project.other_app.views.other_view as view %}

This won't raise an error if that reference doesn't work.

Still, this feels a bit hackish. I think brittle auth tests are
something of a recurring theme here.

On May 20, 5:18 pm, Andrew Fong <fongand...@gmail.com> wrote:
> I have the contrib.auth app installed, and in order for its tests to
> pass, I have to define certain registration templates. When defining
> those templates, if I use the url tag / reverse to point to a view
> outside the auths app, the auth tests fail.
>
> This occurs because the auth tests use a custom urlconf and have no
> knowledge of views elsewhere in the project -- on one hand, this makes
> sense since the auth app shouldn't be expected to know about the URLs
> in the project it's included in.
>
> On the other hand, the auth app invites us to write its own template
> -- and it seems reasonable that the template used for a login page
> might also have a link to another page in the app. For example, my
> registration templates extend a base template that has a nav bar
> pointing to views in other apps.
>
> Any ideas on how to work around this?
>
> -- Andrew
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Custom urlconfs in django.contrib.auth tests failing when reverse is used in templates

2009-05-20 Thread Andrew Fong

I have the contrib.auth app installed, and in order for its tests to
pass, I have to define certain registration templates. When defining
those templates, if I use the url tag / reverse to point to a view
outside the auths app, the auth tests fail.

This occurs because the auth tests use a custom urlconf and have no
knowledge of views elsewhere in the project -- on one hand, this makes
sense since the auth app shouldn't be expected to know about the URLs
in the project it's included in.

On the other hand, the auth app invites us to write its own template
-- and it seems reasonable that the template used for a login page
might also have a link to another page in the app. For example, my
registration templates extend a base template that has a nav bar
pointing to views in other apps.

Any ideas on how to work around this?

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



Re: RelatedObject Cache

2009-03-17 Thread Andrew Fong

And there it is! Thanks Alex!

On Mar 17, 2:18 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Tue, Mar 17, 2009 at 5:08 PM, Andrew Fong <fongand...@gmail.com> wrote:
>
> > Hello all,
>
> > Quick question. Given these models ...
>
> > class A(models.Model): pass
>
> > class B(models.Model):
> >  model_a = models.ForeignKey(A)
>
> > ... getting the model_a attribute on an instance of B will result in
> > that related object being cached. So the question: given an instance
> > of B, how do I know whether the related object has already been
> > cached?
>
> > Been looking through the source code, but I can't find where
> > related_objects are stored. Thanks in advance to anyone who can help!
>
> > -- Andrew
>
> The code to calculate the cache is 
> here:http://code.djangoproject.com/browser/django/trunk/django/db/models/f...
> a lot to follow but it gets used in
> ReverseSingleRelatedObjectDescriptor which calls self.field.get_cache_name()
> which ForeignKey inherits from Field.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



RelatedObject Cache

2009-03-17 Thread Andrew Fong

Hello all,

Quick question. Given these models ...

class A(models.Model): pass

class B(models.Model):
  model_a = models.ForeignKey(A)

... getting the model_a attribute on an instance of B will result in
that related object being cached. So the question: given an instance
of B, how do I know whether the related object has already been
cached?

Been looking through the source code, but I can't find where
related_objects are stored. Thanks in advance to anyone who can help!

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



Re: Debugging infinite loops

2009-01-27 Thread Andrew Fong

Check out http://docs.python.org/library/logging.html for logging.
There's also some Django logging middleware floating around that might
be useful -- just Google for it.

On Jan 27, 11:45 am, defone  wrote:
> Hi,
>
> I'm seeing occasionally bug that is causing an infinite loop. What is
> the best way to debug these in production environment? I was thinking
> that why there is no built-in simple profiler in Django, just for
> example to log how much time it takes to e.g. render each view?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Setup_environ before or after forking?

2009-01-27 Thread Andrew Fong

I am running a python process separate from my actual Django web
server to do background processing. Since I need database access and I
like using Django's models, I call
django.core.management.setup_environ at the start of my background
process.

I am now trying to fork the process using the processing module
(http://pypi.python.org/pypi/processing) so I can run code on multiple
cores concurrently. Specifically, I use the Pool class to create a
bunch of worker processes that I can asynchronously assign work to.
Each of my worker processes also need DB access via Django's models.

Question: Does it make more sense to call setup_environ before or
after forking?

In particular, I don't know how Django sets up its database
connection. Do forked processes share one connection or does each
process have their own connection? Are there pros and cons to each?

Also, if it matters, I'm currently running MySQL 5.0.5 as the DB.

Thanks!

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



Composite Indexing

2009-01-19 Thread Andrew Fong

I'm using contrib.contenttypes and have added the following to my
model:

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()

When examining the DB (I'm using MySQL), I find that content_type is
indexed but object_id is not. I was going to just index object_id, but
it makes more sense to put a composite index on both content_type and
object_id together. Unfortunately, I have no idea how to do this
without writing raw SQL. I googled around but the only stuff I could
find is on primary composite keys and the unique_together constraint.
However, I don't want this composite index to be a primary key, and I
don't want it to be unique. Am I missing something 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Query using actual table values

2008-12-19 Thread Andrew Fong

I'm looking for the Django equivalent of the following:

SELECT * FROM table WHERE table.x1 = table.x2

Pretty sure someone has asked this before but I had a hard time
finding anything. I don't really want to write raw SQL if it can be
avoided.




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



Re: Development server crash with no error message

2008-12-10 Thread Andrew Fong

I'm using MySQLdb, cmemcache, PIL, and the django.contrib.gis stuff.

On Dec 8, 2:58 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Dec 9, 8:50 am, Andrew Fong <[EMAIL PROTECTED]> wrote:
>
> > When I'm poking around in my Django app, my development server
> > (manage.py runserver) will sometimes quit without raising an exception
> > or leaving any messages. I am not tinkering around with the code or
> > doing anything that would force a reload. It just decides to quit.
>
> > I can check the last request I made before it crashed, but without any
> > exceptions or errors, it's very hard to debug. Does anyone have any
> > tips on getting some more useful output out of acrash?
>
> What database adapter are you using? Is it a current version?
>
> What other third party packages are you using which use a C extension
> module to do stuff?
>
> Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Development server crash with no error message

2008-12-08 Thread Andrew Fong

When I'm poking around in my Django app, my development server
(manage.py runserver) will sometimes quit without raising an exception
or leaving any messages. I am not tinkering around with the code or
doing anything that would force a reload. It just decides to quit.

I can check the last request I made before it crashed, but without any
exceptions or errors, it's very hard to debug. Does anyone have any
tips on getting some more useful output out of a crash?

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



pre_delete, post_delete signals for contrib.contenttypes

2008-10-07 Thread Andrew Fong

Let's say you have model A with a foreign key link to model B -- that
is,  A depends on B. If you delete model B, then model A is removed as
well. You will also get two sets of deletion signals. One for A and
one for B.

When using a generic relation however, the signals for A are not sent
when you delete B. However, model A itself is still removed from the
database.

Any opinions about adding such a deletion signal for A?

-- Andrew



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



GeoDjango / GIS Garbage Collection Error

2008-09-23 Thread Andrew Fong

When a Django process terminates, I get the following error message:

Exception exceptions.TypeError: "'NoneType' object is not callable"
in  ignored

I poked around and there appears to be a problem with garbage
collecting instances of django.contrib.gis.geos.base.GEOSGeometry
objects.

To reproduce, create a Django project with two apps installed in the
settings file. Then add / change the following:

- django_project/consts.py -

from django.contrib.gis.geos import Point
SOME_CONST = Point(1,1)

- django_project/app_one/models.py -

from django_project.consts import SOME_CONST

- django_project/app_two/models.py -

from django_project.consts import SOME_CONST

--

Start the shell up. Everything should load just fine. When you close
however, you should get the TypeError. If you run python with the
verbose option, you'll notice that it throws the error when it tries
to clean up django_project.app_two.models (or maybe app_one.models).

If you switch SOME_CONST to some other object (like a datetime), you
won't get the exception. You will get it however so long as SOME_CONST
is a Point, Polygon, or any other instance of
django.contrib.gis.geos.base.GEOSGeometry.

It seems like when app_one is garbage collected, SOME_CONST is
removed / set to None. Then when app_two is collected, it also tries
to garbage collect SOME_CONST but can't find it.

Any ideas? It doesn't seem to be breaking anything in the app, but it
is really annoying.

-- Andrew

P.S. This seems to be the same problem as here, except with GeoDjango
instead of wxPython: 
http://mail.python.org/pipermail/python-list/2003-March/192239.html


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Tests in files other than tests.py and models.py

2008-06-25 Thread Andrew Fong

A quick browse of a few other posts on the list tell me this question
has been asked before but the previous answers didn't exactly work for
me. I created my own solution, but given that I'm very much a Django
(and Python) newbie, if there are any glaring errors in my approach,
please point them out.

Anyhow, we want the Django test runner to run tests from modules other
than tests and models. The documentation says to use tests.py as a
hook to other tests, but it's not very explicit in how to do so. From
previous posts, we know that to "hook" unit tests, we just have to
import the testcase like so:

from project.app.some_module import testcase

... where testcase is an instance of unittest.TestCase. This seems to
work swell.

For doctests, the simplest solution seems to be creating a dictionary
called __test__ that points to the functions and classes whose
docstrings you want to test. For me at least however, this didn't work
well. Doctest does not recurse on the items in __test__, meaning if
you have something in __test__ pointing to a class, it won't read the
docstrings for each class method, only the class's docstring. This
meant you had to manually enter in something for each class method, a
huge pain.

After that, I just put in a custom test suite in my tests.py file. It
seems to work fine, at least in the development version of Django. If
anyone sees any glaring mistakes, please point them out. Otherwise,
this might help someone else down the road:

# Start tests.py
# Place all your tests in separate modules and hook them by
# importing them and adding them to TEST_MODULE_LIST

import unittest
from django.test import _doctest as doctest
from django.test.testcases import OutputChecker, DocTestRunner
doctestOutputChecker = OutputChecker()

import project.app.views as views
import project.app.helpers as helpers

TEST_MODULE_LIST = [views, helpers]

def suite():
  s = unittest.TestSuite()
  for m in TEST_MODULE_LIST:
s.addTest(unittest.defaultTestLoader.loadTestsFromModule(m))
try:
  s.addTest(doctest.DocTestSuite(m,
checker=doctestOutputChecker,
runner=DocTestRunner))
except ValueError:
  # No doc tests in tests.py
  pass
  return s

# End tests.py

-- Andrew

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