diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-10-05 06:00:55 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-10-05 06:00:55 +0000 |
| commit | 571b159dd35b27ff1598973aaa8c52085268fdb5 (patch) | |
| tree | fe00a21bd563b452106ec677b4fad72da4b39657 | |
| parent | 245399becbac4e3246d09fff268f99e3b8af7839 (diff) | |
[1.0.X] Fixed #9259 -- Fixed a validation error for Spanish identity card numbers.
Patch from Marc Garcia.
Backport of r9129 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9130 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/localflavor/es/forms.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavor/es.py | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py index 145bf90768..a033f3e46b 100644 --- a/django/contrib/localflavor/es/forms.py +++ b/django/contrib/localflavor/es/forms.py @@ -76,8 +76,8 @@ class ESIdentityCardNumberField(RegexField): self.cif_control = 'JABCDEFGHI' self.cif_types = 'ABCDEFGHKLMNPQS' self.nie_types = 'XT' - super(ESIdentityCardNumberField, self).__init__(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types + self.cif_types.lower() + self.nie_types.lower(), self.nif_control + self.nif_control.lower()), - max_length=None, min_length=None, + id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE) + super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None, error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')], *args, **kwargs) @@ -88,7 +88,7 @@ class ESIdentityCardNumberField(RegexField): nif_get_checksum = lambda d: self.nif_control[int(d)%23] value = value.upper().replace(' ', '').replace('-', '') - m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control), value) + m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), value) letter1, number, letter2 = m.groups() if not letter1 and letter2: diff --git a/tests/regressiontests/forms/localflavor/es.py b/tests/regressiontests/forms/localflavor/es.py index 66d18dd0fc..b92f62383d 100644 --- a/tests/regressiontests/forms/localflavor/es.py +++ b/tests/regressiontests/forms/localflavor/es.py @@ -157,6 +157,8 @@ ValidationError: [u'Invalid checksum for NIF.'] 'X3287690R' >>> f.clean('t-03287690r') 'T03287690R' +>>> f.clean('P2907500I') +'P2907500I' >>> f.clean('X-03287690') Traceback (most recent call last): ... |
