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

@ -12,9 +12,9 @@ id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday
class DEZipCodeField(RegexField): class DEZipCodeField(RegexField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(DEZipCodeField, self).__init__(r'^\d{5}$', super(DEZipCodeField, self).__init__(r'^\d{5}$',
max_length=None, min_length=None, max_length=None, min_length=None,
error_message=gettext(u'Enter a zip code in the format XXXXX.'), error_message=gettext(u'Enter a zip code in the format XXXXX.'),
*args, **kwargs) *args, **kwargs)
class DEStateSelect(Select): class DEStateSelect(Select):
""" """
@ -43,45 +43,37 @@ class DEIdentityCardNumberField(Field):
parameter = 7 parameter = 7
for i in range(len(given_number)): for i in range(len(given_number)):
fragment = str(int(given_number[i])*parameter) fragment = str(int(given_number[i]) * parameter)
if fragment.isalnum(): if fragment.isalnum():
calculated_checksum += int(fragment[-1]) calculated_checksum += int(fragment[-1])
if parameter == 1:
parameter = 7
elif parameter == 3:
parameter = 1
elif parameter ==7:
parameter = 3
if parameter == 1: return str(calculated_checksum)[-1] == given_checksum
parameter = 7
elif parameter == 3:
parameter = 1
elif parameter ==7:
parameter = 3
if str(calculated_checksum)[-1] == given_checksum:
return True
return False
def clean(self, value): def clean(self, value):
super(DEIdentityCardNumberField, self).clean(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: if value in EMPTY_VALUES:
return u'' return u''
match = re.match(id_re, value) match = re.match(id_re, value)
if not match: if not match:
raise ValidationError(error_msg) raise ValidationError(error_msg)
residence, origin, birthday, validity, checksum = \ gd = match.groupdict()
match.groupdict()['residence'], match.groupdict()['origin'], \ residence, origin = gd['residence'], gd['origin']
match.groupdict()['birthday'], match.groupdict()['validity'], \ birthday, validity, checksum = gd['birthday'], gd['validity'], gd['checksum']
match.groupdict()['checksum']
if residence == '0000000000' or \ if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
birthday == '0000000' or \
validity == '0000000':
raise ValidationError(error_msg) raise ValidationError(error_msg)
all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum) all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum)
if not self.has_valid_checksum(residence) or \ if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \
not self.has_valid_checksum(birthday) or \ not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits):
not self.has_valid_checksum(validity) or \
not self.has_valid_checksum(all_digits):
raise ValidationError(error_msg) raise ValidationError(error_msg)
return u'%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum) 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') >>> f.clean('0434657485D-6407276-0508137-9')
Traceback (most recent call last): 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.']
""" """