Ticket #3337: newforms-fields-super.diff
File newforms-fields-super.diff, 7.0 KB (added by , 18 years ago) |
---|
-
django/newforms/fields.py
86 86 class CharField(Field): 87 87 def __init__(self, max_length=None, min_length=None, required=True, widget=None, label=None, initial=None): 88 88 self.max_length, self.min_length = max_length, min_length 89 Field.__init__(self, required, widget, label, initial)89 super(CharField, self).__init__(self, required, widget, label, initial) 90 90 91 91 def clean(self, value): 92 92 "Validates max_length and min_length. Returns a Unicode object." 93 Field.clean(self, value)93 super(CharField, self).clean(self, value) 94 94 if value in EMPTY_VALUES: 95 95 value = u'' 96 96 if not self.required: … … 109 109 class IntegerField(Field): 110 110 def __init__(self, max_value=None, min_value=None, required=True, widget=None, label=None, initial=None): 111 111 self.max_value, self.min_value = max_value, min_value 112 Field.__init__(self, required, widget, label, initial)112 super(IntegerField, self).__init__(self, required, widget, label, initial) 113 113 114 114 def clean(self, value): 115 115 """ … … 139 139 140 140 class DateField(Field): 141 141 def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None): 142 Field.__init__(self, required, widget, label, initial)142 super(DateField, self).__init__(self, required, widget, label, initial) 143 143 self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS 144 144 145 145 def clean(self, value): … … 147 147 Validates that the input can be converted to a date. Returns a Python 148 148 datetime.date object. 149 149 """ 150 Field.clean(self, value)150 super(DateField, self).clean(self, value) 151 151 if value in EMPTY_VALUES: 152 152 return None 153 153 if isinstance(value, datetime.datetime): … … 168 168 169 169 class TimeField(Field): 170 170 def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None): 171 Field.__init__(self, required, widget, label, initial)171 super(TimeField, self).__init__(self, required, widget, label, initial) 172 172 self.input_formats = input_formats or DEFAULT_TIME_INPUT_FORMATS 173 173 174 174 def clean(self, value): … … 176 176 Validates that the input can be converted to a time. Returns a Python 177 177 datetime.time object. 178 178 """ 179 Field.clean(self, value)179 super(TimeField, self).clean(self, value) 180 180 if value in EMPTY_VALUES: 181 181 return None 182 182 if isinstance(value, datetime.time): … … 202 202 203 203 class DateTimeField(Field): 204 204 def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None): 205 Field.__init__(self, required, widget, label, initial)205 super(DateTimeField, self).__init__(self, required, widget, label, initial) 206 206 self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS 207 207 208 208 def clean(self, value): … … 210 210 Validates that the input can be converted to a datetime. Returns a 211 211 Python datetime.datetime object. 212 212 """ 213 Field.clean(self, value)213 super(DateTimeField, self).clean(self, value) 214 214 if value in EMPTY_VALUES: 215 215 return None 216 216 if isinstance(value, datetime.datetime): … … 232 232 error_message is an optional error message to use, if 233 233 'Enter a valid value' is too generic for you. 234 234 """ 235 Field.__init__(self, required, widget, label, initial)235 super(RegexField, self).__init__(self, required, widget, label, initial) 236 236 if isinstance(regex, basestring): 237 237 regex = re.compile(regex) 238 238 self.regex = regex … … 244 244 Validates that the input matches the regular expression. Returns a 245 245 Unicode object. 246 246 """ 247 Field.clean(self, value)247 super(RegexField, self).clean(self, value) 248 248 if value in EMPTY_VALUES: value = u'' 249 249 value = smart_unicode(value) 250 250 if not self.required and value == u'': … … 282 282 class URLField(RegexField): 283 283 def __init__(self, max_length=None, min_length=None, required=True, verify_exists=False, widget=None, label=None, 284 284 initial=None, validator_user_agent=URL_VALIDATOR_USER_AGENT): 285 RegexField.__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)285 super(URLField, self).__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial) 286 286 self.verify_exists = verify_exists 287 287 self.user_agent = validator_user_agent 288 288 289 289 def clean(self, value): 290 value = RegexField.clean(self, value)290 value = super(URLField, self).clean(self, value) 291 291 if not self.required and value == u'': 292 292 return value 293 293 if self.verify_exists: … … 314 314 315 315 def clean(self, value): 316 316 "Returns a Python boolean object." 317 Field.clean(self, value)317 super(BooleanField, self).clean(self, value) 318 318 return bool(value) 319 319 320 320 class ChoiceField(Field): 321 321 def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None): 322 322 if isinstance(widget, type): 323 323 widget = widget(choices=choices) 324 Field.__init__(self, required, widget, label, initial)324 super(ChoiceField, self).__init__(self, required, widget, label, initial) 325 325 self.choices = choices 326 326 327 327 def clean(self, value): 328 328 """ 329 329 Validates that the input is in self.choices. 330 330 """ 331 value = Field.clean(self, value)331 value = super(ChoiceField, self).clean(self, value) 332 332 if value in EMPTY_VALUES: value = u'' 333 333 value = smart_unicode(value) 334 334 if not self.required and value == u'': … … 342 342 hidden_widget = MultipleHiddenInput 343 343 344 344 def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None, initial=None): 345 ChoiceField.__init__(self, choices, required, widget, label, initial)345 super(MultipleChoiceField, self).__init__(self, choices, required, widget, label, initial) 346 346 347 347 def clean(self, value): 348 348 """ … … 367 367 368 368 class ComboField(Field): 369 369 def __init__(self, fields=(), required=True, widget=None, label=None, initial=None): 370 Field.__init__(self, required, widget, label, initial)370 super(ComboField, self).__init__(self, required, widget, label, initial) 371 371 # Set 'required' to False on the individual fields, because the 372 372 # required validation will be handled by ComboField, not by those 373 373 # individual fields. … … 380 380 Validates the given value against all of self.fields, which is a 381 381 list of Field instances. 382 382 """ 383 Field.clean(self, value)383 super(ComboField, self).clean(self, value) 384 384 for field in self.fields: 385 385 value = field.clean(value) 386 386 return value