Django

Code

Changeset 5231

Show
Ignore:
Timestamp:
05/14/07 09:02:36 (1 year ago)
Author:
mtredinnick
Message:

Renamed form-specific cleaning methods to be do_clean_*, rather than 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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r5209 r5231  
    185185                value = field.clean(value) 
    186186                self.clean_data[name] = value 
    187                 if hasattr(self, 'clean_%s' % name): 
    188                     value = getattr(self, 'clean_%s' % name)() 
     187                if hasattr(self, 'do_clean_%s' % name): 
     188                    value = getattr(self, 'do_clean_%s' % name)() 
    189189                self.clean_data[name] = value 
    190190            except ValidationError, e: 
  • django/trunk/tests/regressiontests/forms/regressions.py

    r4924 r5231  
    3535>>> f.as_p() 
    3636u'<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>' 
     37 
     38####################### 
     39# Miscellaneous Tests # 
     40####################### 
     41 
     42There once was a problem with Form fields called "data". Let's make sure that 
     43doesn't come back. 
     44>>> class DataForm(Form): 
     45...     data = CharField(max_length=10) 
     46>>> f = DataForm({'data': 'xyzzy'}) 
     47>>> f.is_valid() 
     48True 
     49>>> f.clean_data 
     50{'data': u'xyzzy'} 
    3751""" 
  • django/trunk/tests/regressiontests/forms/tests.py

    r5218 r5231  
    23042304>>> class EscapingForm(Form): 
    23052305...     special_name = CharField() 
    2306 ...     def clean_special_name(self): 
     2306...     def do_clean_special_name(self): 
    23072307...         raise ValidationError("Something's wrong with '%s'" % self.clean_data['special_name']) 
    23082308 
     
    23272327...    password1 = CharField(widget=PasswordInput) 
    23282328...    password2 = CharField(widget=PasswordInput) 
    2329 ...    def clean_password2(self): 
     2329...    def do_clean_password2(self): 
    23302330...        if self.clean_data.get('password1') and self.clean_data.get('password2') and self.clean_data['password1'] != self.clean_data['password2']: 
    23312331...            raise ValidationError(u'Please make sure your passwords match.')