Browse files

Fixed #12017 - Overriding the default error message of the UKPostcode…

…Field works again.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12044 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 6eb205c commit 4b2e6743290de5170b2ac96b46241046947f4510 @jezdez jezdez committed Jan 1, 2010
Showing with 12 additions and 1 deletion.
  1. +1 −1 django/contrib/localflavor/uk/forms.py
  2. +11 −0 tests/regressiontests/forms/localflavor/uk.py
View
2 django/contrib/localflavor/uk/forms.py
@@ -33,7 +33,7 @@ def clean(self, value):
# Put a single space before the incode (second part).
postcode = self.space_regex.sub(r' \1', postcode)
if not self.postcode_regex.search(postcode):
- raise ValidationError(self.default_error_messages['invalid'])
+ raise ValidationError(self.error_messages['invalid'])
return postcode
class UKCountySelect(Select):
View
11 tests/regressiontests/forms/localflavor/uk.py
@@ -58,4 +58,15 @@
u''
>>> f.clean('')
u''
+>>> class MyUKPostcodeField(UKPostcodeField):
+... default_error_messages = {
+... 'invalid': 'Enter a bloody postcode!',
+... }
+...
+>>>
+>>> f = MyUKPostcodeField(required=False)
+>>> f.clean('1NV 4L1D')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a bloody postcode!']
"""

0 comments on commit 4b2e674

Please sign in to comment.