Changeset 3978 for django/trunk/django/newforms/fields.py
- Timestamp:
- 11/04/06 14:49:59 (3 years ago)
- Files:
-
- django/trunk/django/newforms/fields.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/fields.py
r3959 r3978 15 15 'RegexField', 'EmailField', 'URLField', 'BooleanField', 16 16 'ChoiceField', 'MultipleChoiceField', 17 'ComboField', 17 18 ) 18 19 … … 35 36 self.widget = widget 36 37 37 def to_python(self, value):38 """ 39 Validates the given value and returns its " normalized" value as an38 def clean(self, value): 39 """ 40 Validates the given value and returns its "cleaned" value as an 40 41 appropriate Python object. 41 42 … … 51 52 self.max_length, self.min_length = max_length, min_length 52 53 53 def to_python(self, value):54 def clean(self, value): 54 55 "Validates max_length and min_length. Returns a Unicode object." 55 Field. to_python(self, value)56 Field.clean(self, value) 56 57 if value in EMPTY_VALUES: value = u'' 57 58 if not isinstance(value, basestring): … … 66 67 67 68 class IntegerField(Field): 68 def to_python(self, value):69 def clean(self, value): 69 70 """ 70 71 Validates that int() can be called on the input. Returns the result 71 72 of int(). 72 73 """ 73 super(IntegerField, self). to_python(value)74 super(IntegerField, self).clean(value) 74 75 try: 75 76 return int(value) … … 90 91 self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS 91 92 92 def to_python(self, value):93 def clean(self, value): 93 94 """ 94 95 Validates that the input can be converted to a date. Returns a Python 95 96 datetime.date object. 96 97 """ 97 Field. to_python(self, value)98 Field.clean(self, value) 98 99 if value in EMPTY_VALUES: 99 100 return None … … 126 127 self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS 127 128 128 def to_python(self, value):129 def clean(self, value): 129 130 """ 130 131 Validates that the input can be converted to a datetime. Returns a 131 132 Python datetime.datetime object. 132 133 """ 133 Field. to_python(self, value)134 Field.clean(self, value) 134 135 if value in EMPTY_VALUES: 135 136 return None … … 158 159 self.error_message = error_message or u'Enter a valid value.' 159 160 160 def to_python(self, value):161 def clean(self, value): 161 162 """ 162 163 Validates that the input matches the regular expression. Returns a 163 164 Unicode object. 164 165 """ 165 Field. to_python(self, value)166 Field.clean(self, value) 166 167 if value in EMPTY_VALUES: value = u'' 167 168 if not isinstance(value, basestring): … … 193 194 self.verify_exists = verify_exists 194 195 195 def to_python(self, value):196 value = RegexField. to_python(self, value)196 def clean(self, value): 197 value = RegexField.clean(self, value) 197 198 if self.verify_exists: 198 199 import urllib2 … … 208 209 widget = CheckboxInput 209 210 210 def to_python(self, value):211 def clean(self, value): 211 212 "Returns a Python boolean object." 212 Field. to_python(self, value)213 Field.clean(self, value) 213 214 return bool(value) 214 215 … … 220 221 self.choices = choices 221 222 222 def to_python(self, value):223 def clean(self, value): 223 224 """ 224 225 Validates that the input is in self.choices. 225 226 """ 226 value = Field. to_python(self, value)227 value = Field.clean(self, value) 227 228 if value in EMPTY_VALUES: value = u'' 228 229 if not isinstance(value, basestring): … … 239 240 ChoiceField.__init__(self, choices, required, widget) 240 241 241 def to_python(self, value):242 def clean(self, value): 242 243 """ 243 244 Validates that the input is a list or tuple. … … 260 261 raise ValidationError(u'Select a valid choice. %s is not one of the available choices.' % val) 261 262 return new_value 263 264 class ComboField(Field): 265 def __init__(self, fields=(), required=True, widget=None): 266 Field.__init__(self, required, widget) 267 self.fields = fields 268 269 def clean(self, value): 270 """ 271 Validates the given value against all of self.fields, which is a 272 list of Field instances. 273 """ 274 Field.clean(self, value) 275 for field in self.fields: 276 value = field.clean(value) 277 return value
