Ticket #3303: clean_clean.patch
File clean_clean.patch, 2.2 KB (added by , 18 years ago) |
---|
-
django/newforms/fields.py
92 92 "Validates max_length and min_length. Returns a Unicode object." 93 93 Field.clean(self, value) 94 94 if value in EMPTY_VALUES: 95 value = u'' 96 if not self.required: 97 return value 95 return u'' 98 96 value = smart_unicode(value) 99 97 if self.max_length is not None and len(value) > self.max_length: 100 98 raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length) … … 117 115 of int(). Returns None for empty values. 118 116 """ 119 117 super(IntegerField, self).clean(value) 120 if not self.required andvalue in EMPTY_VALUES:118 if value in EMPTY_VALUES: 121 119 return None 122 120 try: 123 121 value = int(value) … … 245 243 Unicode object. 246 244 """ 247 245 Field.clean(self, value) 248 if value in EMPTY_VALUES: value = u'' 246 if value in EMPTY_VALUES: 247 value = u'' 249 248 value = smart_unicode(value) 250 if not self.required andvalue == u'':249 if value == u'': 251 250 return value 252 251 if self.max_length is not None and len(value) > self.max_length: 253 252 raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length) … … 288 287 289 288 def clean(self, value): 290 289 value = RegexField.clean(self, value) 291 if not self.required andvalue == u'':290 if value == u'': 292 291 return value 293 292 if self.verify_exists: 294 293 import urllib2 … … 329 328 Validates that the input is in self.choices. 330 329 """ 331 330 value = Field.clean(self, value) 332 if value in EMPTY_VALUES: value = u'' 331 if value in EMPTY_VALUES: 332 value = u'' 333 333 value = smart_unicode(value) 334 if not self.required andvalue == u'':334 if value == u'': 335 335 return value 336 336 valid_values = set([str(k) for k, v in self.choices]) 337 337 if value not in valid_values: