Ticket #3896: 3896.2.diff

File 3896.2.diff, 2.0 KB (added by Gary Wilson <gary.wilson@…>, 17 years ago)

Only the passing of value to clean_XXX method, with test fixes.

  • django/newforms/forms.py

    === modified file 'django/newforms/forms.py'
     
    187187                value = field.clean(value)
    188188                self.cleaned_data[name] = value
    189189                if hasattr(self, 'clean_%s' % name):
    190                     value = getattr(self, 'clean_%s' % name)()
     190                    value = getattr(self, 'clean_%s' % name)(value)
    191191                self.cleaned_data[name] = value
    192192            except ValidationError, e:
    193193                errors[name] = e.messages
  • tests/regressiontests/forms/tests.py

    === modified file 'tests/regressiontests/forms/tests.py'
     
    24342434Validation errors are HTML-escaped when output as HTML.
    24352435>>> class EscapingForm(Form):
    24362436...     special_name = CharField()
    2437 ...     def clean_special_name(self):
    2438 ...         raise ValidationError("Something's wrong with '%s'" % self.cleaned_data['special_name'])
     2437...     def clean_special_name(self, value):
     2438...         raise ValidationError("Something's wrong with '%s'" % value)
    24392439
    24402440>>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False)
    24412441>>> print f
     
    24572457...    username = CharField(max_length=10)
    24582458...    password1 = CharField(widget=PasswordInput)
    24592459...    password2 = CharField(widget=PasswordInput)
    2460 ...    def clean_password2(self):
    2461 ...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']:
     2460...    def clean_password2(self, value):
     2461...        if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != value:
    24622462...            raise ValidationError(u'Please make sure your passwords match.')
    2463 ...        return self.cleaned_data['password2']
     2463...        return value
    24642464>>> f = UserRegistration(auto_id=False)
    24652465>>> f.errors
    24662466{}
Back to Top