mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #14499 -- ATSocialSecurityNumberField now responds to all EMPTY_VALUES correctly. Also converted Austrian localflavor doctests to unittests. We have always been at war with doctests. Thanks to Idan Gazit for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14873 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -4,12 +4,14 @@ AT-specific Form helpers
|
||||
|
||||
import re
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.forms.fields import Field, RegexField, Select
|
||||
from django.core.validators import EMPTY_VALUES
|
||||
from django.forms import ValidationError
|
||||
from django.forms.fields import Field, RegexField, Select
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
re_ssn = re.compile(r'^\d{4} \d{6}')
|
||||
|
||||
|
||||
class ATZipCodeField(RegexField):
|
||||
"""
|
||||
A form field that validates its input is an Austrian postcode.
|
||||
@@ -49,6 +51,9 @@ class ATSocialSecurityNumberField(Field):
|
||||
}
|
||||
|
||||
def clean(self, value):
|
||||
value = super(ATSocialSecurityNumberField, self).clean(value)
|
||||
if value in EMPTY_VALUES:
|
||||
return u""
|
||||
if not re_ssn.search(value):
|
||||
raise ValidationError(self.error_messages['invalid'])
|
||||
sqnr, date = value.split(" ")
|
||||
@@ -62,4 +67,3 @@ class ATSocialSecurityNumberField(Field):
|
||||
if res != int(check):
|
||||
raise ValidationError(self.error_messages['invalid'])
|
||||
return u'%s%s %s'%(sqnr, check, date,)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user