Ticket #7755: django-models-validation-emailfield-blank.patch
File django-models-validation-emailfield-blank.patch, 2.3 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
747 747 return [oldforms.EmailField] 748 748 749 749 def validate(self, field_data, all_data): 750 validators.isValidEmail(field_data, all_data) 750 if field_data: 751 validators.isValidEmail(field_data, all_data) 751 752 752 753 def formfield(self, **kwargs): 753 754 defaults = {'form_class': forms.EmailField} -
tests/modeltests/validation/models.py
16 16 birthdate = models.DateField() 17 17 favorite_moment = models.DateTimeField() 18 18 email = models.EmailField() 19 private_email = models.EmailField(blank=True) 19 20 20 21 def __unicode__(self): 21 22 return self.name … … 130 131 >>> p.favorite_moment 131 132 datetime.datetime(2002, 4, 3, 0, 0) 132 133 133 >>> p = Person(**dict(valid_params, email=' john@example.com'))134 >>> p = Person(**dict(valid_params, email='', private_email='')) 134 135 >>> p.validate() 136 {'email': [u'This field is required.']} 137 >>> p.email, p.private_email 138 ('', '') 139 140 >>> p = Person(**dict(valid_params, email='john@example.com', private_email='john@example.com')) 141 >>> p.validate() 135 142 {} 136 >>> p.email 137 'john@example.com' 143 >>> p.email, p.private_email 144 ('john@example.com', 'john@example.com') 138 145 139 >>> p = Person(**dict(valid_params, email=u'john@example.com' ))146 >>> p = Person(**dict(valid_params, email=u'john@example.com', private_email=u'john@example.com')) 140 147 >>> p.validate() 141 148 {} 142 >>> p.email 143 u'john@example.com' 149 >>> p.email, p.private_email 150 (u'john@example.com', u'john@example.com') 144 151 145 >>> p = Person(**dict(valid_params, email=22 ))146 >>> p.validate() ['email']147 [ u'Enter a valid e-mail address.']152 >>> p = Person(**dict(valid_params, email=22, private_email=22)) 153 >>> p.validate().values() 154 [[u'Enter a valid e-mail address.'], [u'Enter a valid e-mail address.']] 148 155 149 156 # Make sure that Date and DateTime return validation errors and don't raise Python errors. 150 157 >>> p = Person(name='John Doe', is_child=True, email='abc@def.com')