Ticket #10204: patch_nifniecif_es.diff
File patch_nifniecif_es.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/contrib/localflavor/es/forms.py
75 75 self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE' 76 76 self.cif_control = 'JABCDEFGHI' 77 77 self.cif_types = 'ABCDEFGHKLMNPQS' 78 self.nie_types = 'X T'78 self.nie_types = 'XYZ' 79 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 80 super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None, 81 81 error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')], … … 99 99 raise ValidationError, self.error_messages['invalid_nif'] 100 100 elif letter1 in self.nie_types and letter2: 101 101 # NIE 102 if letter2 == nif_get_checksum( number):102 if letter2 == nif_get_checksum(str(self.nie_types.find(letter1)) + number): 103 103 return value 104 104 else: 105 105 raise ValidationError, self.error_messages['invalid_nie'] -
tests/regressiontests/forms/localflavor/es.py
155 155 'X0012953G' 156 156 >>> f.clean('x-3287690-r') 157 157 'X3287690R' 158 >>> f.clean('y3287690r') 159 Traceback (most recent call last): 160 ... 161 ValidationError: [u'Invalid checksum for NIE.'] 162 >>> f.clean('y3287690s') 163 'Y3287690S' 158 164 >>> f.clean('t-03287690r') 159 'T03287690R' 165 Traceback (most recent call last): 166 ... 167 ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] 160 168 >>> f.clean('P2907500I') 161 169 'P2907500I' 162 170 >>> f.clean('X-03287690') … … 226 234 >>> f.clean('x-3287690-r') 227 235 'X3287690R' 228 236 >>> f.clean('t-03287690r') 229 'T03287690R' 237 Traceback (most recent call last): 238 ... 239 ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] 230 240 >>> f.clean('X-03287690') 231 241 Traceback (most recent call last): 232 242 ...