Skip to content

Commit

Permalink
Renamed form-specific cleaning methods to be do_clean_*, rather than …
Browse files Browse the repository at this point in the history
…clean_*.

This avoids a name clash that would occur when you had a form field called
"data" (because clean_data is already a dictionary on the Form class).

Backwards incompatible change.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5231 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed May 14, 2007
1 parent c89dc9c commit f15036a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/newforms/forms.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def full_clean(self):
try: try:
value = field.clean(value) value = field.clean(value)
self.clean_data[name] = value self.clean_data[name] = value
if hasattr(self, 'clean_%s' % name): if hasattr(self, 'do_clean_%s' % name):
value = getattr(self, 'clean_%s' % name)() value = getattr(self, 'do_clean_%s' % name)()
self.clean_data[name] = value self.clean_data[name] = value
except ValidationError, e: except ValidationError, e:
errors[name] = e.messages errors[name] = e.messages
Expand Down
14 changes: 14 additions & 0 deletions tests/regressiontests/forms/regressions.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@
>>> f = SomeForm() >>> f = SomeForm()
>>> f.as_p() >>> f.as_p()
u'<p><label for="id_somechoice_0">Somechoice:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="0" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="1" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="2" name="somechoice" /> Nainen</label></li>\n</ul></p>' u'<p><label for="id_somechoice_0">Somechoice:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="0" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="1" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="2" name="somechoice" /> Nainen</label></li>\n</ul></p>'
#######################
# Miscellaneous Tests #
#######################
There once was a problem with Form fields called "data". Let's make sure that
doesn't come back.
>>> class DataForm(Form):
... data = CharField(max_length=10)
>>> f = DataForm({'data': 'xyzzy'})
>>> f.is_valid()
True
>>> f.clean_data
{'data': u'xyzzy'}
""" """
4 changes: 2 additions & 2 deletions tests/regressiontests/forms/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@
Validation errors are HTML-escaped when output as HTML. Validation errors are HTML-escaped when output as HTML.
>>> class EscapingForm(Form): >>> class EscapingForm(Form):
... special_name = CharField() ... special_name = CharField()
... def clean_special_name(self): ... def do_clean_special_name(self):
... raise ValidationError("Something's wrong with '%s'" % self.clean_data['special_name']) ... raise ValidationError("Something's wrong with '%s'" % self.clean_data['special_name'])
>>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False) >>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False)
Expand All @@ -2326,7 +2326,7 @@
... username = CharField(max_length=10) ... username = CharField(max_length=10)
... password1 = CharField(widget=PasswordInput) ... password1 = CharField(widget=PasswordInput)
... password2 = CharField(widget=PasswordInput) ... password2 = CharField(widget=PasswordInput)
... def clean_password2(self): ... def do_clean_password2(self):
... if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: ... if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']:
... raise ValidationError(u'Please make sure your passwords match.') ... raise ValidationError(u'Please make sure your passwords match.')
... return self.clean_data['password2'] ... return self.clean_data['password2']
Expand Down

0 comments on commit f15036a

Please sign in to comment.