Ticket #5871: localflavor.error_messages.patch

File localflavor.error_messages.patch, 54.5 KB (added by Jan Rademaker <j.rademaker@…>, 17 years ago)
  • django/contrib/localflavor/uk/forms.py

     
    1212    The regular expression used is sourced from the schema for British Standard
    1313    BS7666 address types: http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd
    1414    """
     15    default_error_messages = {
     16        'invalid': ugettext(u'Enter a postcode. A space is required between the two postcode parts.'),
     17    }
     18   
    1519    def __init__(self, *args, **kwargs):
    1620        super(UKPostcodeField, self).__init__(r'^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW]) [0-9][ABD-HJLNP-UW-Z]{2})$',
    17             max_length=None, min_length=None,
    18             error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'),
    19             *args, **kwargs)
     21            max_length=None, min_length=None, *args, **kwargs)
    2022
    2123class UKCountySelect(Select):
    2224    """
  • django/contrib/localflavor/ca/forms.py

     
    1313 
    1414class CAPostalCodeField(RegexField):
    1515    """Canadian postal code field."""
     16    default_error_messages = {
     17        'invalid': gettext(u'Enter a postal code in the format XXX XXX.'),
     18    }
     19   
    1620    def __init__(self, *args, **kwargs):
    1721        super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXYZ]\d[A-Z] \d[A-Z]\d$',
    18             max_length=None, min_length=None,
    19             error_message=gettext(u'Enter a postal code in the format XXX XXX.'),
    20             *args, **kwargs)
     22            max_length=None, min_length=None, *args, **kwargs)
    2123 
    2224class CAPhoneNumberField(Field):
    2325    """Canadian phone number field."""
     26    default_error_messages = {
     27        'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.',
     28    }
     29   
    2430    def clean(self, value):
    2531        """Validate a phone number.
    2632        """
     
    3137        m = phone_digits_re.search(value)
    3238        if m:
    3339            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
    34         raise ValidationError(u'Phone numbers must be in XXX-XXX-XXXX format.')
     40        raise ValidationError(self.error_messages['invalid'])
    3541
    3642class CAProvinceField(Field):
    3743    """
     
    3945    It normalizes the input to the standard two-leter postal service
    4046    abbreviation for the given province.
    4147    """
     48    default_error_messages = {
     49        'invalid': u'Enter a Canadian province or territory.',
     50    }
     51   
    4252    def clean(self, value):
    4353        from ca_provinces import PROVINCES_NORMALIZED
    4454        super(CAProvinceField, self).clean(value)
     
    5363                return PROVINCES_NORMALIZED[value.strip().lower()].decode('ascii')
    5464            except KeyError:
    5565                pass
    56         raise ValidationError(u'Enter a Canadian province or territory.')
     66        raise ValidationError(self.error_messages['invalid'])
    5767 
    5868class CAProvinceSelect(Select):
    5969    """
     
    7484        * Passes the check digit process "Luhn Algorithm"
    7585             See: http://en.wikipedia.org/wiki/Social_Insurance_Number
    7686    """
     87    default_error_messages = {
     88        'invalid': ugettext('Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.'),
     89    }
     90   
    7791    def clean(self, value):
    7892        super(CASocialInsuranceNumberField, self).clean(value)
    7993        if value in EMPTY_VALUES:
    8094            return u''
    81         msg = ugettext('Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.')
     95       
    8296        match = re.match(sin_re, value)
    8397        if not match:
    84             raise ValidationError(msg)
     98            raise ValidationError(self.error_messages['invalid'])
    8599           
    86100        number = u'%s-%s-%s' % (match.group(1), match.group(2), match.group(3))   
    87101        check_number = u'%s%s%s' % (match.group(1), match.group(2), match.group(3))
    88102        if not self.luhn_checksum_is_valid(check_number):
    89             raise ValidationError(msg)
     103            raise ValidationError(self.error_messages['invalid'])
    90104        return number
    91105       
    92106    def luhn_checksum_is_valid(self, number):
  • django/contrib/localflavor/us/forms.py

     
    1212ssn_re = re.compile(r"^(?P<area>\d{3})[-\ ]?(?P<group>\d{2})[-\ ]?(?P<serial>\d{4})$")
    1313
    1414class USZipCodeField(RegexField):
     15    default_error_messages = {
     16        'invalid': ugettext('Enter a zip code in the format XXXXX or XXXXX-XXXX.'),
     17    }
     18   
    1519    def __init__(self, *args, **kwargs):
    1620        super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
    17             max_length=None, min_length=None,
    18             error_message=ugettext('Enter a zip code in the format XXXXX or XXXXX-XXXX.'),
    19                     *args, **kwargs)
     21            max_length=None, min_length=None, *args, **kwargs)
    2022
    2123class USPhoneNumberField(Field):
     24    default_error_messages = {
     25        'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.',
     26    }
     27   
    2228    def clean(self, value):
    2329        super(USPhoneNumberField, self).clean(value)
    2430        if value in EMPTY_VALUES:
     
    2733        m = phone_digits_re.search(value)
    2834        if m:
    2935            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
    30         raise ValidationError(u'Phone numbers must be in XXX-XXX-XXXX format.')
     36        raise ValidationError(self.error_messages['invalid'])
    3137
    3238class USSocialSecurityNumberField(Field):
    3339    """
     
    4450          promotional use or distribution (e.g., the Woolworth's number or the
    4551          1962 promotional number).
    4652    """
     53    default_error_messages = {
     54        'invalid': ugettext('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'),
     55    }
     56   
    4757    def clean(self, value):
    4858        super(USSocialSecurityNumberField, self).clean(value)
    4959        if value in EMPTY_VALUES:
    5060            return u''
    51         msg = ugettext('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.')
    5261        match = re.match(ssn_re, value)
    5362        if not match:
    54             raise ValidationError(msg)
     63            raise ValidationError(self.error_messages['invalid'])
    5564        area, group, serial = match.groupdict()['area'], match.groupdict()['group'], match.groupdict()['serial']
    5665
    5766        # First pass: no blocks of all zeroes.
    5867        if area == '000' or \
    5968           group == '00' or \
    6069           serial == '0000':
    61             raise ValidationError(msg)
     70            raise ValidationError(self.error_messages['invalid'])
    6271
    6372        # Second pass: promotional and otherwise permanently invalid numbers.
    6473        if area == '666' or \
    6574           (area == '987' and group == '65' and 4320 <= int(serial) <= 4329) or \
    6675           value == '078-05-1120' or \
    6776           value == '219-09-9999':
    68             raise ValidationError(msg)
     77            raise ValidationError(self.error_messages['invalid'])
    6978        return u'%s-%s-%s' % (area, group, serial)
    7079
    7180class USStateField(Field):
     
    7483    It normalizes the input to the standard two-leter postal service
    7584    abbreviation for the given state.
    7685    """
     86    default_error_messages = {
     87        'invalid': u'Enter a U.S. state or territory.',
     88    }
     89   
    7790    def clean(self, value):
    7891        from us_states import STATES_NORMALIZED
    7992        super(USStateField, self).clean(value)
     
    88101                return STATES_NORMALIZED[value.strip().lower()].decode('ascii')
    89102            except KeyError:
    90103                pass
    91         raise ValidationError(u'Enter a U.S. state or territory.')
     104        raise ValidationError(self.error_messages['invalid'])
    92105
    93106class USStateSelect(Select):
    94107    """
  • django/contrib/localflavor/de/forms.py

     
    1010id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday>\d{7})[-\ ]?(?P<validity>\d{7})[-\ ]?(?P<checksum>\d{1})$")
    1111
    1212class DEZipCodeField(RegexField):
     13    default_error_messages = {
     14        'invalid': ugettext('Enter a zip code in the format XXXXX.'),
     15    }
    1316    def __init__(self, *args, **kwargs):
    1417        super(DEZipCodeField, self).__init__(r'^\d{5}$',
    15             max_length=None, min_length=None,
    16             error_message=ugettext('Enter a zip code in the format XXXXX.'),
    17                     *args, **kwargs)
     18            max_length=None, min_length=None, *args, **kwargs)
    1819
    1920class DEStateSelect(Select):
    2021    """
     
    3637
    3738    Algorithm is documented at http://de.wikipedia.org/wiki/Personalausweis
    3839    """
     40    default_error_messages = {
     41        'invalid': ugettext('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'),
     42    }
     43   
    3944    def has_valid_checksum(self, number):
    4045        given_number, given_checksum = number[:-1], number[-1]
    4146        calculated_checksum = 0
     
    5762
    5863    def clean(self, value):
    5964        super(DEIdentityCardNumberField, self).clean(value)
    60         error_msg = ugettext('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.')
    6165        if value in EMPTY_VALUES:
    6266            return u''
    6367        match = re.match(id_re, value)
    6468        if not match:
    65             raise ValidationError(error_msg)
     69            raise ValidationError(self.error_messages['invalid'])
    6670
    6771        gd = match.groupdict()
    6872        residence, origin = gd['residence'], gd['origin']
    6973        birthday, validity, checksum = gd['birthday'], gd['validity'], gd['checksum']
    7074
    7175        if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
    72             raise ValidationError(error_msg)
     76            raise ValidationError(self.error_messages['invalid'])
    7377
    7478        all_digits = u"%s%s%s%s" % (residence, birthday, validity, checksum)
    7579        if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \
    7680            not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits):
    77                 raise ValidationError(error_msg)
     81                raise ValidationError(self.error_messages['invalid'])
    7882
    7983        return u'%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum)
  • django/contrib/localflavor/ch/forms.py

     
    1212phone_digits_re = re.compile(r'^0([1-9]{1})\d{8}$')
    1313
    1414class CHZipCodeField(RegexField):
     15    default_error_messages = {
     16        'invalid': ugettext('Enter a zip code in the format XXXX.'),
     17    }
     18   
    1519    def __init__(self, *args, **kwargs):
    1620        super(CHZipCodeField, self).__init__(r'^\d{4}$',
    17         max_length=None, min_length=None,
    18         error_message=ugettext('Enter a zip code in the format XXXX.'),
    19         *args, **kwargs)
     21        max_length=None, min_length=None, *args, **kwargs)
    2022
    2123class CHPhoneNumberField(Field):
    2224    """
     
    2527    '0XX.XXX.XX.XX' and '0XXXXXXXXX' validate but are corrected to
    2628    '0XX XXX XX XX'.
    2729    """
     30    default_error_messages = {
     31        'invalid': 'Phone numbers must be in 0XX XXX XX XX format.',
     32    }
     33   
    2834    def clean(self, value):
    2935        super(CHPhoneNumberField, self).clean(value)
    3036        if value in EMPTY_VALUES:
     
    3339        m = phone_digits_re.search(value)
    3440        if m:
    3541            return u'%s %s %s %s' % (value[0:3], value[3:6], value[6:8], value[8:10])
    36         raise ValidationError('Phone numbers must be in 0XX XXX XX XX format.')
     42        raise ValidationError(self.error_messages['invalid'])
    3743
    3844class CHStateSelect(Select):
    3945    """
     
    5460
    5561    Algorithm is documented at http://adi.kousz.ch/artikel/IDCHE.htm
    5662    """
     63    default_error_messages = {
     64        'invalid': ugettext('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'),
     65    }
     66   
    5767    def has_valid_checksum(self, number):
    5868        given_number, given_checksum = number[:-1], number[-1]
    5969        new_number = given_number
     
    8797
    8898    def clean(self, value):
    8999        super(CHIdentityCardNumberField, self).clean(value)
    90         error_msg = ugettext('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.')
    91100        if value in EMPTY_VALUES:
    92101            return u''
    93102
    94103        match = re.match(id_re, value)
    95104        if not match:
    96             raise ValidationError(error_msg)
     105            raise ValidationError(self.error_messages['invalid'])
    97106
    98107        idnumber, pos9, checksum = match.groupdict()['idnumber'], match.groupdict()['pos9'], match.groupdict()['checksum']
    99108
    100109        if idnumber == '00000000' or \
    101110           idnumber == 'A0000000':
    102             raise ValidationError(error_msg)
     111            raise ValidationError(self.error_messages['invalid'])
    103112
    104113        all_digits = "%s%s%s" % (idnumber, pos9, checksum)
    105114        if not self.has_valid_checksum(all_digits):
    106             raise ValidationError(error_msg)
     115            raise ValidationError(self.error_messages['invalid'])
    107116
    108117        return u'%s%s%s' % (idnumber, pos9, checksum)
    109118
  • django/contrib/localflavor/fi/forms.py

     
    88from django.utils.translation import ugettext
    99
    1010class FIZipCodeField(RegexField):
     11    default_error_messages = {
     12        'invalid': ugettext('Enter a zip code in the format XXXXX.'),
     13    }
    1114    def __init__(self, *args, **kwargs):
    1215        super(FIZipCodeField, self).__init__(r'^\d{5}$',
    13             max_length=None, min_length=None,
    14             error_message=ugettext('Enter a zip code in the format XXXXX.'),
    15                     *args, **kwargs)
     16            max_length=None, min_length=None, *args, **kwargs)
    1617
    1718class FIMunicipalitySelect(Select):
    1819    """
     
    2324        super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
    2425
    2526class FISocialSecurityNumber(Field):
     27    default_error_messages = {
     28        'invalid': ugettext('Enter a valid Finnish social security number.'),
     29    }
     30   
    2631    def clean(self, value):
    2732        super(FISocialSecurityNumber, self).clean(value)
    2833        if value in EMPTY_VALUES:
     
    3742            (?P<serial>(\d{3}))
    3843            (?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE)
    3944        if not result:
    40             raise ValidationError(ugettext('Enter a valid Finnish social security number.'))
     45            raise ValidationError(self.error_messages['invalid'])
    4146        gd = result.groupdict()
    4247        checksum = int(gd['date'] + gd['serial'])
    4348        if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper():
    4449            return u'%s' % value.upper()
    45         raise ValidationError(ugettext('Enter a valid Finnish social security number.'))
     50        raise ValidationError(self.error_messages['invalid'])
  • django/contrib/localflavor/cl/forms.py

     
    2525    Samples for testing are available from
    2626    https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html
    2727    """
     28    default_error_messages = {
     29        'invalid': ugettext('Enter a valid Chilean RUT.'),
     30        'strict': ugettext('Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'),
     31        'checksum': ugettext('The Chilean RUT is not valid.'),
     32    }
     33   
    2834    def __init__(self, *args, **kwargs):
    2935        if 'strict' in kwargs:
    3036            del kwargs['strict']
    3137            super(CLRutField, self).__init__(r'^(\d{1,2}\.)?\d{3}\.\d{3}-[\dkK]$',
    32                 error_message=ugettext('Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'),
    33                         *args, **kwargs)
     38                error_message=self.default_error_messages['strict'], *args, **kwargs)
    3439        else:
    3540            # In non-strict mode, accept RUTs that validate but do not exist in
    3641            # the real world.
    37             super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', error_message=ugettext('Enter valid a Chilean RUT'), *args, **kwargs)
     42            super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', *args, **kwargs)
    3843
    3944    def clean(self, value):
    4045        """
     
    4752        if self._algorithm(rut) == verificador:
    4853            return self._format(rut, verificador)
    4954        else:
    50             raise ValidationError(u'The Chilean RUT is not valid.')
     55            raise ValidationError(self.error_messages['checksum'])
    5156
    5257    def _algorithm(self, rut):
    5358        """
  • django/contrib/localflavor/ar/forms.py

     
    2424
    2525    See http://www.correoargentino.com.ar/consulta_cpa/home.php
    2626    """
     27    default_error_messages = {
     28        'invalid': ugettext("Enter a postal code in the format NNNN or ANNNNAAA."),
     29    }
     30   
    2731    def __init__(self, *args, **kwargs):
    2832        super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$',
    29             min_length=4, max_length=8,
    30             error_message=ugettext("Enter a postal code in the format NNNN or ANNNNAAA."),
    31                     *args, **kwargs)
     33            min_length=4, max_length=8, *args, **kwargs)
    3234
    3335    def clean(self, value):
    3436        value = super(ARPostalCodeField, self).clean(value)
    3537        if value in EMPTY_VALUES:
    3638            return u''
    3739        if len(value) not in (4, 8):
    38             raise ValidationError(ugettext("Enter a postal code in the format NNNN or ANNNNAAA."))
     40            raise ValidationError(self.error_messages['invalid'])
    3941        if len(value) == 8:
    4042            return u'%s%s%s' % (value[0].upper(), value[1:5], value[5:].upper())
    4143        return value
     
    4446    """
    4547    A field that validates `Documento Nacional de Identidad´ (DNI) numbers.
    4648    """
     49    default_error_messages = {
     50        'invalid': ugettext("This field requires only numbers."),
     51        'max_digits': ugettext("This field requires 7 or 8 digits."),
     52    }
     53   
    4754    def __init__(self, *args, **kwargs):
    4855        super(ARDNIField, self).__init__(max_length=10, min_length=7, *args,
    4956                **kwargs)
     
    5865        if not value.isdigit():
    5966            value = value.replace('.', '')
    6067        if not value.isdigit():
    61             raise ValidationError(ugettext("This field requires only numbers."))
     68            raise ValidationError(self.error_messages['invalid'])
    6269        if len(value) not in (7, 8):
    63             raise ValidationError(
    64                     ugettext("This field requires 7 or 8 digits."))
     70            raise ValidationError(self.error_messages['max_digits'])
    6571
    6672        return value
    6773
     
    7076    This field validates a CUIT (Código Único de Identificación Tributaria). A
    7177    CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit.
    7278    """
     79    default_error_messages = {
     80        'invalid': ugettext('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
     81        'checksum': ugettext("Invalid CUIT."),
     82    }
     83   
    7384    def __init__(self, *args, **kwargs):
    7485        super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$',
    75             error_message=ugettext('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
    7686            *args, **kwargs)
    7787
    7888    def clean(self, value):
     
    8595            return u''
    8696        value, cd = self._canon(value)
    8797        if self._calc_cd(value) != cd:
    88             raise ValidationError(ugettext("Invalid CUIT."))
     98            raise ValidationError(self.error_messages['checksum'])
    8999        return self._format(value, cd)
    90100
    91101    def _canon(self, cuit):
  • django/contrib/localflavor/br/forms.py

     
    1717phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$')
    1818
    1919class BRZipCodeField(RegexField):
     20    default_error_messages = {
     21        'invalid': _('Enter a zip code in the format XXXXX-XXX.'),
     22    }
     23   
    2024    def __init__(self, *args, **kwargs):
    2125        super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$',
    22             max_length=None, min_length=None,
    23             error_message=_('Enter a zip code in the format XXXXX-XXX.'),
    24                     *args, **kwargs)
     26            max_length=None, min_length=None, *args, **kwargs)
    2527
    2628class BRPhoneNumberField(Field):
     29    default_error_messages = {
     30        'invalid': _('Phone numbers must be in XX-XXXX-XXXX format.'),
     31    }
     32   
    2733    def clean(self, value):
    2834        super(BRPhoneNumberField, self).clean(value)
    2935        if value in EMPTY_VALUES:
     
    3238        m = phone_digits_re.search(value)
    3339        if m:
    3440            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
    35         raise ValidationError(_('Phone numbers must be in XX-XXXX-XXXX format.'))
     41        raise ValidationError(self.error_messages['invalid'])
    3642
    3743class BRStateSelect(Select):
    3844    """
     
    4854    A choice field that uses a list of Brazilian states as its choices.
    4955    """
    5056    widget = Select
     57    default_error_messages = {
     58        'invalid': _(u'Select a valid brazilian state. That state is not one of the available states.'),
     59    }
    5160
    5261    def __init__(self, required=True, widget=None, label=None,
    5362                 initial=None, help_text=None):
     
    6574            return value
    6675        valid_values = set([smart_unicode(k) for k, v in self.widget.choices])
    6776        if value not in valid_values:
    68             raise ValidationError(_(u'Select a valid brazilian state.'
    69                                            u' That state is not one'
    70                                            u' of the available states.'))
     77            raise ValidationError(self.error_messages['invalid'])
    7178        return value
    7279
    7380def DV_maker(v):
     
    8390    More information:
    8491    http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
    8592    """
     93    default_error_messages = {
     94        'invalid': _("Invalid CPF number."),
     95        'max_digits': _("This field requires at most 11 digits or 14 characters."),
     96        'digits_only': _("This field requires only numbers."),
     97    }
     98   
    8699    def __init__(self, *args, **kwargs):
    87100        super(BRCPFField, self).__init__(max_length=14, min_length=11, *args, **kwargs)
    88101
     
    100113        try:
    101114            int(value)
    102115        except ValueError:
    103             raise ValidationError(_("This field requires only numbers."))
     116            raise ValidationError(self.error_messages['digits_only'])
    104117        if len(value) != 11:
    105             raise ValidationError(_("This field requires at most 11 digits or 14 characters."))
     118            raise ValidationError(self.error_messages['max_digits'])
    106119        orig_dv = value[-2:]
    107120
    108121        new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(range(10, 1, -1))])
     
    112125        new_2dv = DV_maker(new_2dv % 11)
    113126        value = value[:-1] + str(new_2dv)
    114127        if value[-2:] != orig_dv:
    115             raise ValidationError(_("Invalid CPF number."))
     128            raise ValidationError(self.error_messages['invalid'])
    116129
    117130        return orig_value
    118131
    119132class BRCNPJField(Field):
     133    default_error_messages = {
     134        'invalid': _("Invalid CNPJ number."),
     135        'digits_only': _("This field requires only numbers."),
     136        'max_digits': _("This field requires at least 14 digits"),
     137    }
     138   
    120139    def clean(self, value):
    121140        """
    122141        Value can be either a string in the format XX.XXX.XXX/XXXX-XX or a
     
    131150        try:
    132151            int(value)
    133152        except ValueError:
    134             raise ValidationError("This field requires only numbers.")
     153            raise ValidationError(self.error_messages['digits_only'])
    135154        if len(value) != 14:
    136             raise ValidationError(
    137                 _("This field requires at least 14 digits"))
     155            raise ValidationError(self.error_messages['max_digits'])
    138156        orig_dv = value[-2:]
    139157
    140158        new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(range(5, 1, -1) + range(9, 1, -1))])
     
    144162        new_2dv = DV_maker(new_2dv % 11)
    145163        value = value[:-1] + str(new_2dv)
    146164        if value[-2:] != orig_dv:
    147             raise ValidationError(_("Invalid CNPJ number."))
     165            raise ValidationError(self.error_messages['invalid'])
    148166
    149167        return orig_value
    150 
  • django/contrib/localflavor/pe/forms.py

     
    1919    """
    2020    A field that validates `Documento Nacional de IdentidadŽ (DNI) numbers.
    2121    """
     22    default_error_messages = {
     23        'invalid': ugettext("This field requires only numbers."),
     24        'max_digits': ugettext("This field requires 8 digits."),
     25    }
     26   
    2227    def __init__(self, *args, **kwargs):
    2328        super(PEDNIField, self).__init__(max_length=8, min_length=8, *args,
    2429                **kwargs)
     
    3136        if value in EMPTY_VALUES:
    3237            return u''
    3338        if not value.isdigit():
    34             raise ValidationError(ugettext("This field requires only numbers."))
     39            raise ValidationError(self.error_messages['invalid'])
    3540        if len(value) != 8:
    36             raise ValidationError(ugettext("This field requires 8 digits."))
     41            raise ValidationError(self.error_messages['max_digits'])
    3742
    3843        return value
    3944
     
    4247    This field validates a RUC (Registro Unico de Contribuyentes). A RUC is of
    4348    the form XXXXXXXXXXX.
    4449    """
     50    default_error_messages = {
     51        'invalid': ugettext("This field requires only numbers."),
     52        'max_digits': ugettext("This field requires 11 digits."),
     53    }
     54   
    4555    def __init__(self, *args, **kwargs):
    4656        super(PERUCField, self).__init__(max_length=11, min_length=11, *args,
    4757            **kwargs)
     
    5464        if value in EMPTY_VALUES:
    5565            return u''
    5666        if not value.isdigit():
    57             raise ValidationError(ugettext("This field requires only numbers."))
     67            raise ValidationError(self.error_messages['invalid'])
    5868        if len(value) != 11:
    59             raise ValidationError(ugettext("This field requires 11 digits."))
     69            raise ValidationError(self.error_messages['max_digits'])
    6070        return value
    6171
  • django/contrib/localflavor/in_/forms.py

     
    1010
    1111
    1212class INZipCodeField(RegexField):
     13    default_error_messages = {
     14        'invalid': gettext(u'Enter a zip code in the format XXXXXXX.'),
     15    }
     16   
    1317    def __init__(self, *args, **kwargs):
    1418        super(INZipCodeField, self).__init__(r'^\d{6}$',
    15             max_length=None, min_length=None,
    16             error_message=gettext(u'Enter a zip code in the format XXXXXXX.'),
    17             *args, **kwargs)
     19            max_length=None, min_length=None, *args, **kwargs)
    1820
    1921class INStateField(Field):
    2022    """
     
    2224    abbreviation. It normalizes the input to the standard two-letter vehicle
    2325    registration abbreviation for the given state or union territory
    2426    """
     27    default_error_messages = {
     28        'invalid': u'Enter a Indian state or territory.',
     29    }
     30   
    2531    def clean(self, value):
    2632        from in_states import STATES_NORMALIZED
    2733        super(INStateField, self).clean(value)
     
    3642                return smart_unicode(STATES_NORMALIZED[value.strip().lower()])
    3743            except KeyError:
    3844                pass
    39         raise ValidationError(u'Enter a Indian state or territory.')
     45        raise ValidationError(self.error_messages['invalid'])
    4046
    4147class INStateSelect(Select):
    4248    """
  • django/contrib/localflavor/au/forms.py

     
    1212
    1313class AUPostCodeField(RegexField):
    1414    """Australian post code field."""
     15    default_error_messages = {
     16        'invalid': ugettext('Enter a 4 digit post code.'),
     17    }
     18   
    1519    def __init__(self, *args, **kwargs):
    1620        super(AUPostCodeField, self).__init__(r'^\d{4}$',
    17             max_length=None, min_length=None,
    18             error_message=ugettext('Enter a 4 digit post code.'),
    19                     *args, **kwargs)
     21            max_length=None, min_length=None, *args, **kwargs)
    2022
    2123class AUPhoneNumberField(Field):
    2224    """Australian phone number field."""
     25    default_error_messages = {
     26        'invalid': u'Phone numbers must contain 10 digits.',
     27    }
     28   
    2329    def clean(self, value):
    2430        """
    2531        Validate a phone number. Strips parentheses, whitespace and hyphens.
     
    3137        phone_match = PHONE_DIGITS_RE.search(value)
    3238        if phone_match:
    3339            return u'%s' % phone_match.group(1)
    34         raise ValidationError(u'Phone numbers must contain 10 digits.')
     40        raise ValidationError(self.error_messages['invalid'])
    3541
    3642class AUStateSelect(Select):
    3743    """
  • django/contrib/localflavor/fr/forms.py

     
    1111phone_digits_re = re.compile(r'^0\d(\s|\.)?(\d{2}(\s|\.)?){3}\d{2}$')
    1212
    1313class FRZipCodeField(RegexField):
     14    default_error_messages = {
     15        'invalid': ugettext('Enter a zip code in the format XXXXX.'),
     16    }
     17   
    1418    def __init__(self, *args, **kwargs):
    1519        super(FRZipCodeField, self).__init__(r'^\d{5}$',
    16             max_length=None, min_length=None,
    17             error_message=ugettext('Enter a zip code in the format XXXXX.'),
    18                     *args, **kwargs)
     20            max_length=None, min_length=None, *args, **kwargs)
    1921
    2022class FRPhoneNumberField(Field):
    2123    """
     
    2426    '0X.XX.XX.XX.XX' and '0XXXXXXXXX' validate but are corrected to
    2527    '0X XX XX XX XX'.
    2628    """
     29    default_error_messages = {
     30        'invalid': u'Phone numbers must be in 0X XX XX XX XX format.',
     31    }
     32   
    2733    def clean(self, value):
    2834        super(FRPhoneNumberField, self).clean(value)
    2935        if value in EMPTY_VALUES:
     
    3238        m = phone_digits_re.search(value)
    3339        if m:
    3440            return u'%s %s %s %s %s' % (value[0:2], value[2:4], value[4:6], value[6:8], value[8:10])
    35         raise ValidationError(u'Phone numbers must be in 0X XX XX XX XX format.')
     41        raise ValidationError(self.error_messages['invalid'])
    3642
    3743class FRDepartmentSelect(Select):
    3844    """
  • django/contrib/localflavor/es/forms.py

     
    1515    Spanish postal code is a five digits string, with two first digits
    1616    between 01 and 52, assigned to provinces code.
    1717    """
     18    default_error_messages = {
     19        'invalid': _('Enter a valid postal code in the range and format 01XXX - 52XXX.'),
     20    }
     21   
    1822    def __init__(self, *args, **kwargs):
    1923        super(ESPostalCodeField, self).__init__(
    2024                r'^(0[1-9]|[1-4][0-9]|5[0-2])\d{3}$',
    21                 max_length=None, min_length=None,
    22                 error_message=_('Enter a valid postal code in the range and format 01XXX - 52XXX.'),
    23                 *args, **kwargs)
     25                max_length=None, min_length=None, *args, **kwargs)
    2426
    2527class ESPhoneNumberField(RegexField):
    2628    """
     
    3335
    3436    TODO: accept and strip characters like dot, hyphen... in phone number
    3537    """
     38    default_error_messages = {
     39        'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'),
     40    }
     41   
    3642    def __init__(self, *args, **kwargs):
    3743        super(ESPhoneNumberField, self).__init__(r'^(6|8|9)\d{8}$',
    38                 max_length=None, min_length=None,
    39                 error_message=_('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'),
    40                 *args, **kwargs)
     44                max_length=None, min_length=None, *args, **kwargs)
    4145
    4246class ESIdentityCardNumberField(RegexField):
    4347    """
     
    5862    public, and different authors have different opinions on which ones allows
    5963    letters, so both validations are assumed true for all types.
    6064    """
     65    default_error_messages = {
     66        'invalid': _('Please enter a valid NIF, NIE, or CIF.'),
     67        'invalid_only_nif': _('Please enter a valid NIF or NIE.'),
     68        'invalid_nif': _('Invalid checksum for NIF.'),
     69        'invalid_nie': _('Invalid checksum for NIE.'),
     70        'invalid_cif': _('Invalid checksum for CIF.'),
     71    }
     72   
    6173    def __init__(self, only_nif=False, *args, **kwargs):
    6274        self.only_nif = only_nif
    6375        self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE'
    6476        self.cif_control = 'JABCDEFGHI'
    6577        self.cif_types = 'ABCDEFGHKLMNPQS'
    6678        self.nie_types = 'XT'
    67         if self.only_nif:
    68             self.id_types = 'NIF or NIE'
    69         else:
    70             self.id_types = 'NIF, NIE, or CIF'
    7179        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()),
    7280                max_length=None, min_length=None,
    73                 error_message=_('Please enter a valid %s.' % self.id_types),
     81                error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')],
    7482                *args, **kwargs)
    7583
    7684    def clean(self, value):
     
    8896            if letter2 == nif_get_checksum(number):
    8997                return value
    9098            else:
    91                 raise ValidationError, _('Invalid checksum for NIF.')
     99                raise ValidationError, self.error_messages['invalid_nif']
    92100        elif letter1 in self.nie_types and letter2:
    93101            # NIE
    94102            if letter2 == nif_get_checksum(number):
    95103                return value
    96104            else:
    97                 raise ValidationError, _('Invalid checksum for NIE.')
     105                raise ValidationError, self.error_messages['invalid_nie']
    98106        elif not self.only_nif and letter1 in self.cif_types and len(number) in [7, 8]:
    99107            # CIF
    100108            if not letter2:
     
    103111            if letter2 in [checksum, self.cif_control[checksum]]:
    104112                return value
    105113            else:
    106                 raise ValidationError, _('Invalid checksum for CIF.')
     114                raise ValidationError, self.error_messages['invalid_cif']
    107115        else:
    108             raise ValidationError, _('Please enter a valid %s.' % self.id_types)
     116            raise ValidationError, self.error_messages['invalid']
    109117
    110118class ESCCCField(RegexField):
    111119    """
     
    130138
    131139        TODO: allow IBAN validation too
    132140    """
     141    default_error_messages = {
     142        'invalid': _('Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'),
     143        'checksum': _('Invalid checksum for bank account number.'),
     144    }
     145   
    133146    def __init__(self, *args, **kwargs):
    134147        super(ESCCCField, self).__init__(r'^\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}$',
    135             max_length=None, min_length=None,
    136             error_message=_('Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'),
    137             *args, **kwargs)
     148            max_length=None, min_length=None, *args, **kwargs)
    138149
    139150    def clean(self, value):
    140151        super(ESCCCField, self).clean(value)
     
    147158        if get_checksum('00' + entity + office) + get_checksum(account) == checksum:
    148159            return value
    149160        else:
    150             raise ValidationError, _('Invalid checksum for bank account number.')
     161            raise ValidationError, self.error_messages['checksum']
    151162
    152163class ESRegionSelect(Select):
    153164    """
  • django/contrib/localflavor/jp/forms.py

     
    1515
    1616    Accepts 7 digits, with or without a hyphen.
    1717    """
     18    default_error_messages = {
     19        'invalid': ugettext('Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
     20    }
     21   
    1822    def __init__(self, *args, **kwargs):
    1923        super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$',
    20             max_length=None, min_length=None,
    21             error_message=ugettext('Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
    22                     *args, **kwargs)
     24            max_length=None, min_length=None, *args, **kwargs)
    2325
    2426    def clean(self, value):
    2527        """
  • django/contrib/localflavor/nl/forms.py

     
    1717    """
    1818    A Dutch postal code field.
    1919    """
     20    default_error_messages = {
     21        'invalid': _('Enter a valid postal code'),
     22    }
     23   
    2024    def clean(self, value):
    2125        super(NLZipCodeField, self).clean(value)
    2226        if value in EMPTY_VALUES:
    2327            return u''
    2428       
    25         msg = _('Enter a valid postal code')
    2629        value = value.strip().upper().replace(' ', '')
    2730        if not pc_re.search(value):
    28             raise ValidationError(msg)
     31            raise ValidationError(self.error_messages['invalid'])
    2932       
    3033        if int(value[:4]) < 1000:
    31             raise ValidationError(msg)
     34            raise ValidationError(self.error_messages['invalid'])
    3235       
    3336        return u'%s %s' % (value[:4], value[4:])
    3437
     
    4548    """
    4649    A Dutch telephone number field.
    4750    """
     51    default_error_messages = {
     52        'invalid': _('Enter a valid phone number'),
     53    }
     54   
    4855    def clean(self, value):
    4956        super(NLPhoneNumberField, self).clean(value)
    5057        if value in EMPTY_VALUES:
    5158            return u''
    5259       
    53         msg = _('Enter a valid phone number')
    5460        phone_nr = re.sub('[\-\s\(\)]', '', smart_unicode(value))
    5561       
    5662        if len(phone_nr) == 10 and numeric_re.search(phone_nr):
     
    6066           numeric_re.search(phone_nr[3:]):
    6167            return value
    6268       
    63         raise ValidationError(msg)
     69        raise ValidationError(self.error_messages['invalid'])
    6470
    6571class NLSoFiNumberField(Field):
    6672    """
     
    6874 
    6975    http://nl.wikipedia.org/wiki/Sofinummer
    7076    """
     77    default_error_messages = {
     78        'invalid': _('Enter a valid SoFi number'),
     79    }
     80   
    7181    def clean(self, value):
    7282        super(NLSoFiNumberField, self).clean(value)
    7383        if value in EMPTY_VALUES:
    7484            return u''
    7585       
    76         msg = _('Enter a valid SoFi number')
    77        
    7886        if not sofi_re.search(value):
    79             raise ValidationError(msg)
     87            raise ValidationError(self.error_messages['invalid'])
    8088       
    8189        if int(value) == 0:
    82             raise ValidationError(msg)
     90            raise ValidationError(self.error_messages['invalid'])
    8391       
    8492        checksum = 0
    8593        for i in range(9, 1, -1):
     
    8795        checksum -= int(value[-1])
    8896       
    8997        if checksum % 11 != 0:
    90             raise ValidationError(msg)
     98            raise ValidationError(self.error_messages['invalid'])
    9199       
    92100        return value
  • django/contrib/localflavor/is_/forms.py

     
    1313    Icelandic identification number (kennitala). This is a number every citizen
    1414    of Iceland has.
    1515    """
     16    default_error_messages = {
     17        'invalid': ugettext('Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.'),
     18        'checksum': ugettext(u'The Icelandic identification number is not valid.'),
     19    }
     20   
    1621    def __init__(self, *args, **kwargs):
    17         error_msg = ugettext('Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.')
    1822        kwargs['min_length'],kwargs['max_length'] = 10,11
    19         super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', error_message=error_msg, *args, **kwargs)
     23        super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', *args, **kwargs)
    2024
    2125    def clean(self, value):
    2226        value = super(ISIdNumberField, self).clean(value)
     
    2832        if self._validate(value):
    2933            return self._format(value)
    3034        else:
    31             raise ValidationError(ugettext(u'The Icelandic identification number is not valid.'))
     35            raise ValidationError(self.error_messages['checksum'])
    3236
    3337    def _canonify(self, value):
    3438        """
  • django/contrib/localflavor/za/forms.py

     
    1616    using the Luhn checksum, and uses a simlistic (read: not entirely accurate)
    1717    check for the birthdate
    1818    """
     19    default_error_messages = {
     20        'invalid': _(u'Enter a valid South African ID number'),
     21    }
    1922
    20     def __init__(self, *args, **kwargs):
    21         super(ZAIDField, self).__init__()
    22         self.error_message = _(u'Enter a valid South African ID number')
    23 
    2423    def clean(self, value):
    2524        # strip spaces and dashes
    2625        value = value.strip().replace(' ', '').replace('-', '')
     
    3332        match = re.match(id_re, value)
    3433       
    3534        if not match:
    36             raise ValidationError(self.error_message)
     35            raise ValidationError(self.error_messages['invalid'])
    3736
    3837        g = match.groupdict()
    3938
     
    4342            # There is no way to guess the century of a ZA ID number
    4443            d = date(int(g['yy']) + 2000, int(g['mm']), int(g['dd']))
    4544        except ValueError:
    46             raise ValidationError(self.error_message)
     45            raise ValidationError(self.error_messages['invalid'])
    4746
    4847        if not luhn(value):
    49             raise ValidationError(self.error_message)
     48            raise ValidationError(self.error_messages['invalid'])
    5049
    5150        return value
    5251
    5352class ZAPostCodeField(RegexField):
     53    default_error_messages = {
     54        'invalid': _(u'Enter a valid South African postal code'),
     55    }
     56   
    5457    def __init__(self, *args, **kwargs):
    5558        super(ZAPostCodeField, self).__init__(r'^\d{4}$',
    56             max_length=None, min_length=None,
    57             error_message=_(u'Enter a valid South African postal code'))
     59            max_length=None, min_length=None)
  • django/contrib/localflavor/pl/forms.py

     
    3535
    3636    The algorithm is documented at http://en.wikipedia.org/wiki/PESEL.
    3737    """
     38    default_error_messages = {
     39        'invalid': _(u'National Identification Number consists of 11 digits.'),
     40        'checksum': _(u'Wrong checksum for the National Identification Number.'),
     41    }
    3842
    3943    def __init__(self, *args, **kwargs):
    4044        super(PLNationalIdentificationNumberField, self).__init__(r'^\d{11}$',
    41             max_length=None, min_length=None, error_message=_(u'National Identification Number consists of 11 digits.'),
    42             *args, **kwargs)
     45            max_length=None, min_length=None, *args, **kwargs)
    4346
    4447    def clean(self,value):
    4548        super(PLNationalIdentificationNumberField, self).clean(value)
    4649        if not self.has_valid_checksum(value):
    47             raise ValidationError(_(u'Wrong checksum for the National Identification Number.'))
     50            raise ValidationError(self.error_messages['checksum'])
    4851        return u'%s' % value
    4952
    5053    def has_valid_checksum(self, number):
     
    6568    Checksum algorithm based on documentation at
    6669    http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
    6770    """
     71    default_error_messages = {
     72        'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),
     73        'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
     74    }
    6875
    6976    def __init__(self, *args, **kwargs):
    7077        super(PLTaxNumberField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
    71             max_length=None, min_length=None,
    72             error_message=_(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),  *args, **kwargs)
     78            max_length=None, min_length=None, *args, **kwargs)
    7379
    7480    def clean(self,value):
    7581        super(PLTaxNumberField, self).clean(value)
    7682        value = re.sub("[-]", "", value)
    7783        if not self.has_valid_checksum(value):
    78             raise ValidationError(_(u'Wrong checksum for the Tax Number (NIP).'))
     84            raise ValidationError(self.error_messages['checksum'])
    7985        return u'%s' % value
    8086
    8187    def has_valid_checksum(self, number):
     
    102108
    103109    The checksum algorithm is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
    104110    """
     111    default_error_messages = {
     112        'invalid': _(u'National Business Register Number (REGON) consists of 7 or 9 digits.'),
     113        'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'),
     114    }
     115   
    105116    def __init__(self, *args, **kwargs):
    106117        super(PLNationalBusinessRegisterField, self).__init__(r'^\d{7,9}$',
    107             max_length=None, min_length=None, error_message=_(u'National Business Register Number (REGON) consists of 7 or 9 digits.'),
    108             *args, **kwargs)
     118            max_length=None, min_length=None, *args, **kwargs)
    109119
    110120    def clean(self,value):
    111121        super(PLNationalBusinessRegisterField, self).clean(value)
    112122        if not self.has_valid_checksum(value):
    113             raise ValidationError(_(u'Wrong checksum for the National Business Register Number (REGON).'))
     123            raise ValidationError(self.error_messages['checksum'])
    114124        return u'%s' % value
    115125
    116126    def has_valid_checksum(self, number):
     
    142152    A form field that validates as Polish postal code.
    143153    Valid code is XX-XXX where X is digit.
    144154    """
     155    default_error_messages = {
     156        'invalid': _(u'Enter a postal code in the format XX-XXX.'),
     157    }
     158   
    145159    def __init__(self, *args, **kwargs):
    146160        super(PLPostalCodeField, self).__init__(r'^\d{2}-\d{3}$',
    147             max_length=None, min_length=None,
    148             error_message=_(u'Enter a postal code in the format XX-XXX.'),
    149             *args, **kwargs)
    150 
     161            max_length=None, min_length=None, *args, **kwargs)
  • django/contrib/localflavor/it/forms.py

     
    1010import re
    1111
    1212class ITZipCodeField(RegexField):
     13    default_error_messages = {
     14        'invalid': ugettext('Enter a valid zip code.'),
     15    }
    1316    def __init__(self, *args, **kwargs):
    1417        super(ITZipCodeField, self).__init__(r'^\d{5}$',
    15         max_length=None, min_length=None,
    16         error_message=ugettext('Enter a valid zip code.'),
    17                 *args, **kwargs)
     18        max_length=None, min_length=None, *args, **kwargs)
    1819
    1920class ITRegionSelect(Select):
    2021    """
     
    3839    For reference see http://www.agenziaentrate.it/ and search for
    3940    'Informazioni sulla codificazione delle persone fisiche'.
    4041    """
    41     err_msg = ugettext(u'Enter a valid Social Security number.')
     42    default_error_messages = {
     43        'invalid': ugettext(u'Enter a valid Social Security number.'),
     44    }
     45   
    4246    def __init__(self, *args, **kwargs):
    4347        super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$',
    44         max_length=None, min_length=None, error_message=self.err_msg,
    45         *args, **kwargs)
     48        max_length=None, min_length=None, *args, **kwargs)
    4649
    4750    def clean(self, value):
    4851        value = super(ITSocialSecurityNumberField, self).clean(value)
     
    5255        try:
    5356            check_digit = ssn_check_digit(value)
    5457        except ValueError:
    55             raise ValidationError(self.err_msg)
     58            raise ValidationError(self.error_messages['invalid'])
    5659        if not value[15] == check_digit:
    57             raise ValidationError(self.err_msg)
     60            raise ValidationError(self.error_messages['invalid'])
    5861        return value
    5962
    6063class ITVatNumberField(Field):
    6164    """
    6265    A form field that validates Italian VAT numbers (partita IVA).
    6366    """
     67    default_error_messages = {
     68        'invalid': ugettext(u'Enter a valid VAT number.'),
     69    }
     70   
    6471    def clean(self, value):
    6572        value = super(ITVatNumberField, self).clean(value)
    6673        if value == u'':
    6774            return value
    68         err_msg = ugettext(u'Enter a valid VAT number.')
    6975        try:
    7076            vat_number = int(value)
    7177        except ValueError:
    72             raise ValidationError(err_msg)
     78            raise ValidationError(self.error_messages['invalid'])
    7379        vat_number = str(vat_number).zfill(11)
    7480        check_digit = vat_number_check_digit(vat_number[0:10])
    7581        if not vat_number[10] == check_digit:
    76             raise ValidationError(err_msg)
     82            raise ValidationError(self.error_messages['invalid'])
    7783        return smart_unicode(vat_number)
  • django/contrib/localflavor/no/forms.py

     
    88from django.utils.translation import ugettext
    99
    1010class NOZipCodeField(RegexField):
     11    default_error_messages = {
     12        'invalid': ugettext('Enter a zip code in the format XXXX.'),
     13    }
     14   
    1115    def __init__(self, *args, **kwargs):
    1216        super(NOZipCodeField, self).__init__(r'^\d{4}$',
    13             max_length=None, min_length=None,
    14             error_message=ugettext('Enter a zip code in the format XXXX.'),
    15                     *args, **kwargs)
     17            max_length=None, min_length=None, *args, **kwargs)
    1618
    1719class NOMunicipalitySelect(Select):
    1820    """
     
    2729    """
    2830    Algorithm is documented at http://no.wikipedia.org/wiki/Personnummer
    2931    """
     32    default_error_messages = {
     33        'invalid': ugettext(u'Enter a valid Norwegian social security number.'),
     34    }
     35   
    3036    def clean(self, value):
    3137        super(NOSocialSecurityNumber, self).clean(value)
    3238        if value in EMPTY_VALUES:
    3339            return u''
    3440
    35         msg = ugettext(u'Enter a valid Norwegian social security number.')
    3641        if not re.match(r'^\d{11}$', value):
    37             raise ValidationError(msg)
     42            raise ValidationError(self.error_messages['invalid'])
    3843
    3944        day = int(value[:2])
    4045        month = int(value[2:4])
     
    5257            if 900 <= inum < 1000 and year2 > 39:
    5358                self.birthday = datetime.date(1900+year2, month, day)
    5459        except ValueError:
    55             raise ValidationError(msg)
     60            raise ValidationError(self.error_messages['invalid'])
    5661
    5762        sexnum = int(value[8])
    5863        if sexnum % 2 == 0:
     
    6873            return sum([(a * b) for (a, b) in zip(aval, bval)])
    6974
    7075        if multiply_reduce(digits, weight_1) % 11 != 0:
    71             raise ValidationError(msg)
     76            raise ValidationError(self.error_messages['invalid'])
    7277        if multiply_reduce(digits, weight_2) % 11 != 0:
    73             raise ValidationError(msg)
     78            raise ValidationError(self.error_messages['invalid'])
    7479
    7580        return value
    7681
  • django/contrib/localflavor/sk/forms.py

     
    2626    A form field that validates its input as Slovak postal code.
    2727    Valid form is XXXXX or XXX XX, where X represents integer.
    2828    """
     29    default_error_messages = {
     30        'invalid': ugettext(u'Enter a postal code in the format XXXXX or XXX XX.'),
     31    }
     32   
    2933    def __init__(self, *args, **kwargs):
    3034        super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
    31             max_length=None, min_length=None,
    32             error_message=ugettext(u'Enter a postal code in the format XXXXX or XXX XX.'),
    33             *args, **kwargs)
     35            max_length=None, min_length=None, *args, **kwargs)
    3436
    3537    def clean(self, value):
    3638        """
  • tests/regressiontests/forms/localflavor/cl.py

     
    4141>>> rut.clean('11-6')
    4242Traceback (most recent call last):
    4343...
    44 ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.']
     44ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.']
    4545
    4646# valid format, bad verifier.
    4747>>> rut.clean('11.111.111-0')
     
    5353>>> rut.clean('767484100')
    5454Traceback (most recent call last):
    5555...
    56 ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.']
     56ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.']
    5757>>> rut.clean('78.412.790-7')
    5858u'78.412.790-7'
    5959>>> rut.clean('8.334.6043')
    6060Traceback (most recent call last):
    6161...
    62 ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.']
     62ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.']
    6363>>> rut.clean('76793310-K')
    6464Traceback (most recent call last):
    6565...
    66 ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.']
     66ValidationError: [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.']
    6767
    6868## CLRegionSelect #########################################################
    6969>>> from django.contrib.localflavor.cl.forms import CLRegionSelect
Back to Top