Fixed inconsistent indentation in localflavor/de/forms.py from [4922]
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4939 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
07f599ca5c
commit
e3308e1976
|
@ -12,9 +12,9 @@ id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday
|
|||
class DEZipCodeField(RegexField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DEZipCodeField, self).__init__(r'^\d{5}$',
|
||||
max_length=None, min_length=None,
|
||||
error_message=gettext(u'Enter a zip code in the format XXXXX.'),
|
||||
*args, **kwargs)
|
||||
max_length=None, min_length=None,
|
||||
error_message=gettext(u'Enter a zip code in the format XXXXX.'),
|
||||
*args, **kwargs)
|
||||
|
||||
class DEStateSelect(Select):
|
||||
"""
|
||||
|
@ -43,45 +43,37 @@ class DEIdentityCardNumberField(Field):
|
|||
parameter = 7
|
||||
|
||||
for i in range(len(given_number)):
|
||||
fragment = str(int(given_number[i])*parameter)
|
||||
if fragment.isalnum():
|
||||
calculated_checksum += int(fragment[-1])
|
||||
fragment = str(int(given_number[i]) * parameter)
|
||||
if fragment.isalnum():
|
||||
calculated_checksum += int(fragment[-1])
|
||||
if parameter == 1:
|
||||
parameter = 7
|
||||
elif parameter == 3:
|
||||
parameter = 1
|
||||
elif parameter ==7:
|
||||
parameter = 3
|
||||
|
||||
if parameter == 1:
|
||||
parameter = 7
|
||||
elif parameter == 3:
|
||||
parameter = 1
|
||||
elif parameter ==7:
|
||||
parameter = 3
|
||||
|
||||
if str(calculated_checksum)[-1] == given_checksum:
|
||||
return True
|
||||
return False
|
||||
return str(calculated_checksum)[-1] == given_checksum
|
||||
|
||||
def clean(self, value):
|
||||
super(DEIdentityCardNumberField, self).clean(value)
|
||||
error_msg = gettext(u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format')
|
||||
error_msg = gettext(u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.')
|
||||
if value in EMPTY_VALUES:
|
||||
return u''
|
||||
match = re.match(id_re, value)
|
||||
if not match:
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
residence, origin, birthday, validity, checksum = \
|
||||
match.groupdict()['residence'], match.groupdict()['origin'], \
|
||||
match.groupdict()['birthday'], match.groupdict()['validity'], \
|
||||
match.groupdict()['checksum']
|
||||
gd = match.groupdict()
|
||||
residence, origin = gd['residence'], gd['origin']
|
||||
birthday, validity, checksum = gd['birthday'], gd['validity'], gd['checksum']
|
||||
|
||||
if residence == '0000000000' or \
|
||||
birthday == '0000000' or \
|
||||
validity == '0000000':
|
||||
if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum)
|
||||
if not self.has_valid_checksum(residence) or \
|
||||
not self.has_valid_checksum(birthday) or \
|
||||
not self.has_valid_checksum(validity) or \
|
||||
not self.has_valid_checksum(all_digits):
|
||||
if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \
|
||||
not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits):
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
return u'%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum)
|
||||
|
|
|
@ -881,5 +881,5 @@ u'9786324830D-6104243-0910271-2'
|
|||
>>> f.clean('0434657485D-6407276-0508137-9')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format']
|
||||
ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.']
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue