Re: Django Contrib's UserCreationForm (Potential Bug)

2010-01-07 Thread Sandman
On 1/7/10 2:13 AM, Daniel Roseman wrote:
> On Jan 7, 4:36�am, Sandman  wrote:
>> 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.
>>
>> �forms.py
>> 2KViewDownload
> 
> Yes, this is a bug. It's already been raised in the issue tracker
> (#12520).
> 
> I must say that it's probably a bad idea to be developing against
> trunk at the moment. It's in quite a lot of flux as we approach 1.2,
> so unless you desperately need the latest features, I'd stay on 1.1
> for now.
> --
> DR.
> 
Thanks a lot for your replay Daniel. Yeah, I think I will revert to 1.1
for now to avoid heartache :)

Take care,
Rajiv.
-- 
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 Contrib's UserCreationForm (Potential Bug)

2010-01-07 Thread Daniel Roseman
On Jan 7, 4:36 am, Sandman  wrote:
> 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.
>
>  forms.py
> 2KViewDownload

Yes, this is a bug. It's already been raised in the issue tracker
(#12520).

I must say that it's probably a bad idea to be developing against
trunk at the moment. It's in quite a lot of flux as we approach 1.2,
so unless you desperately need the latest features, I'd stay on 1.1
for now.
--
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.




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.