Page load very slow, in Django site

2010-01-06 Thread NMarcu
Hello all,

My page is loading very slow, more then 5 sec per page. I'm using
apache2. How can I see what is the problem, or what can be the reason?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




warning: Not importing directory

2010-01-06 Thread Delacroy Systems
How do I solve this? Happens when I do a runserver...

warning: Not importing directory 'C:\Python25\Lib\site-packages\blocks
\locale': missing __init__.py
warning: Not importing directory 'C:\Python25\Lib\site-packages
\django_cms-2.0.2-py2.5.egg\cms\locale': missing __init__.py
warning: Not importing directory 'C:\Python25\Lib\site-packages\blocks
\locale':missing __init__.py
warning: Not importing directory 'C:\Python25\Lib\site-packages
\django_cms-2.0.2-py2.5.egg\cms\locale': missing __init__.py
Validating models...
0 errors found

If I create an __init__.py, I get this:
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "manage.py", line 2, in 
from django.core.management import execute_manager
  File "c:\python25\Lib\site-packages\django\core\management
\__init__.py", line
3, in 
from optparse import OptionParser, NO_DEFAULT
  File "C:\Python25\lib\optparse.py", line 404, in 
_builtin_cvt = { "int" : (_parse_int, _("integer")),
  File "C:\Python25\lib\gettext.py", line 566, in gettext
return dgettext(_current_domain, message)
  File "C:\Python25\lib\gettext.py", line 530, in dgettext
codeset=_localecodesets.get(domain))
  File "C:\Python25\lib\gettext.py", line 465, in translation
mofiles = find(domain, localedir, languages, all=1)
  File "C:\Python25\lib\gettext.py", line 437, in find
for nelang in _expand_lang(lang):
  File "C:\Python25\lib\gettext.py", line 131, in _expand_lang
from locale import normalize
ImportError: cannot import name normalize
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: form.has_changed always true?

2010-01-06 Thread Margie Roginski
If you look at the form's _changed_data attribute, it will give you a
list of the fields that have changed.  That should tell you what is
causing has_changed() to return True.

Margie


On Jan 6, 6:50 pm, Karen Tracey  wrote:
> On Wed, Jan 6, 2010 at 7:34 PM, Alastair Campbell  wrote:
> > Hi everyone,
>
> > I've been looking for a simple way to send an email when a user
> > updates their profile.
>
> > After some digging I found form.has_changed() which appears to fit the
> > bill. However, it always seems to return true, so I could end up
> > bombarding our elderly admin lady with lots of useless emails.
>
> > I'm using a simple model form (with a sub-set of the available
> > fields), rendered in the default manner, no hidden fields or anything.
> > If I open the page, hit save, if form.has_changed(): runs.
>
> > Is there anything else that might cause has_changed to be true?
>
> has_changed() returns True if the bound data of the form differs from the
> initial data. It does work and it does not always return True.  Without
> specifics of the code you are using to construct your form I'm not sure why
> it is always seeming to return True in your case.
>
> Karen
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: problems deserializing json object

2010-01-06 Thread Malcolm MacKinnon
Thanks Daniel, I'll give that a try.

On Wed, Jan 6, 2010 at 2:02 AM, Daniel Roseman wrote:

> On Jan 6, 1:54 am, Malcolm MacKinnon  wrote:
> > I'm having difficulty deserializing a json object. I'm using django
> > appengine patch, so the models aren't the same as django's, but they are
> > very similar:
> >
> > class Cust(db.Model):
> > custno = db.StringProperty(required=True)
> > company = db.StringProperty(required=True)
> > contact = db.StringProperty(required=False)
> > address1 = db.StringProperty(required=False)
> > address2 = db.StringProperty(required=False)
> > city = db.StringProperty(required=True)
> > state = db.StringProperty(required=False)
> > zipc = db.StringProperty(required=False)
> > country = db.StringProperty(required=False)
> > phone = db.StringProperty(required=False)
> > salesmn = db.StringProperty(required=True)
> > email = db.StringProperty()
> >
> > def __unicode__(self):
> > return self.custno + " : " + str(self.company)+" :
> > "+str(self.city)+" : "+str(self.state)
>
> Aargh! unicode methods must return unicode! Not bytestrings! Do this:
> return u'%s: %s: %s: %s' % (self.custno, self.company, self.city,
> self.state)
>
>
> >
> > class Cust_List(db.Model):
> > custno = db.StringProperty(required=True)
> > companies = db.TextProperty(required=True) #customer list as json
> object
> >
> > Note that the json object is stored in the db.TextProperty companies, and
> is
> > composed of more than a 1000 customers, all of which are also
> individually
> > stored in the model, Cust . I query the json object for a customer list,
> > since it saves CPU time on the appengine.
> >
> > Here's what happens when I try to decode the json string object:>>> from
> sport.models import Cust_List
> > >>> from django.core import serializers
> > >>> a=Cust_List.all()
> > >>> b=a.get() #returns the only and only data item in this model, which
> is a
> >
> > json object previously stored in the datastore.>>>
> c=serializers.deserialize('json', b.companies)
> > >>> d=list(c)
> > >>> e=len(d)
> > >>> e
> > 1057
> > >>> b
> >
> > etc...
> > cy...@global.net", "phone": "269/552-", "state": "MN", "contact":
> "Rick
> > L
> > ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
> > hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD RIVE
> > R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company":
> "ZSPORTS",
> > "cus
> > tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033",
> "sta
> > te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
> > "address2":
> >  ""}}]')>>> d
> >
> > etc...
> >  ,
> >  > edObject: WAT091 : WATERVILLE VALLEY RESORT : WATERVILLE VALLEY : NH>,
> >  > izedObject: WES003 : WESTCHESTER ROAD RUNNER : WHITE PLAINS : NY>,
> >  > Object: WES100 : WEST HILL SHOP : PUTNEY : VT>,  WHE189
> > : WH
> > EELIE FUN MULTI SPORT : LEBANON : OH>,  > WHIRLAWAY S
> > PORTS CTR : METHUEN : MA>,  > TOURING
> >  : DAVIS : WV>,  :
> > WHIS
> > TLER, BC : >,  > CO>,  > eserializedObject: WIL520 : WILD ROSE MOUNTAIN SPORTS : SALT LAKE CITY :
> > UT>,  > eserializedObject: WIL659 : ADVENTURE OUTFITTERS : HADLEY : MA>,
> >  > ject: WIL760 : WILDERNESS WAY, INC : SOLDOTNA : AK>,  > WIL9LA
> >  : WILSON BACKCOUNTRY : WILSON : WY>,  WILSON
> > MOUNT
> > AIN SPORTS : LAKE LOUISE, ALBERTA : >,  > WILDERNESS
> > SPORTS-DILLON : DILLON : CO>,  > MOUNTAIN SP
> > ORTS : WINTHROP : WA>,  > LAKE C
> > ITY : UT>,  WILMINGTON :
> > DE>
> > ,  BURLINGTON
> > : V
> > T>,  VT>,
> >  > erializedObject: WOR059 : WORLD CYCLE : BOISE : ID>,  > YEL017
> >  : YELLOWSTONE GATEWAY SPORTS : BOZEMAN : MT>,  ZAP013 :
> > ZAP
> > POS.COM : HENDERSON : NV>,  > PALO AL
> > TO : CA>,  KALAMAZOO :
> > MI>
> > , ] etc.
> >
> > Note that I just get returned a unicode representation of my model, Cust.
> > But the contact information, address information, and so on disappears in
> > the deserialized object. Any thoughts on why or what I'm doing wrong?
> >
> > Thanks for any help or ideas!
> >
> You're not getting a unicode representation, you're getting a
> DeserialzedObject. As the documentation (http://docs.djangoproject.com/
> en/1.1/topics/serialization/#deserializing-data) says, you need to
> iterate through the list of objects and call save() on each one to
> create the actual model.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to 

Re: ForeignKey efficiency question

2010-01-06 Thread apramanik
Oops not a join, but still a db hit :).

On Jan 6, 9:03 pm, apramanik  wrote:
> Hey all, if I have a foreign key on a model (say Model B has a foreign
> key to Model A) and I do something like this:
>
> a = A.objects.get( pk = 1 )
> b = B.objects.get( pk = 1 )
>
> if b.a == a :
>     # Do something
>
> Is that inefficient, since its doing a join to pull b.a? Should I be
> comparing their ids? How do I get that from the b model? Something
> like this:
>
> if b.a_id == a.id :
>    # Do something
>
> Not sure about the syntax. Thanks!
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




ForeignKey efficiency question

2010-01-06 Thread apramanik
Hey all, if I have a foreign key on a model (say Model B has a foreign
key to Model A) and I do something like this:

a = A.objects.get( pk = 1 )
b = B.objects.get( pk = 1 )

if b.a == a :
# Do something

Is that inefficient, since its doing a join to pull b.a? Should I be
comparing their ids? How do I get that from the b model? Something
like this:

if b.a_id == a.id :
   # Do something

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




Does anyone have a Django or Python flow chart?

2010-01-06 Thread spike
Does anyone have a Django or Python flow chart?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Django Contrib's UserCreationForm (Potential Bug)

2010-01-06 Thread Sandman
Hi All,

Happy new year.

I've been using the svn version of django while developing a small app.
Yesterday after I updated the code, one of my tests started returning an
error. In fixing this error, I may have uncovered a bug but I can't be
sure if this is intentional behavior (I'm not really an experienced dev,
so no confidence :().

Anyway, I have a UserCreationForm that inherits from
django.contrib.auth.forms.UserCreationForm (Code attached). In the
recent change to django code, a "clean" method was added to Contrib's
UserCreationForm. This method does not return any value. I think it is
supposed to return self.cleaned_data

When my form (that delegates clean to super) tries to use cleaned_data
in the save(), an exception is raised since self.cleaned_data end up
being None.

I have fixed the problem by adding a clean method in my form code that
delegates to "clean" of the ancestor of Contrib's UserCreationForm. But
it would be nice to simply inherit the form from contrib.auth and not
have to worry about the clean method.

What do you think?

Take care,
Rajiv.
from models import UserProfile
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
from django.contrib.auth.forms import UserCreationForm as 
ContribUserCreationForm


class UserCreationForm(ContribUserCreationForm):
"""
Extends the form from django.contrib to include profile info.
"""
email = CommonFields().get_email_field()
full_name = CommonFields().get_full_name_field()
password2 = forms.CharField(
label=_("Confirm Password"), widget=forms.PasswordInput
)

class Meta(ContribUserCreationForm.Meta):
#
# Add new fields after the parent fields so that the new fields
# appear at the bottom
#
fields = (
'username',
'password1',
'password2',
'email',
'full_name',
)

#
# Avoid the lack of return value from ContribUserCreationForm
# by calling the grandparents clean().
#
def clean(self):
"""
Override the bug-ridden base class's clean method
"""
self.instance.password = UNUSABLE_PASSWORD
return super(ContribUserCreationForm, self).clean()

def save(self, user, commit=False):
"""
Save the new user into the database.
"""
user = super(UserCreationForm, self).save(commit=False)

user.set_password(self.cleaned_data['password1'])
user.email = self.cleaned_data['email']

if self.cleaned_data.has_key('full_name'):
user.first_name, user.last_name = CommonFields().split_full_name(
self.cleaned_data['full_name']
)
user.save()
#
# Create a profile for the new user.
#
profile = UserProfile(user=user)
profile.nickname = user.username
profile.theme_layout = ThemeChoices().get_default_theme()
profile.save()

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




Re: form.has_changed always true?

2010-01-06 Thread Karen Tracey
On Wed, Jan 6, 2010 at 7:34 PM, Alastair Campbell  wrote:

> Hi everyone,
>
> I've been looking for a simple way to send an email when a user
> updates their profile.
>
> After some digging I found form.has_changed() which appears to fit the
> bill. However, it always seems to return true, so I could end up
> bombarding our elderly admin lady with lots of useless emails.
>
> I'm using a simple model form (with a sub-set of the available
> fields), rendered in the default manner, no hidden fields or anything.
> If I open the page, hit save, if form.has_changed(): runs.
>
> Is there anything else that might cause has_changed to be true?
>
>
has_changed() returns True if the bound data of the form differs from the
initial data. It does work and it does not always return True.  Without
specifics of the code you are using to construct your form I'm not sure why
it is always seeming to return True in your case.

Karen
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Django/Apache/mod_wsgi: How do I specify the SCRIPT_NAME for non-root URLs?

2010-01-06 Thread Karen Tracey
On Wed, Jan 6, 2010 at 2:39 PM, Tyler Erickson wrote:

> I am trying to use Apache and mod_wsgi to serve multiple django
> sites.  The django sites are served up fine when at the root URL, but
> when served from a sub-URL the portion of the the URL consumed by
> Apache disappears from any links created in the django site pages.
> From reading throught the WSGI spec (http://www.wsgi.org/wsgi/
> Specifications/routing_args),
> it appears that I need to specify the
> SCRIPT_NAME environment variable, but I am not sure where I should do
> that.  (The apache/django.wsgi file seemed like a logical place to set
> the SCRIPT_NAME environment variable, but that seems to have no effect
> on the generated URLs.)
>
>
It should Just Work, no need to set any environment variables.  There have
been a couple of threads recently similar to this:

http://groups.google.com/group/django-users/browse_thread/thread/ce1436670a3c55d5/
http://groups.google.com/group/django-users/browse_thread/thread/e790664ee1855647/

The first identified a Django problem in a very specific case (reverses
called during processing of requests for the project root url without a
trailing slash).  The cause of the second I don't recall seeing an answer
on. When I try it, it works for me, excepting the one case identified in the
first thread.  There is a fair amount of debugging advice to be found in
those threads, so perhaps they will help you in tracking down what is going
wrong in your case.

Karen
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Development server exiting after entering login info in admin site

2010-01-06 Thread Karen Tracey
On Wed, Jan 6, 2010 at 6:12 PM, Pascal Vincent wrote:

> I'm reposting this question here, since I didn't get any answer the
> first time, and I'm struck there.
> Where can I find help with this, should I rather post the problem to
> another group?
>
> ---
> I'm new to django, and was going through the tutorial (on Mac Os X
> 10.4.11, installed latest stable version from tarball).
> All seems to go well, and I can access the local site until I enter
> the damin login and passwd and submit.
> After that the development server program just exits without notice.
> (and the client browser then obviously can't get any connection to
> it).
>
> I've traced this back to autoreload.py line 96
> which reads:  sys.exit(restart_with_reloader())
> Any idea what is going (or what I am doing) wrong here?
>
>
I've never seen this nor recall hearing of it being reported before so have
no idea what is going on. You've not tracked it down far enough to point to
where the problem is.  That line is not the problem.  Note it calls, before
exiting, restart_with_reloader(). The question that needs to be answered now
is why does restart_with_reloader() return when you login?  Something weird
is apparently happening that is causing the process to terminate with an
unexpected return code (not the one that signals code has changed and causes
restart_with_reloader() to just start a new process).

I suspect you might have more success tracking down what is going on by
tracing through in a debugger the processing that happens during login.  I'm
not sure you're going to be able to get much more out of the code you're
looking at now than "hmm, the dev server process terminated with an
unexpected exit code".

You might try running the dev server with the --noreload option and seeing
if you get any better indication of the failure that way, though I don't
know why you would get more output from that case.  But maybe it'll be
easier to track down without the code that does the
auto-reload-on-code-change.

I do recall that some Pythons on Macs seem to behave relatively badly for
error situations such as infinite recursion.  Instead of a traceback
identifying the problem you might get a process termination with core dump
on Macs.  You might be running into some sort of problem like that, where
the Python interpreter is just terminating unexpectedly.

Karen
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Unable to delete certain admin objects. Get "coercing to unicode" error on some, but not all objects.

2010-01-06 Thread Karen Tracey
On Wed, Jan 6, 2010 at 5:20 PM, rc  wrote:

> I get the following error when I try and delete a "testcase":
>
> Request Method: GET
> Request URL: http://hades/admin/bisite/testcase/20/delete/
> Django Version: 1.0.2 final
> Python Version: 2.5.2
> Installed Applications:
> [snip]
>
679. get_deleted_objects(deleted_objects, perms_needed,
> request.user, obj, opts, 1, self.admin_site)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/util.py"
> in get_deleted_objects
>  107. nh(deleted_objects, current_depth, [u'%s:
> %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj),
> []])
>
> Exception Type: TypeError at /admin/bisite/testcase/20/delete/
> Exception Value: coercing to Unicode: need string or buffer, int found
>
> but deleting a "job" works just fine.
>
> You can see from my testcase model that it does in fact return a
> string (test_name)
>
>
Admin here is collecting a list of related objects that are going to need to
be deleted as a result of deleting the one you have chosen.  So not only
does Testcase need to have a proper unicode-returning __unicode__
implementation, so does any model that has a ForeignKey pointing to it.
Really, all your __unicode__ methods need to return unicode, not bytestrings
or ints or other objects.

Karen
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



form.has_changed always true?

2010-01-06 Thread Alastair Campbell
Hi everyone,

I've been looking for a simple way to send an email when a user
updates their profile.

After some digging I found form.has_changed() which appears to fit the
bill. However, it always seems to return true, so I could end up
bombarding our elderly admin lady with lots of useless emails.

I'm using a simple model form (with a sub-set of the available
fields), rendered in the default manner, no hidden fields or anything.
If I open the page, hit save, if form.has_changed(): runs.

Is there anything else that might cause has_changed to be true?

Perhaps this is why has_changed() isn't mentioned in the documentation?

I kinda hope I'm being stupid on this one, I'd rather not get into a
long comparison function!

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




Re: Cannot Click Into Internet Explorer Input Text Field

2010-01-06 Thread geraldcor
For those interested: It was a z-index issue. I set my main content
div to z-index: -1; so that my drop down menus would not get hidden in
IE. This however masked my input fields. So, I ended up removing that
z-index and giving my #nav a z-index of 1000. Did the trick.

Greg

On Jan 5, 6:14 pm, geraldcor  wrote:
> Hello All,
>
> I have recently run into a very weird internet explorer problem. I
> cannot enter any of my text input boxes unless I carefully hover my
> mouse near the top or bottom edge of the field. The cursor does not
> change until I get to the very top of the field. It works fine in all
> other browsers but IE6, 7 and 8 have all shown this problem. I can
> click into the google CSE field on my page and other fields on other
> sites, but the field that django is producing give me this problem.
> Any ideas on how to fix it? It is kind of critical that this gets
> fixed.
>
> Thanks for all of you help.
>
> Greg
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Development server exiting after entering login info in admin site

2010-01-06 Thread Pascal Vincent
I'm reposting this question here, since I didn't get any answer the
first time, and I'm struck there.
Where can I find help with this, should I rather post the problem to
another group?

---
I'm new to django, and was going through the tutorial (on Mac Os X
10.4.11, installed latest stable version from tarball).
All seems to go well, and I can access the local site until I enter
the damin login and passwd and submit.
After that the development server program just exits without notice.
(and the client browser then obviously can't get any connection to
it).

I've traced this back to autoreload.py line 96
which reads:  sys.exit(restart_with_reloader())
Any idea what is going (or what I am doing) wrong here?

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




How can I retrieve the ModelAdmin given the model class or an instance?

2010-01-06 Thread Marco Rogers
I'm retrieving a model using django.db.models.get_model.  The view is
receiving a post from a form generated by the ModelAdmin.  How can I
get a hold of that ModelAdmin instance so can then get a hold of the
ModelForm?  This will allow me to process the post (validation,
related objects, etc).  The ModelAdmin has a reference to it's model,
but the reverse doesn't seem to be true.

The way I'm doing this right now is bad juju.  The AdminSite keeps a
registry of models and ModelAdmins so I'm doing this:

modeladmin = admin.site._registry[model];

Obviously using this internal registry is a bad idea.  I was looking
for a more official api similar to get_model or one of the following:

modeladmin = admin.site.get_admin(model)

Even if this just returns the instance from the registry like above.
Or make it accessible through the model like one of the following:

modeladmin = model.get_admin()
modeladmin = model._admin

Any help with this is appreciated

Now a litlte more context. Like I mentioned above, what I actually
need is a ModelForm similar to the one generated by the admin site.  I
have a custom admin view that receives the post from an add/change
form.  So to process that post I need the equivalent ModelForm.

If there is an easier or more idiomatic way to write custom admin
views, I'd appreciate if someone pointed 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Unable to delete certain admin objects. Get "coercing to unicode" error on some, but not all objects.

2010-01-06 Thread rc
I get the following error when I try and delete a "testcase":

Request Method: GET
Request URL: http://hades/admin/bisite/testcase/20/delete/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'bisite']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in root
  157. return self.model_page(request, *url.split('/',
2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in model_page
  176. return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in __call__
  195. return self.delete_view(request, unquote(url[:-7]))
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in delete_view
  679. get_deleted_objects(deleted_objects, perms_needed,
request.user, obj, opts, 1, self.admin_site)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/util.py"
in get_deleted_objects
  107. nh(deleted_objects, current_depth, [u'%s:
%s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj),
[]])

Exception Type: TypeError at /admin/bisite/testcase/20/delete/
Exception Value: coercing to Unicode: need string or buffer, int found

but deleting a "job" works just fine.

You can see from my testcase model that it does in fact return a
string (test_name)

I have the following models:

class Testcase(models.Model):
test_id = models.AutoField(primary_key=True)
test_name = models.CharField(max_length=300)
src = models.ForeignKey(Source, null=True, blank=True)
bitrate = models.IntegerField(null=True, blank=True)
test_type = models.CharField(max_length=300)
output_resolution = models.CharField(max_length=15, blank=True)
description = models.CharField(max_length=3000, blank=True)
ref_file = models.CharField(max_length=765, blank=True)
ref_encode_filesize = models.IntegerField(null=True, blank=True)
ref_y_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_u_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_v_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_yuv_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
highmark_version = models.CharField(max_length=60, blank=True)
def __unicode__(self):
return self.test_name
class Meta:
ordering = ['test_name']
db_table = u'testcase'

class Job(models.Model):
job_id = models.AutoField(primary_key=True)
job_name = models.CharField(max_length=50)
server = models.CharField(max_length=25)
minute = models.CharField(max_length=10, choices = 
u.min_choices())
hour = models.CharField(max_length=10, choices = 
u.hour_choices())
day_of_month = models.CharField(max_length=10, choices =
u.dom_choices())
month = models.CharField(max_length=10, choices = 
u.mon_choices())
day_of_week = models.CharField(
max_length=10, choices = u.dow_choices(),
help_text = '* If Day of Week 
is selected, \
Day of Month and Month will be 
ignored.')
logfile_name = models.CharField(max_length=100)
new_code = models.BooleanField(
help_text = '* Check out new code and compile 
before running
tests.')
base_dir = models.CharField(
max_length=100, help_text = '* Directory to 
check code into.')
svn_dir = models.CharField(max_length=100,

 help_text = '* SVN directory to check 
code out of.')
test_dir = models.CharField(max_length=100,

help_text = '* Directory to 
store test files in.')
profile = 

Re: how relate webpage with databse in my harddisk?

2010-01-06 Thread Kenny Meyer
> How other can access pages i generated with django?
You mean how others can access pages which Django generated *for you*.
If you're connected with computers in a home network they can see your
work with a webbrowser, knowing the IP address of the Pc which is
serving the Django "pages". Usually this is :8000 if
you're using Django's development server.
If you want to deploy it on a web server, read this:
http://docs.djangoproject.com/en/dev/howto/deployment/
> How others could be able to fill forms and get data from my hard disk
> through generated html interface?
Through a webbrowser.
> I would like to connect to generated html pages through internet [..]
Redirect traffic from your router which is incoming on port 80 to your
local machine to any port on which your webserver is running. Now that's
a very brief how-to. Google is your friend.


signature.asc
Description: Digital signature


Re: Error when trying to connect to django_session

2010-01-06 Thread Daniel Roseman
On Jan 6, 7:51 pm, Mike  wrote:
> I am a newb to a this so please keep that in mind when reading this.
> I am running Ubuntu 9.10, postgreSQL 8.4, psycopg2, Django 1.1.1, and
> Apache 2.2.  Everything works fine until I go to authenticate then I
> get an error.  I am trying to get the authentication piece to work by
> using the canned template and I get the following traceback:
>
> [Wed Jan 06 11:33:12 2010] [notice] caught SIGTERM, shutting down
> [Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Compiled for Python/2.6.2.
> [Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Runtime using Python/
> 2.6.4.
> [Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Python module path '/usr/
> lib/python2.6/:/usr/lib/python2.6/plat-linux2:/usr/lib/python2.6/lib-
> tk:/usr/lib/python2.6/lib-old:/usr/lib/py$
> [Wed Jan 06 11:33:13 2010] [notice] Apache/2.2.12 (Ubuntu) PHP/
> 5.2.10-2ubuntu6.3 with Suhosin-Patch mod_wsgi/2.5 Python/2.6.4
> mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming no$
> [Wed Jan 06 11:33:16 2010] [error] mod_wsgi (pid=22889): Exception
> occurred processing WSGI script '/srv/Django/FDRAB_Intranet/apache/
> django.wsgi'.
> Traceback (most recent call last):
> File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line
> 245, in __call__
>   response = middleware_method(request, response)
> File "/usr/lib/pymodules/python2.6/django/contrib/sessions/
> middleware.py", line 36, in process_response
>   request.session.save()
> File "/usr/lib/pymodules/python2.6/django/contrib/sessions/backends/
> db.py", line 58, in save
>   obj.save(force_insert=must_create)
> File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
> 410, in save
>   self.save_base(force_insert=force_insert, force_update=force_update)
> File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
> 470, in save_base
>   manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by
> ())):
> File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
> 112, in __nonzero__
>   iter(self).next()
> File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
> 106, in _result_iter
>   self._fill_cache()
> File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
> 692, in _fill_cache
>   self._result_cache.append(self._iter.next())
> File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
> 756, in iterator
>   for row in self.query.results_iter():
> File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
> line 287, in results_iter
>   for rows in self.execute_sql(MULTI):
> File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
> line 2369, in execute_sql
>   cursor.execute(sql, params)
> File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line
> 19, in execute
>   return self.cursor.execute(sql, params)
> ProgrammingError: relation "django_session" does not exist
> LINE 1: SELECT (1) AS "a" FROM "django_session" WHERE
> "django_sessio...
>
> The most annoying part is that Django can write to the table in other
> instances, but for some reason it fails when I try to authenticate.

Have you run ./manage.py syncdb since adding django.contrib.auth to
INSTALLED_APPS?
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: how can a test log in as a given user before calling client.get()?

2010-01-06 Thread Phlip
> Google cannot find any traffic on this topic, so I'm warming up the
> question here before researching it myself. If I figure out how to
> write login_as() for tests, I will post it here.

Do I always have to see the same hands??

from django.contrib.auth.models import User
hell_yeah = True

u = User.objects.create(username=u'admin', is_active=True,
email=u'ad...@admin.admin',
is_superuser=hell_yeah, is_staff=True,
password=u'sha1$e34de
$49632495b9ab78a54ff53a0d1145e2b9e8eb2af6')

self.client.login(username='admin', password='admin') # <--
the money line

self.get('/shop-admin/')  #  TODO  get should demand a 200

Some of you might see fit to put that User into a reusable (but test-
only) JSON file... to each her or his own.

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




auth unit tests fail because sites isn't used

2010-01-06 Thread msoulier
I can't find anywhere in the django docs where it says that
django.contrib.auth uses django.contrib.sites, but when I run my unit
tests I get this

==
ERROR: test_current_site_in_context_after_login
(django.contrib.auth.tests.views.LoginTest)
--
Traceback (most recent call last):
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/contrib/auth/tests/views.py", line 191, in
test_current_site_in_context_after_login
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/contrib/sites/models.py", line 22, in get_current
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/manager.py", line 120, in get
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/query.py", line 300, in get
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/query.py", line 81, in __len__
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/query.py", line 238, in iterator
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/sql/query.py", line 287, in results_iter
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/models/sql/query.py", line 2369, in execute_sql
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/db/backends/sqlite3/base.py", line 193, in execute
OperationalError: no such table: django_site

--
Ran 45 tests in 22.375s

FAILED (errors=1)

I don't need the sites app, but it looks like auth needs it. Is that
correct?

It would be nice to just supress this test from running...

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




how can a test log in as a given user before calling client.get()?

2010-01-06 Thread Phlip
Djangoids:

Google cannot find any traffic on this topic, so I'm warming up the
question here before researching it myself. If I figure out how to
write login_as() for tests, I will post it here.

The issue is, with the contrib/auth system turned on, client.get()
can't fetch a page; it redirects to the login page. Fair enough, but
tests have to run security-free (unless your administrators and
premium users like bugs). So what do I set into the "session", and how
do I add that to the .get(), to test a protected page?

Watch this space!

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




Re: Django, Apache, mod_wsgi, GET works, POST doesn't

2010-01-06 Thread Rob
Have you managed to figure this out - I'm having a similar (I believe
the same) issue.

On Jan 5, 6:27 am, Patrick May  wrote:
> Can you make it fail in the development server, with DEBUG turned on?
>
> If so, you can get more helpful error display and/or do pdb.set_trace() and
> poke around.
>
> I'll give that a try, thanks!
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Error when trying to connect to django_session

2010-01-06 Thread Mike
I am a newb to a this so please keep that in mind when reading this.
I am running Ubuntu 9.10, postgreSQL 8.4, psycopg2, Django 1.1.1, and
Apache 2.2.  Everything works fine until I go to authenticate then I
get an error.  I am trying to get the authentication piece to work by
using the canned template and I get the following traceback:

[Wed Jan 06 11:33:12 2010] [notice] caught SIGTERM, shutting down
[Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Compiled for Python/2.6.2.
[Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Runtime using Python/
2.6.4.
[Wed Jan 06 11:33:13 2010] [warn] mod_wsgi: Python module path '/usr/
lib/python2.6/:/usr/lib/python2.6/plat-linux2:/usr/lib/python2.6/lib-
tk:/usr/lib/python2.6/lib-old:/usr/lib/py$
[Wed Jan 06 11:33:13 2010] [notice] Apache/2.2.12 (Ubuntu) PHP/
5.2.10-2ubuntu6.3 with Suhosin-Patch mod_wsgi/2.5 Python/2.6.4
mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming no$
[Wed Jan 06 11:33:16 2010] [error] mod_wsgi (pid=22889): Exception
occurred processing WSGI script '/srv/Django/FDRAB_Intranet/apache/
django.wsgi'.
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line
245, in __call__
  response = middleware_method(request, response)
File "/usr/lib/pymodules/python2.6/django/contrib/sessions/
middleware.py", line 36, in process_response
  request.session.save()
File "/usr/lib/pymodules/python2.6/django/contrib/sessions/backends/
db.py", line 58, in save
  obj.save(force_insert=must_create)
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
410, in save
  self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line
470, in save_base
  manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by
())):
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
112, in __nonzero__
  iter(self).next()
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
106, in _result_iter
  self._fill_cache()
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
692, in _fill_cache
  self._result_cache.append(self._iter.next())
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line
756, in iterator
  for row in self.query.results_iter():
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
line 287, in results_iter
  for rows in self.execute_sql(MULTI):
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py",
line 2369, in execute_sql
  cursor.execute(sql, params)
File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line
19, in execute
  return self.cursor.execute(sql, params)
ProgrammingError: relation "django_session" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_session" WHERE
"django_sessio...

The most annoying part is that Django can write to the table in other
instances, but for some reason it fails when I try to authenticate.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Django/Apache/mod_wsgi: How do I specify the SCRIPT_NAME for non-root URLs?

2010-01-06 Thread Tyler Erickson
I am trying to use Apache and mod_wsgi to serve multiple django
sites.  The django sites are served up fine when at the root URL, but
when served from a sub-URL the portion of the the URL consumed by
Apache disappears from any links created in the django site pages.
>From reading throught the WSGI spec (http://www.wsgi.org/wsgi/
Specifications/routing_args), it appears that I need to specify the
SCRIPT_NAME environment variable, but I am not sure where I should do
that.  (The apache/django.wsgi file seemed like a logical place to set
the SCRIPT_NAME environment variable, but that seems to have no effect
on the generated URLs.)

Below is a description of my setup, and the apache and WSGI
configuration files.

- Tyler


OS: Ubuntu 9.04
django: 1.1 SVN-11733
apache: 2.2.11-2ubuntu2.3
libapache2-mod-wsgi: 2.3-1build1


#
Apache configuration file (default)
#

ServerAdmin webmas...@localhost

###
# Configuration for the olwidget test project
###
Alias /olwidget/site_media/ "/usr/local/olwidget/trunk/olwidget/
django-olwidget/test_project/site_media/"

Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing


Alias /olwidget/media/ "/usr/local/lib/python2.6/dist-packages/
django/contrib/admin/media/"

Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing


WSGIScriptAlias /olwidget /usr/local/olwidget/trunk/olwidget/
django-olwidget/test_project/apache/django.wsgi

Order deny,allow
Allow from all


###
# Configuration for WFEIS
###
Alias /wfeis/site_media/ "/usr/local/django_nasa_fire_dss/
site_media/"

Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing


Alias /wfeis/media/ "/usr/local/lib/python2.6/dist-packages/django/
contrib/admin/media/"

Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing


WSGIScriptAlias /wfeis /usr/local/django_nasa_fire_dss/apache/
django.wsgi

Order deny,allow
Allow from all





#
Example WSGI configuration file
(/usr/local/olwidget/trunk/olwidget/django-olwidget/test_project/
apache/django.wsgi)
#
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'
os.environ['SCRIPT_NAME'] = 'olwidget'
# append the django project root directory to the python path
sys.path.append('/usr/local/olwidget/trunk/olwidget/django-olwidget')
sys.path.append('/usr/local/olwidget/trunk/olwidget/django-olwidget/
test_project')
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




how relate webpage with databse in my harddisk?

2010-01-06 Thread gintare
Hello,

Sorry for a simple question.

How other can access pages i generated with django?
How others could be able to fill forms and get data from my hard disk
through generated html interface?

I am connecting and filling database by myself in folder  /mano/
mysite1.
I would like to connect to generated html pages through internet from
remote computer, fill questionaries and leave or get data to/from
database.

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




Re: Got Django and Buildout working, but what about PIL and Postgres?

2010-01-06 Thread Kevin Teague
This is what I use for PostgreSQL and psycopg2 installation with
Buildout:

First, adjust the eggs to pull-in a custom-built psycopg2 egg:

eggs = ${psycopg2:egg}
   ${buildout:eggs}

Then for psycopg2 do:

[psycopg2]
recipe = zc.recipe.egg:custom
egg = psycopg2
include-dirs = ${postgresql:location}/include
library-dirs = ${postgresql:location}/lib

The ${postgresql:location} can alternately be pointed to an existing
PostgreSQL install. Or I sometimes use a ${shared-location:path} which
I set in my ~/.buildout/default.cfg file if I have a lot of different
apps and don't want a zillion different PostgreSQL installs. Or you
can install PostgreSQL with the 'configure; make; make
install;' (CMMI) recipe:

[postgresql]
recipe = zc.recipe.cmmi
url =
http://wwwmaster.postgresql.org/redir/198/h/source/v8.3.7/postgresql-8.3.7.tar.gz
extra_options =
  --with-readline

And initialize a PostgreSQL database with:

[init-pgsql]
recipe = iw.recipe.cmd
on_install = true
on_update = false
cmds =
  ${postgresql:location}/bin/initdb -D ${postgresql:location}/var/data
-E UNICODE

And create a suite of symlinks to make the PostgreSQL commands
available in your project's ./bin directory with:

[pgsql-symlinks]
recipe = cns.recipe.symlink
symlink_target = ${buildout:directory}/bin
symlink_base = ${postgresql:location}/bin
symlink =
  clusterdb
  createdb
  createlang
  createuser
  dropdb
  droplang
  dropuser
  ecpg
  initdb
  ipcclean
  pg_config
  pg_controldata
  pg_ctl
  pg_dump
  pg_dumpall
  pg_resetxlog
  pg_restore
  postgres
  postmaster
  psql
  reindexdb
  vacuumdb

Finally, you need to add a find-links pointing to a place where the
psycopg2 package can be found, since it hasn't actually been released
on PyPI (arg!):

[buildout]
find-links = http://initd.org/pub/software/psycopg/PSYCOPG-2-0/

And for the time being, pin psycopg2 back down to version 2.0.8. This
is because the newer versions prefer a build_ext option pointing to
the 'pg_config' binary, but zc.recipe.egg currently doesn't support
this (a feature enhancement for this recipe which I haven't yet gotten
around to writing, since 2.0.8 works fine for me current needs):

[versions]
psycopg2 = 2.0.8

It can be quite a bit of config-ery, but when you get a complete
working web app with a full database from a single one-push button
install, it's a beautiful thing :)
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Exiting Postgresql user to Django App user

2010-01-06 Thread Christophe Pettus


On Jan 5, 2010, at 11:10 PM, Rama wrote:

I would like to use existing postgresql users with my django app, I
wonder is there any solutions already available with django...


I assume you mean something along the lines of, "I would like to map  
the user logins on my Django site to PostgreSQL database roles."


The bad news: There's nothing built in, and Django always connects as  
the role specified in the DATABASE_USER variable in settings.py


The good news: It's not hard to implement.

Here's one approach:

+ Create a user that will serve as the initial role when the  
application connects to the database, and set that in DATABASE_USER.


+ Once the Django user has been established, use the raw SQL interface  
to send a SET ROLE command to the server for the appropriate role.   
This could be done in a middleware layer.


There are some things to think about here:

The initial role will need to have the right privileges to do the SET  
ROLE, so there's a potential security problem there.


SET ROLE does not assign session variables that were set to the role  
with ALTER ROLE, so things like the schema search path (if you are  
using it) won't be available.

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

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




Re: error using memcache and filter()

2010-01-06 Thread Subramanyam
Thanks a LOT !! Frank

Further to your analysis I checked the following
http://docs.djangoproject.com/en/dev/topics/serialization/#serializing-dataand
understood from the note (rather my understanding ) that only .all()
query set method  would give the serialized data

if we want .filter () ( or any other queryset methods didn`t check them all
)  we have to serialize/de-serialize the queryset

Did the following and it worked

from django.core import serializers
cache.set('test1',serializers.serialize("json",User.objects.filter(is_staff=False)[0:10]))

there on I deserialize again to get the objects back


Thanks again !!


Regards
Subramanyam


On Wed, Jan 6, 2010 at 8:42 AM, Frank DiRocco  wrote:

> 'yam,
>
> I have not seen this error, but my responses to the error are inline.
>
>
> On Jan 6, 2010, at 6:30 AM, Subramanyam wrote:
>
>  File "/home/bvemu/lib/python2.6/site-packages/django/core/cache/
>> backends/memcached.py", line 37, in set
>>   self._cache.set(smart_str(key), value, timeout or
>> self.default_timeout)
>>
>
> So it appears your issue originates when you call cache.set(key,user_list)
>
>
>   File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
>> py2.6.egg/memcache.py", line 515, in set
>>   return self._set("set", key, val, time, min_compress_len)
>>  File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
>> py2.6.egg/memcache.py", line 725, in _set
>>   store_info = self._val_to_store_info(val, min_compress_len)
>>  File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
>> py2.6.egg/memcache.py", line 697, in _val_to_store_info
>>   pickler.dump(val)
>> PicklingError: Can't pickle > 'django.utils.functional.__proxy__'>: attribute lookup
>> django.utils.functional.__proxy__ failed
>>
>
> But from these last three lines you can deduce that "Can't pickle" is
> telling you the object is not unserializable (only in the failing case). So,
> when we reflect back on the point at which you populated the val you passed
> to the cache backend you will probably find:
>
>
>  user_list=User.objects.all()[0:10]

>>>
> produces a list of objects that are serializable (ie, your superuser
> account)
>
> and
>
>
>  user_list=User.objects.filter(is_staff=False)[0:10]

>>>
> is returning an unserializable value possibly? (although pickle.dump([],
> some_object) succeeds, serializing an empty list)
>
> I would have to say it seems like you are passing unexpected data to the
> cacher that is not being validated as serializable and the pickler is
> failing to serialize the invalid data. But this is, just a guess...
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Exiting Postgresql user to Django App user

2010-01-06 Thread Daniel Roseman
On Jan 6, 7:10 am, Rama  wrote:
> Hi
> I would like to use existing postgresql users with my django app, I
> wonder is there any solutions already available with django...
>
> Please let me know.

You don't need, or want, to do this. Django connects to the database
as a single user, whose credentials are set in settings.py.

Access to your web app should be a completely separate issue to access
to your database.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Exiting Postgresql user to Django App user

2010-01-06 Thread Bill Freeman
Have you tried setting DATABASE_USER in settings.py to the desired user?

On Wed, Jan 6, 2010 at 2:10 AM, Rama  wrote:
> Hi
> I would like to use existing postgresql users with my django app, I
> wonder is there any solutions already available with django...
>
> Please let me know.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Got Django and Buildout working, but what about PIL and Postgres?

2010-01-06 Thread Masklinn
On 6 Jan 2010, at 16:43 , Masklinn wrote:
> 
> * PIL shouldn't be needed if you use buildout correctly
And I read PIL but thought PIP, disregard this.


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




Re: Securing Django Installation - file permissions?

2010-01-06 Thread Daniel Hirsch
Thank you for the response Daniel. That was more-or-less what I
*thought* but it was great to be able to pass the information on to
him from a 3rd party. That said, is there anything I should be doing
from a practical standpoint as far as setting file permissions in my
project directories? Things that should be locked down or should not
be?

On Jan 5, 3:30 pm, Daniel Roseman  wrote:
> On Jan 5, 11:12 pm, Daniel Hirsch  wrote:
>
>
>
>
>
> > Hi everyone,
>
> > We just launched our first django application into production and my
> > server admin is hounding me about its security. He claims that python
> > is vulnerable to scripting by the URL, which I quite honestly have no
> > clue about.
>
> > So, my question to you is two-fold:
>
> > 1 - What are the likely and potential vulnerabilities of a django
> > installed running under mod_wsgi on Apache on Red Hat Enterprise?
> > 2 - What the best practices for securing a installation?
>
> > I've searched the documentation and didn't find much mention of any of
> > this, so if there is a good source, please point me to it and I'll be
> > out of your hair.
>
> > Much appreciated!
>
> > Daniel Hirsch
>
> Your sysadmin doesn't sound like he knows what he's talking about,
> unfortunately.
>
> Firstly, none of the Python code - either Django or your app - should
> be in the server root or anywhere that Apache serves. mod_wsgi doesn't
> run arbitrary Python files depending on the URL, as your sysadmin
> seems to think, but dispatches URLs to a separate long-running
> process. If hackers are able to gain access to your server, install
> malicious Python files in an area not accessible by Apache, and then
> change the WSGI application or the Django URLconf to run them, then to
> be honest you have problems that are well beyond Django's
> responsibility.
>
> Perhaps he is under the mistaken impression that Django is some sort
> of CGI app?
> --
> DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Saving several copies of an object

2010-01-06 Thread pjmorse
On Jan 5, 1:11 pm, Matthias Kestenholz 
wrote:
> This won't do it, because ns is a Form, not a Model object. Something
> like this might work though:
>
> obj = ns.save(commit=False)
>
> for language in languages:
>     obj.id = None
>     obj.language = language
>     obj.save()
>
> Matthias

Thanks, Matthias, that does work.

Noting Daniel's comment, here's what the original code looked like:

languages = Language.objects.all()

for language in languages:
"""add required fields"""
nsForm.cleaned_data['news'] = news_obj
nsForm.cleaned_data['language'] = language
nsForm.cleaned_data['news_date'] = datetime.now()
if language == user.language:
nsForm.cleaned_data['translated'] = True
else:
nsForm.cleaned_data['translated'] = False
nsForm.save()

Following Matthias' example and taking some redundant code out of the
loop, here's the code that worked:

"""add required fields"""
nsForm.cleaned_data['news'] = news_obj
nsForm.cleaned_data['news_date'] = datetime.now()
languages = Language.objects.all()
obj = nsForm.save(commit=False)

for language in languages:
obj.id = None
obj.language = language
if language == user.race.language:
obj.translated = True
else:
obj.translated = False
obj.save()

Thanks again, everyone.

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




Re: Got Django and Buildout working, but what about PIL and Postgres?

2010-01-06 Thread Reinout van Rees

On 01/06/2010 04:23 PM, littlejim84 wrote:


Can anyone help me to reliably get PIL and Postgres working with my
Buildout? Thank you so much in advance... Everything I've tried so far just
throws up all sorts of errors.


Add the lines marked with '<<<' behind them to your buildout to 
*probably* solve the PIL issue.


* The find-links line points at a specially-stripped PIL download used 
by for instance Plone.  It is stripped of the 'tk' stuff, which helps a 
lot with the common PIL compilation errors.


* The versions lines are needed to pin PIL to 1.1.6 as 1.1.7 is just 
out: this has several problems, at least in buildouts I saw.



[buildout]
parts = python django
develop = .
eggs = myproject
find-links = http://dist.repoze.org/   <<<
versions = versions<<<

[versions] <<<
PIL = 1.1.6<<<

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[django]
recipe = djangorecipe
version = 1.1.1
project = myproject
projectegg = myproject
settings = testsettings
test = myproject
eggs = ${buildout:eggs}



Reinout

--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer/advisor at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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




Re: Got Django and Buildout working, but what about PIL and Postgres?

2010-01-06 Thread Masklinn
On 6 Jan 2010, at 16:23 , littlejim84 wrote:
> 
> Hello. I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on
> setting up Django with Buildout:
> http://jacobian.org/writing/django-apps-with-buildout/
> 
> Finally, I have got this Buildout to work! ...but I'm now needing PIL and
> Postgres for a complete isolated Django development area. I've tried to
> modify my buildout.cfg with tutorials I've read around the internet, but
> just can't find how to do it without it throwing up all sorts of errors. I
> feel PIL and Postgres are the next things to complete this little setup, so
> I can just get on with it... (I'm not an expert at any of this by the way, I
> come from a PHP background). My current buildout.cfg looks like this:
> 
> [buildout]
> parts = python django
> develop = .
> eggs = myproject
> 
> [python]
> recipe = zc.recipe.egg
> interpreter = python
> eggs = ${buildout:eggs}
> 
> [django]
> recipe = djangorecipe
> version = 1.1.1
> project = myproject
> projectegg = myproject
> settings = testsettings
> test = myproject
> eggs = ${buildout:eggs}
> 
> Can anyone help me to reliably get PIL and Postgres working with my
> Buildout? Thank you so much in advance... Everything I've tried so far just
> throws up all sorts of errors.


Can't really help you, but I have two things:
* For Postgres, psycopg2 installs fine using pip, but *you need to have the 
Postgres tools on your $PATH*
* PIL shouldn't be needed if you use buildout correctly (with the dependency 
list thingy), that would – I think – be redundant.-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Got Django and Buildout working, but what about PIL and Postgres?

2010-01-06 Thread littlejim84



Hello. I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on
setting up Django with Buildout:
http://jacobian.org/writing/django-apps-with-buildout/

Finally, I have got this Buildout to work! ...but I'm now needing PIL and
Postgres for a complete isolated Django development area. I've tried to
modify my buildout.cfg with tutorials I've read around the internet, but
just can't find how to do it without it throwing up all sorts of errors. I
feel PIL and Postgres are the next things to complete this little setup, so
I can just get on with it... (I'm not an expert at any of this by the way, I
come from a PHP background). My current buildout.cfg looks like this:

[buildout]
parts = python django
develop = .
eggs = myproject

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[django]
recipe = djangorecipe
version = 1.1.1
project = myproject
projectegg = myproject
settings = testsettings
test = myproject
eggs = ${buildout:eggs}

Can anyone help me to reliably get PIL and Postgres working with my
Buildout? Thank you so much in advance... Everything I've tried so far just
throws up all sorts of errors.

-- 
View this message in context: 
http://old.nabble.com/Got-Django-and-Buildout-working%2C-but-what-about-PIL-and-Postgres--tp27026890p27026890.html
Sent from the django-users mailing list archive at Nabble.com.

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




building a multi lingual website

2010-01-06 Thread mikeymor
Hello all,
i'm new to django and wrote several test applications, so far it feels
like falling in love.
i tried to write a test project with multi lingual support, and found
several  good examples.
however once i try to do it in my project it doesn't work.
this is my models.py code:
class Language(models.Model):
code = models.CharField(max_length=5)
name = models.CharField(max_length=16)
def __str__(self):
return self.name

class BookTranslation(models.Model):
language = models.ForeignKey("Language")
title = models.CharField(max_length=32)
description = models.TextField()
model = models.ForeignKey("Book")

class Book(multilingual.MultilingualModel):
ISBN = models.IntegerField()
class Meta:
translation = BookTranslation
multilingual = ['title', 'description']



and for some reason, it doesn't create tables in the MYSQL DB  no
error is given.
i should mention that all parameters check out, and if i remove the
multilingual code and just write normal classes everything works.
is there something i need to install ?

any help will be appreciated.

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




Queryset |-ing and joins

2010-01-06 Thread Daniel Pope
I have encountered a problem with joins in Django's ORM. I had assumed
that

queryset.filter(**a) | queryset.filter(**b)

is functionally equivalent to

queryset.filter(models.Q(**a) | models.Q(**b))

for all a and b. That is not what is happening. If my assumption is
not true, then what are the intended semantics for the first form? If
my assumption is correct, then this must be a bug in Django.

The code I'm using, and the generated SQL from ._as_sql() is below.

Tags are many-to-many with Projects, Projects are many-to-many with
Profiles in two separate maps: teammembers and investigators. Profiles
are also many-to-many with Tags in two separate maps, an include
(profiles_watching) and an exclude (profiles_ignoring) map. The query
is to find Tags linked via Projects to a Profile, plus those that are
directly included and not those directly excluded. 'self' is a
models.Manager for research.Tag.

The first form is the original version that omits some of the results
I'm expecting to see.

of_interest_automatic = (
self.filter(project__teammembers=profile) |
self.filter(project__investigators=profile)
).distinct()
return (
of_interest_automatic |
self.filter(profiles_watching=profile).distinct()
).exclude(profiles_ignoring=profile).distinct()

(of_interest_automatic is actually a separate method, which is why
distinct() is repeated)

('SELECT DISTINCT U0.`id` FROM `research_tag` U0 INNER JOIN
`research_project_tags` U1 ON (U0.`id` = U1.`tag_id`) INNER JOIN
`research_project` U2 ON (U1.`project_id` = U2.`id`) LEFT OUTER JOIN
`research_project_teammembers` U3 ON (U2.`id` = U3.`project_id`) LEFT
OUTER JOIN `research_project_investigators` U5 ON (U2.`id` =
U5.`project_id`) LEFT OUTER JOIN `people_profile_tags_include` U6 ON
(U0.`id` = U6.`tag_id`) WHERE ((U3.`profile_id` = %s  OR
U5.`profile_id` = %s  OR U6.`profile_id` = %s ) AND NOT (U0.`id` IN
(SELECT U1.`tag_id` FROM `people_profile_tags_exclude` U1 WHERE
U1.`profile_id` = %s )))', (287, 287, 287, 287))

This is how I have rewritten it

return self.filter(
Q(project__teammembers=profile) |
Q(project__investigators=profile) |
Q(profiles_watching=profile)
).exclude(profiles_ignoring=profile).distinct()

('SELECT DISTINCT U0.`id` FROM `research_tag` U0 LEFT OUTER JOIN
`research_project_tags` U1 ON (U0.`id` = U1.`tag_id`) LEFT OUTER JOIN
`research_project` U2 ON (U1.`project_id` = U2.`id`) LEFT OUTER JOIN
`research_project_teammembers` U3 ON (U2.`id` = U3.`project_id`) LEFT
OUTER JOIN `research_project_investigators` U5 ON (U2.`id` =
U5.`project_id`) LEFT OUTER JOIN `people_profile_tags_include` U7 ON
(U0.`id` = U7.`tag_id`) WHERE ((U3.`profile_id` = %s  OR
U5.`profile_id` = %s  OR U7.`profile_id` = %s ) AND NOT (U0.`id` IN
(SELECT U1.`tag_id` FROM `people_profile_tags_exclude` U1 WHERE
U1.`profile_id` = %s )))', (287, 287, 287, 287))

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




Re: error using memcache and filter()

2010-01-06 Thread Frank DiRocco

'yam,

I have not seen this error, but my responses to the error are inline.

On Jan 6, 2010, at 6:30 AM, Subramanyam wrote:


File "/home/bvemu/lib/python2.6/site-packages/django/core/cache/
backends/memcached.py", line 37, in set
   self._cache.set(smart_str(key), value, timeout or
self.default_timeout)


So it appears your issue originates when you call cache.set 
(key,user_list)



 File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 515, in set
   return self._set("set", key, val, time, min_compress_len)
 File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 725, in _set
   store_info = self._val_to_store_info(val, min_compress_len)
 File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 697, in _val_to_store_info
   pickler.dump(val)
PicklingError: Can't pickle : attribute lookup
django.utils.functional.__proxy__ failed


But from these last three lines you can deduce that "Can't pickle" is  
telling you the object is not unserializable (only in the failing  
case). So, when we reflect back on the point at which you populated  
the val you passed to the cache backend you will probably find:



user_list=User.objects.all()[0:10]


produces a list of objects that are serializable (ie, your superuser  
account)


and


user_list=User.objects.filter(is_staff=False)[0:10]


is returning an unserializable value possibly? (although pickle.dump 
([], some_object) succeeds, serializing an empty list)


I would have to say it seems like you are passing unexpected data to  
the cacher that is not being validated as serializable and the pickler  
is failing to serialize the invalid data. But this is, just a guess...


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




Re: Django-Admin filter on 'backwards' foreign key

2010-01-06 Thread tback
Hi Shawn, thanks for your help anyway! Anyone else?

Till Backhaus

On Jan 5, 4:02 pm, Shawn Milochik  wrote:
> Sorry, I completely missed the part of the question where you said you wanted 
> to do it in the Django Admin. That I don't know about.
>
> Shawn
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-06 Thread koenb

On 31 dec 2009, 01:56, Sam Walters  wrote:
> Thanks for the replies.
>
> Yes, there is the option of going to raw MySQL. However the project
> requirements mean i can't use raw SQL. (portability, readability)
> From what i can see using django's db API i have to execute the
> queries 500 times.
> I am very familiar with the query documentation and i know that
> select_related will prevent foward facing foreign keys translating to
> an individual sql queries which hit the db and would slow it down.
>
> Fact is even when i dont use 'select_related' the major performance
> problem occurs with the 'many-to-many' and 'reverse foreign' keys
> (some 75% of the performance penalty for my package method is with
> these) and only 20% can be solved by select_related.
>
> To be specific about how the multiplicities unfold:
>
> search_querySet is a Directory.objects.filter(...
>
> for s in search_querySet:
>         address_info = s.address_set.all() #.select_related(depth=2) -
> yes i can/will put select related here but it really does not help
> that much 20% tops
>         #address_info is usually 2-3 rows from an address table
>         for a in address_info:#.select_related(depth=2):
>             if a.addresstype.adrtype == 'Physical' and
> a.addradmin.addr_enabled == True:
>             #further reduction in the number of rows which we need to
> get values from.
>             related_phone=a.phone_set.all()
>             related_email=s.email_set.all()
>             #phones and emails are a small number of rows 2-3 tops
>
> It is these lines which produce the performance hit.
> I cant see a way of using django's query language to avoid having to
> descend into each of the 500 'directory' objects because of the
> necessity to get all rows from the related tables in phones an emails
> and to inspect the type of 'address' object.
>
> thanks for the ideas. will continue testing and looking for answers
>
> -Sam
>
> On Thu, Dec 31, 2009 at 2:41 AM, Nick Arnett  wrote:
>
> > On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford 
> > wrote:
>
> >> I'm not an expert on this, but a few thoughts.
>
> >> First, if I'm reading your message right, it sounds like your problem
> >> probably isn't with the query, but with how many times you're running
> >> it.
>
> > I'll echo that... the problem is not the database - the queries are as good
> > as it gets.  The problem is running them repeatedly.
>
> > If all else fails, I'd replace those queries that execute 500 times with raw
> > SQL that uses the IN operator to get the required rows.
>
> > E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
> > `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173)
>
> > I imagine there's an ORM query that will do the same thing, but I know MySQL
> > far better than I know Django.
>
> > Nick
>

You can take a look at apps like django-selectreverse [1] or django-
batch-select [2] for some ideas to make this kind of optimisations
easier.

Koen

[1] http://code.google.com/p/django-selectreverse/
[2] http://github.com/lilspikey/django-batch-select
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




hi.. supress the flatpages' fields' help texts

2010-01-06 Thread Ali Rıza Keleş
Hi all,

How can I supress help_texts of flatpages' fields without modifying core
code of django contrib. 

Thanks.

--
Ali Rıza Keleş


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




error using memcache and filter()

2010-01-06 Thread Subramanyam
Hi

I am using memcached for caching objects , but am stuck with the
following

When I use the .all() method it works fine
>> from django.core.cache import cache
>>> user_list=User.objects.all()[0:10]
>>> key='userlist'
>>> cache.set(key,user_list)


But when I use .filter() method I get the following error

>>> user_list=User.objects.filter(is_staff=False)[0:10]
>>> key='userlist'
>>> cache.set(key,user_list)
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/bvemu/lib/python2.6/site-packages/django/core/cache/
backends/memcached.py", line 37, in set
self._cache.set(smart_str(key), value, timeout or
self.default_timeout)
  File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 515, in set
return self._set("set", key, val, time, min_compress_len)
  File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 725, in _set
store_info = self._val_to_store_info(val, min_compress_len)
  File "/home/bvemu/lib/python2.6/site-packages/python_memcached-1.45-
py2.6.egg/memcache.py", line 697, in _val_to_store_info
pickler.dump(val)
PicklingError: Can't pickle : attribute lookup
django.utils.functional.__proxy__ failed


please let me know if anyone has seen the error before


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




Re: Saving several copies of an object

2010-01-06 Thread Simon Brunning
2010/1/5 pjmorse :
> It's a multi-language site: US, UK, DE. (Why US and UK are considered
> different languages is organizational politics beyond the scope of my
> work.)

UK and US English are enormously similar, but there are real
differences in vocabulary (e.g. lift versus elevator, bin versus trash
can), spelling (e.g. colour versus color), punctuation (e.g. with the
placement on puctuation in relation to quote marks), and occasionally
even grammar ("my bank are dreadful" versus "my bank is dreadful").

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




Re: constraints fail importing data

2010-01-06 Thread Antoni Aloy
You have to check the constraints in table of course. There is no
information we can use to help you sorry.

2010/1/6 shaner 

> INSERT INTO table (col1,col2) SELECT col1,col2 FROM table2
>
> is what i'm trying do, copy some columns from one table to one in
> django, i get constraints failed
>
> i made a test db and tested this and worked, copied the two columns to
> another table fine, also tried recreating the model w/ blank=true and
> null=true figuring maybe some of my other columns were requiring
> something
>
> anyone know what's up here?
>
>
-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net
-- 

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Re: Combining columns coming from 2 tables

2010-01-06 Thread Antoni Aloy
2010/1/5 fredlab 

> Hey,
>
> My question is probably very simple. Below, my simplified model :
>
> I have a table of stock items in stock (item_code, item_title,
> property1, property2, storeroom, quantity_available)
> I have a table listing transaction of items (transaction_id,
> item_code, transaction_type, transaction_quantity, transaction_date)
>
> I succeed to be able to view all data for each model using django
> admin but it does not satisfy me. I want to be able in the transaction
> admin view to list columns from the transaction table as well as
> columns from the storeroom table) :
>
> I want to show the following in the transaction admin view :
>
> transaction_id, item_code, item_title, transaction_type,
> transaction_quantity, property1, property2
>
> Any idea how to get such result ?
>
> Note that I investigated one way consisting of creating function to
> define properties and get values of property 1 and so on. The problem
> then is that I cannot order the list or filter based on the property1
> or property 2 for example.
>
> In advance, thanks for the help.
>
>
You can't use the admin as is to do that. You could write you own form, you
own display data etc. but in my oppinion is too much effor. Perhapts the
easy way is to write a separate page, link in the admin and try to make the
dessing to much as much as possible. You have to be prepared to write your
own filter, sort methods etc.


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

You received this message because you are subscribed to the Google Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.

To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



Exiting Postgresql user to Django App user

2010-01-06 Thread Rama
Hi
I would like to use existing postgresql users with my django app, I
wonder is there any solutions already available with django...

Please let me know.

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




pickle error in DecimalField

2010-01-06 Thread Akash
I am using DecimalField in django table for pricing.  It works fine
sometimes but sometimes it throws an Pickle error (PicklingError:
Can't pickle : it's not the same object as decimal.Decimal).
I am importing decimal module in views also.
Have anyone encountered this issue? Can anyone help on this?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: use of @vary_on_cookie decorator with URLconf based cache_page usage

2010-01-06 Thread Victor Lima
Off topic side note: beware if you use vary on cookie and google  
analytics, since analytics cookies changes a lot you are actually  
caching views per analytics cookie change... That bugged us for a  
while in our project.


Att,
Victor Lima

Em 05/01/2010, às 21:32, Justin L  escreveu:


For several months, we have been caching views using the URLconf
method (urls.py). An entry from urls.py is below as an example:

url(r'^(?P.*)/content/(?P[-\w]+)/$$', cache_page
(hierarchies.views.category_content_detail, CACHE_TIMEOUT),
name='category_content_detail'),

Recently, we had a need to add variance of cache based on cookie value
to support some personalization features. After reading the django
docs, it seemed easy enough to add the @vary_on_cookie decorator to
appropriate views.

@vary_on_cookie
def category_content_detail(request, path, id):
..
..

What I've noticed, is that since adding this vary decorator, the page
is no longer caching, as seen by monitoring logs and seeing many
backend processes firing which normally do not fire when the page is
cached.

Any ideas on why I'd see this behavior? My browser is setting the
cookie value appropriately, as I've monitored in Firebug, but I'm just
not seeing any sort of caching taking place. Upon removing the
vary_on_cookie decorator, caching returns to normal.

What I have noticed in testing is this. If I go back to a pure pre-
view cache setup:

@vary_on_cookie
@cache_page(60 * 15)
def category_content_detail(request, path, id):

Is there a way to use vary_on_cookie with the URLconf like setup? I
like the flexibility of the URLConf method and but also need the vary
features.

Reference:
http://docs.djangoproject.com/en/dev/topics/cache/#specifying-per-view-cache-in-the-urlconf
--
You received this message because you are subscribed to the Google  
Groups "Django users" group.

To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en 
.



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




Re: problems deserializing json object

2010-01-06 Thread Daniel Roseman
On Jan 6, 1:54 am, Malcolm MacKinnon  wrote:
> I'm having difficulty deserializing a json object. I'm using django
> appengine patch, so the models aren't the same as django's, but they are
> very similar:
>
> class Cust(db.Model):
>     custno = db.StringProperty(required=True)
>     company = db.StringProperty(required=True)
>     contact = db.StringProperty(required=False)
>     address1 = db.StringProperty(required=False)
>     address2 = db.StringProperty(required=False)
>     city = db.StringProperty(required=True)
>     state = db.StringProperty(required=False)
>     zipc = db.StringProperty(required=False)
>     country = db.StringProperty(required=False)
>     phone = db.StringProperty(required=False)
>     salesmn = db.StringProperty(required=True)
>     email = db.StringProperty()
>
>     def __unicode__(self):
>         return self.custno + " : " + str(self.company)+" :
> "+str(self.city)+" : "+str(self.state)

Aargh! unicode methods must return unicode! Not bytestrings! Do this:
return u'%s: %s: %s: %s' % (self.custno, self.company, self.city,
self.state)


>
> class Cust_List(db.Model):
>     custno = db.StringProperty(required=True)
>     companies = db.TextProperty(required=True) #customer list as json object
>
> Note that the json object is stored in the db.TextProperty companies, and is
> composed of more than a 1000 customers, all of which are also individually
> stored in the model, Cust . I query the json object for a customer list,
> since it saves CPU time on the appengine.
>
> Here's what happens when I try to decode the json string object:>>> from 
> sport.models import Cust_List
> >>> from django.core import serializers
> >>> a=Cust_List.all()
> >>> b=a.get() #returns the only and only data item in this model, which is a
>
> json object previously stored in the datastore.>>> 
> c=serializers.deserialize('json', b.companies)
> >>> d=list(c)
> >>> e=len(d)
> >>> e
> 1057
> >>> b
>
> etc...
> cy...@global.net", "phone": "269/552-", "state": "MN", "contact": "Rick
> L
> ee", "salesmn": "O1", "country": "", "address2": ""}}, {"pk": "XBwTAxc
> hELEgpzcG9ydGNUYDA", "model": "sport.cust", "fields": {"city": "GOLD RIVE
> R", "zipc": "95670", "address1": "11282 PYRITES WAY", "company": "ZSPORTS",
> "cus
> tno": "ZSP001", "email": "ra...@zsports.com", "phone": "916/638-0033", "sta
> te": "CA", "contact": "Randy Mintz", "salesmn": "H1", "country": "",
> "address2":
>  ""}}]')>>> d
>
> etc...
>  ,
>  edObject: WAT091 : WATERVILLE VALLEY RESORT : WATERVILLE VALLEY : NH>,
>  izedObject: WES003 : WESTCHESTER ROAD RUNNER : WHITE PLAINS : NY>,
>  Object: WES100 : WEST HILL SHOP : PUTNEY : VT>,  : WH
> EELIE FUN MULTI SPORT : LEBANON : OH>,  WHIRLAWAY S
> PORTS CTR : METHUEN : MA>,  TOURING
>  : DAVIS : WV>,  WHIS
> TLER, BC : >,  CO>,  eserializedObject: WIL520 : WILD ROSE MOUNTAIN SPORTS : SALT LAKE CITY :
> UT>,  eserializedObject: WIL659 : ADVENTURE OUTFITTERS : HADLEY : MA>,
>  ject: WIL760 : WILDERNESS WAY, INC : SOLDOTNA : AK>,  WIL9LA
>  : WILSON BACKCOUNTRY : WILSON : WY>,  MOUNT
> AIN SPORTS : LAKE LOUISE, ALBERTA : >,  WILDERNESS
> SPORTS-DILLON : DILLON : CO>,  MOUNTAIN SP
> ORTS : WINTHROP : WA>,  LAKE C
> ITY : UT>,  DE>
> ,  : V
> T>, ,
>  erializedObject: WOR059 : WORLD CYCLE : BOISE : ID>,  YEL017
>  : YELLOWSTONE GATEWAY SPORTS : BOZEMAN : MT>,  ZAP
> POS.COM : HENDERSON : NV>,  PALO AL
> TO : CA>,  MI>
> , ] etc.
>
> Note that I just get returned a unicode representation of my model, Cust.
> But the contact information, address information, and so on disappears in
> the deserialized object. Any thoughts on why or what I'm doing wrong?
>
> Thanks for any help or ideas!
>
You're not getting a unicode representation, you're getting a
DeserialzedObject. As the documentation (http://docs.djangoproject.com/
en/1.1/topics/serialization/#deserializing-data) says, you need to
iterate through the list of objects and call save() on each one to
create the actual model.
--
DR.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.