Re: Emergency: Critical form error on medium-volume site

2010-09-20 Thread intrepidweb
Thank you so much, Xavier. I think that's it. A while ago I checked my
template tags for thread safety, but somehow I missed one of them that
deals with form formatting. I will let you know if the problems
reappears.

All the best,
Leif


On Sep 20, 10:09 am, Xavier Ordoquy <xordo...@linovia.com> wrote:
> Hi,
>
> Are you sure you don't get a thread safety issue ?
> Do you have your own template tags for those forms ?
>
> Regards,
> Xavier.
>
> Le 20 sept. 2010 à 18:42, intrepidweb a écrit :
>
>
>
> > Hi all,
>
> > Last week I ported a site that gets 50k+ pageviews/day from a PHP/
> > mySQL stack to Django/Postgresql. It has gone mostly smoothly, all
> > things considered. However, I have encountered a VERY troubling bug
> > involving the forms module, and I can't figure it out.
>
> > The form in question allows users to edit their profile. We have
> > several types of users, and each user type has a core set of fields,
> > as well as a few unique ones. Rather than write each profile edit form
> > from scratch, they inherit from parent classes.
>
> > The profile edit form accepts a User instance in its __init__ method,
> > and uses that object to populate the initial data, and also to save
> > the cleaned data to the appropriate User and UserProfile instances.
>
> > The problem is in about 20% of the time, the form, when displayed on a
> > page, is displaying OTHER users' information as the initial data. I
> > have determined that this is not a page caching issue. Additionally, I
> > confirmed that the correct user object is being passed to the form
> > class. So the form instance itself is switching the user object. My
> > guess is that somehow the user object is being assigned as a class
> > attribute, not an instance attribute. But otherwise I am stumped.
>
> > Here are snippets of the code. I know the inheritance scheme seems a
> > bit convoluted, but it was written this way in the name of DRY. Any
> > help would be greatly appreciated.
>
> > Leif
>
> > #
>
> > class PostalCodeForm (forms.Form):
> >    country = forms.ChoiceField(choices=[(c.country_code,c.en_name) for c
> > in Country.objects.all()],required=True, label='Country')
> >    postal_code = forms.CharField(required=True, label="ZIP/postal code")
>
> >    def clean_country (self):
> >            ...
>
> >    def clean_postal_code (self):
> >            ...
> > 
>
> > class UserProfileEditFormBase (forms.Form):
> >    first_name = custom_fields.NoProfanitiesCharField(max_length=150,
> > help_text = 'Your real first name. We will keep it private.')
> >    last_name = custom_fields.NoProfanitiesCharField(max_length=150,
> > required=False, help_text = 'Your real last name. We will keep it
> > private.')
> >    display_name = custom_fields.NoProfanitiesCharField(max_length=40,
> > help_text="Your public screenname. Will be shown on reviews that you
> > write, comments, etc.", label="Display name")
> >    email = custom_fields.EmailField()
> >    gender = forms.models.ModelChoiceField(queryset=Gender.objects.all(),
> > empty_label=None)
>
> >    def __init__ (self, user, *args, **kwargs):
> >            kwargs.setdefault('initial',{})
> >            kwargs['initial'] = self.get_initial(user,kwargs['initial'])
> >            super(UserProfileEditFormBase,self).__init__(*args, **kwargs)
> >            self.user = user
>
> >    def get_initial (self, user, initial={}):
> >            for k in self.base_fields.keys():
> >                    if k=='country':
> >                            initial[k] = getattr(profile,k).country_code
> >                    elif k=='postal_code' and getattr(profile,k,None):
> >                            initial[k] = getattr(profile,k).postal_code
> >                    elif getattr(user,k,None):
> >                            initial[k] = getattr(user,k)
> >                    elif getattr(profile, k, None):
> >                            a = getattr(profile, k)
> >                            if hasattr(a,'id'):
> >                                    initial[k] = a.id
> >                            else:
> >                                    initial[k] = a
> >            return initial
>
> >    def save (self):
> >            # uses self.user to save the cleaned_data
> >            ...
>
> > ##
>
> > class UserProfileEditForm (UserProfileEditFormBase, PostalCodeForm):
>
> >    about_you = forms.CharField(help_text="Description of yourself

Emergency: Critical form error on medium-volume site

2010-09-20 Thread intrepidweb
Hi all,

Last week I ported a site that gets 50k+ pageviews/day from a PHP/
mySQL stack to Django/Postgresql. It has gone mostly smoothly, all
things considered. However, I have encountered a VERY troubling bug
involving the forms module, and I can't figure it out.

The form in question allows users to edit their profile. We have
several types of users, and each user type has a core set of fields,
as well as a few unique ones. Rather than write each profile edit form
from scratch, they inherit from parent classes.

The profile edit form accepts a User instance in its __init__ method,
and uses that object to populate the initial data, and also to save
the cleaned data to the appropriate User and UserProfile instances.

The problem is in about 20% of the time, the form, when displayed on a
page, is displaying OTHER users' information as the initial data. I
have determined that this is not a page caching issue. Additionally, I
confirmed that the correct user object is being passed to the form
class. So the form instance itself is switching the user object. My
guess is that somehow the user object is being assigned as a class
attribute, not an instance attribute. But otherwise I am stumped.

Here are snippets of the code. I know the inheritance scheme seems a
bit convoluted, but it was written this way in the name of DRY. Any
help would be greatly appreciated.

Leif

#

class PostalCodeForm (forms.Form):
country = forms.ChoiceField(choices=[(c.country_code,c.en_name) for c
in Country.objects.all()],required=True, label='Country')
postal_code = forms.CharField(required=True, label="ZIP/postal code")

def clean_country (self):
...

def clean_postal_code (self):
...


class UserProfileEditFormBase (forms.Form):
first_name = custom_fields.NoProfanitiesCharField(max_length=150,
help_text = 'Your real first name. We will keep it private.')
last_name = custom_fields.NoProfanitiesCharField(max_length=150,
required=False, help_text = 'Your real last name. We will keep it
private.')
display_name = custom_fields.NoProfanitiesCharField(max_length=40,
help_text="Your public screenname. Will be shown on reviews that you
write, comments, etc.", label="Display name")
email = custom_fields.EmailField()
gender = forms.models.ModelChoiceField(queryset=Gender.objects.all(),
empty_label=None)

def __init__ (self, user, *args, **kwargs):
kwargs.setdefault('initial',{})
kwargs['initial'] = self.get_initial(user,kwargs['initial'])
super(UserProfileEditFormBase,self).__init__(*args, **kwargs)
self.user = user

def get_initial (self, user, initial={}):
for k in self.base_fields.keys():
if k=='country':
initial[k] = getattr(profile,k).country_code
elif k=='postal_code' and getattr(profile,k,None):
initial[k] = getattr(profile,k).postal_code
elif getattr(user,k,None):
initial[k] = getattr(user,k)
elif getattr(profile, k, None):
a = getattr(profile, k)
if hasattr(a,'id'):
initial[k] = a.id
else:
initial[k] = a
return initial

def save (self):
# uses self.user to save the cleaned_data
...

##

class UserProfileEditForm (UserProfileEditFormBase, PostalCodeForm):

about_you = forms.CharField(help_text="Description of yourself that
will appear with reviews and comments that you write.",
widget=forms.widgets.Textarea, required=False )

def get_initial (self, user, initial={}):

initial = super(UserProfileEditForm,self).get_initial(user, 
initial)
bios = user.reviewerbio_set.filter(is_primary=True)
if bios:
initial['about_you'] = bios[0].text

return initial

def save (self, user):


###


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



GIS/OpenLayers point field widget problem

2010-02-17 Thread intrepidweb
Hi there,

I am having a problem using the OpenLayers mapping widget for a GIS
point field.

I have a model called Locality that has a point field called
"coordinates." I set the value of that field using the following
format:  POINT(LAT, LNG).

For example, for Atlanta, GA, the value of the coordinates field was
set using the string "POINT (33,82178, -84.45596)".

However, when I view the admin change page for Atlanta, GA, the
mapping widget shows the coordinates as somewhere in Antarctica. It
appears to be transposing the coordinates -- in other words, it is
showing a *longitude* of -84.45596 and a *latitude* of 33,82178,
instead of the other way around.

Does anyone know why this is happening and how I can fix it?

I am using the development version, but I have had the same problem in
1.0 and 1.1.

Thanks!
Leif

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



Problem with map widget on admin change page (GIS / OpenLayers)

2009-07-16 Thread intrepidweb

Hi there,

I have a model called Locality that has a coordinates field. When I
view the admin change form for the model, the mapping widget appears,
but the actual map is grayed out.

For example, for Atlanta, GA, the coordinates are 33.69132,
-84.40137.  When the OpenLayers map widget is rendered, the individual
boxes that make up the map are all blank (gray), although the controls
are visible. Here is the URL for one of the boxes that comprise the
map:

http://labs.metacarta.com/wms/vmap0?LAYERS=basic=WMS=...

Does anyone know why the map is not being rendered? Do I need an API
key? I am using GeoModelAdmin as the base class for the model admin
class; the only options I've specified so far are search_fields,
ordering and fields.

Thanks for the help!
Leif

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



Problem with map widget on admin change page (GIS / OpenLayers)

2009-05-14 Thread intrepidweb

Hi there,

I have a model called Locality that has a coordinates field. When I
view the admin change form for the model, the mapping widget appears,
but the actual map is grayed out.

For example, for Atlanta, GA, the coordinates are 33.69132,
-84.40137.  When the OpenLayers map widget is rendered, the individual
boxes that make up the map are all blank (gray), although the controls
are visible. Here is the URL for one of the boxes that comprise the
map:

http://labs.metacarta.com/wms/vmap0?LAYERS=basic=WMS=1.1.1=GetMap==application%2Fvnd.ogc.se_inimage=image%2Fjpeg=EPSG%3A4326=33.75,-84.375,33.837890625,-84.287109375=256=256

Does anyone know why the map is not being rendered? Do I need an API
key?

I am using GeoModelAdmin as the base class for the model admin class;
the only options I've specified so far are search_fields, ordering and
fields.

Thanks for the help!

Leif

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



Chaining custom filter methods

2008-09-17 Thread intrepidweb

Hi there,

I would like to chain a few custom filter methods like so:

>>> Model.custom_manager.custom_filter1().custom_filter2()

The docs tell us how to override a Manager's base QuerySet by
overriding the Manager.get_query_set() method:

* 
http://docs.djangoproject.com/en/dev/topics/db/managers/#modifying-initial-manager-querysets

But it's not clear how to use that approach to chain custom filters.

When another user asked the same question a few months ago, Malcolm
Tredinnick sent him on the right track:

*
http://groups.google.com/group/django-users/browse_thread/thread/3d00660409d277da/88effc5365f2484b?hl=en=gst=custom+manager+chain#88effc5365f2484b

But I'm still hazy about how to write the code. Can anyone provide an
example?

Thanks!
Leif


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



Chaining custom filter methods

2008-09-17 Thread intrepidweb

Hi there,

I would like to chain a few different custom filter methods like so:

Model.custom_manager.custom_filter1().custom_filter2()

The docs tell us how to override a Manager's base QuerySet by
overriding the Manager.get_query_set() method:

http://docs.djangoproject.com/en/dev/topics/db/managers/#modifying-initial-manager-querysets

But it's not clear how to use that approach to chain custom filters.

When another user asked the same question a few months ago, Malcolm
Tredinnick set him on the right track:

http://groups.google.com/group/django-users/browse_frm/thread/3d00660409d277da?hl=en=1=custom+manager+chain

But I'm still hazy about how to write the code. Can anyone provide an
example?

Thanks!
Leif



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



Re: Custom middleware: using process_view to modify the view_func

2008-09-17 Thread intrepidweb

FYI, I answered my own question. It's pretty simple, actually. If you
want process_view() to override the view_func() that was passed in,
simply return new_view_func(). Similarly, if you want to override the
view_args, just return view_func(view_args). Duh.



On Sep 16, 1:37 pm, intrepidweb <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I'm working on a custom middleware class for the first time. My goal
> is to write a process_view function that modifies the view_func and/or
> view_args that were passed in.
>
> The documentation states that process_view can either return None or
> an HttpResponse. But is there a way to modify the arguments that were
> passed in?
>
> For example, if some_view is passed in as the view_func, is there a
> way to change it to another_view, so another_view is executed instead?
>
> Thanks for the help!
>
> Leif
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Custom middleware: using process_view to modify the view_func

2008-09-16 Thread intrepidweb

Hi there,

I'm working on a custom middleware class for the first time. My goal
is to write a process_view function that modifies the view_func and/or
view_args that were passed in.

The documentation states that process_view can either return None or
an HttpResponse. But is there a way to modify the arguments that were
passed in?

For example, if some_view is passed in as the view_func, is there a
way to change it to another_view, so another_view is executed instead?

Thanks for the help!

Leif



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