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:
Adrian Holovaty 2007-04-06 04:24:06 +00:00
parent 07f599ca5c
commit e3308e1976
2 changed files with 26 additions and 34 deletions

View File

@ -43,10 +43,9 @@ class DEIdentityCardNumberField(Field):
parameter = 7
for i in range(len(given_number)):
fragment = str(int(given_number[i])*parameter)
fragment = str(int(given_number[i]) * parameter)
if fragment.isalnum():
calculated_checksum += int(fragment[-1])
if parameter == 1:
parameter = 7
elif parameter == 3:
@ -54,34 +53,27 @@ class DEIdentityCardNumberField(Field):
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)

View File

@ -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.']
"""