Ticket #9259: 9259.diff

File 9259.diff, 1.9 KB (added by Marc Garcia, 16 years ago)

Fix and tests

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

     
    7676        self.cif_control = 'JABCDEFGHI'
    7777        self.cif_types = 'ABCDEFGHKLMNPQS'
    7878        self.nie_types = 'XT'
    79         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()),
    80                 max_length=None, min_length=None,
     79        id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE)
     80        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 '')],
    8282                *args, **kwargs)
    8383
     
    8888        nif_get_checksum = lambda d: self.nif_control[int(d)%23]
    8989
    9090        value = value.upper().replace(' ', '').replace('-', '')
    91         m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control), value)
     91        m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), value)
    9292        letter1, number, letter2 = m.groups()
    9393
    9494        if not letter1 and letter2:
  • tests/regressiontests/forms/localflavor/es.py

     
    157157'X3287690R'
    158158>>> f.clean('t-03287690r')
    159159'T03287690R'
     160>>> f.clean('P2907500I')
     161'P2907500I'
    160162>>> f.clean('X-03287690')
    161163Traceback (most recent call last):
    162164...
Back to Top