Ticket #7833: usercreationform.patch

File usercreationform.patch, 1.5 KB (added by Jeroen Vloothuis, 16 years ago)
  • django/contrib/auth/tests/forms.py

     
    4444>>> form["password2"].errors
    4545[u"The two password fields didn't match."]
    4646
     47The first password isn't specified
     48
     49>>> data = {
     50...     'username': 'jsmith2',
     51...     'password2': 'test123',
     52... }
     53>>> form = UserCreationForm(data)
     54>>> form.is_valid()
     55False
     56>>> form["password1"].errors
     57[u'This field is required.']
     58
    4759The success case.
    4860
    4961>>> data = {
  • django/contrib/auth/forms.py

     
    2929        raise forms.ValidationError(_("A user with that username already exists."))
    3030   
    3131    def clean_password2(self):
    32         password1 = self.cleaned_data["password1"]
    3332        password2 = self.cleaned_data["password2"]
     33
     34        try:
     35            password1 = self.cleaned_data["password1"]
     36        except KeyError:
     37            # No password has been given to check against. We will
     38            # skip our checks since the form will signal this to the
     39            # user because the field is required.
     40            return password2
     41           
    3442        if password1 != password2:
    3543            raise forms.ValidationError(_("The two password fields didn't match."))
    3644        return password2
Back to Top