Ticket #10204: patch_nifniecif_es.diff

File patch_nifniecif_es.diff, 2.2 KB (added by Cesar Ortiz <cesar.ortiz@…>, 16 years ago)

An alternative (and right) patch

  • django/contrib/localflavor/es/forms.py

     
    7575        self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE'
    7676        self.cif_control = 'JABCDEFGHI'
    7777        self.cif_types = 'ABCDEFGHKLMNPQS'
    78         self.nie_types = 'XT'
     78        self.nie_types = 'XYZ'
    7979        id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE)
    8080        super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None,
    8181                error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')],
     
    9999                raise ValidationError, self.error_messages['invalid_nif']
    100100        elif letter1 in self.nie_types and letter2:
    101101            # NIE
    102             if letter2 == nif_get_checksum(number):
     102            if letter2 == nif_get_checksum(str(self.nie_types.find(letter1)) + number):
    103103                return value
    104104            else:
    105105                raise ValidationError, self.error_messages['invalid_nie']
  • tests/regressiontests/forms/localflavor/es.py

     
    155155'X0012953G'
    156156>>> f.clean('x-3287690-r')
    157157'X3287690R'
     158>>> f.clean('y3287690r')
     159Traceback (most recent call last):
     160...
     161ValidationError: [u'Invalid checksum for NIE.']
     162>>> f.clean('y3287690s')
     163'Y3287690S'
    158164>>> f.clean('t-03287690r')
    159 'T03287690R'
     165Traceback (most recent call last):
     166...
     167ValidationError: [u'Please enter a valid NIF, NIE, or CIF.']
    160168>>> f.clean('P2907500I')
    161169'P2907500I'
    162170>>> f.clean('X-03287690')
     
    226234>>> f.clean('x-3287690-r')
    227235'X3287690R'
    228236>>> f.clean('t-03287690r')
    229 'T03287690R'
     237Traceback (most recent call last):
     238...
     239ValidationError: [u'Please enter a valid NIF, NIE, or CIF.']
    230240>>> f.clean('X-03287690')
    231241Traceback (most recent call last):
    232242...
Back to Top