Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #8229: Added handling for a special case in the validation of S…

…panish ID numbers. Thanks to Marc Garcia for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8405 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cbcc4159342288f6866f2006c30dd16740703049 1 parent 77c9492
@freakboy3742 freakboy3742 authored
View
4 django/contrib/localflavor/es/forms.py
@@ -108,7 +108,7 @@ def clean(self, value):
if not letter2:
number, letter2 = number[:-1], int(number[-1])
checksum = cif_get_checksum(number)
- if letter2 in [checksum, self.cif_control[checksum]]:
+ if letter2 in (checksum, self.cif_control[checksum]):
return value
else:
raise ValidationError, self.error_messages['invalid_cif']
@@ -180,5 +180,5 @@ def __init__(self, attrs=None):
def cif_get_checksum(number):
s1 = sum([int(digit) for pos, digit in enumerate(number) if int(pos) % 2])
s2 = sum([sum([int(unit) for unit in str(int(digit) * 2)]) for pos, digit in enumerate(number) if not int(pos) % 2])
- return 10 - ((s1 + s2) % 10)
+ return (10 - ((s1 + s2) % 10)) % 10
View
2  tests/regressiontests/forms/localflavor/es.py
@@ -167,6 +167,8 @@
ValidationError: [u'Invalid checksum for NIE.']
>>> f.clean('B38790911')
'B38790911'
+>>> f.clean('B31234560')
+'B31234560'
>>> f.clean('B-3879091A')
'B3879091A'
>>> f.clean('B 38790917')

0 comments on commit cbcc415

Please sign in to comment.
Something went wrong with that request. Please try again.