Ticket #12595: 12595-2.diff

File 12595-2.diff, 32.0 KB (added by Claude Paroz, 14 years ago)
  • django/contrib/localflavor/ar/forms.py

    commit 10e15fc85a0867d549bb0dc686652cba8a9e3945
    Author: Claude Paroz <claude@2xlibre.net>
    Date:   Fri Apr 29 23:36:18 2011 +0200
    
        Fix init parameters to Regex/CharFields of localflavor
    
    diff --git a/django/contrib/localflavor/ar/forms.py b/django/contrib/localflavor/ar/forms.py
    index 53721a1..57b5f8b 100644
    a b class ARPostalCodeField(RegexField):  
    2828        'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."),
    2929    }
    3030
    31     def __init__(self, *args, **kwargs):
     31    def __init__(self, max_length=8, min_length=4, *args, **kwargs):
    3232        super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$',
    33             min_length=4, max_length=8, *args, **kwargs)
     33            max_length, min_length, *args, **kwargs)
    3434
    3535    def clean(self, value):
    3636        value = super(ARPostalCodeField, self).clean(value)
    class ARDNIField(CharField):  
    5151        'max_digits': _("This field requires 7 or 8 digits."),
    5252    }
    5353
    54     def __init__(self, *args, **kwargs):
    55         super(ARDNIField, self).__init__(max_length=10, min_length=7, *args,
     54    def __init__(self, max_length=10, min_length=7, *args, **kwargs):
     55        super(ARDNIField, self).__init__(max_length, min_length, *args,
    5656                **kwargs)
    5757
    5858    def clean(self, value):
    class ARCUITField(RegexField):  
    8181        'checksum': _("Invalid CUIT."),
    8282    }
    8383
    84     def __init__(self, *args, **kwargs):
     84    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    8585        super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$',
    86             *args, **kwargs)
     86            max_length, min_length, *args, **kwargs)
    8787
    8888    def clean(self, value):
    8989        """
  • django/contrib/localflavor/at/forms.py

    diff --git a/django/contrib/localflavor/at/forms.py b/django/contrib/localflavor/at/forms.py
    index cfe0206..5272136 100644
    a b class ATZipCodeField(RegexField):  
    2121    default_error_messages = {
    2222        'invalid': _('Enter a zip code in the format XXXX.'),
    2323    }
    24     def __init__(self, *args, **kwargs):
     24    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2525        super(ATZipCodeField, self).__init__(r'^\d{4}$',
    26                 max_length=None, min_length=None, *args, **kwargs)
     26                max_length, min_length, *args, **kwargs)
    2727
    2828class ATStateSelect(Select):
    2929    """
  • django/contrib/localflavor/au/forms.py

    diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py
    index 12911ea..db0bd78 100644
    a b class AUPostCodeField(RegexField):  
    2121        'invalid': _('Enter a 4 digit postcode.'),
    2222    }
    2323
    24     def __init__(self, *args, **kwargs):
    25         if 'max_length' in kwargs:
    26             kwargs.pop('max_length')
     24    def __init__(self, max_length=4, min_length=None, *args, **kwargs):
    2725        super(AUPostCodeField, self).__init__(r'^\d{4}$',
    28             max_length=4, min_length=None, *args, **kwargs)
     26            max_length, min_length, *args, **kwargs)
    2927
    3028
    3129class AUPhoneNumberField(Field):
  • django/contrib/localflavor/be/forms.py

    diff --git a/django/contrib/localflavor/be/forms.py b/django/contrib/localflavor/be/forms.py
    index 3b27f84..6715e87 100644
    a b class BEPostalCodeField(RegexField):  
    2323            'Enter a valid postal code in the range and format 1XXX - 9XXX.'),
    2424    }
    2525
    26     def __init__(self, *args, **kwargs):
     26    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2727        super(BEPostalCodeField, self).__init__(r'^[1-9]\d{3}$',
    28                 max_length=None, min_length=None, *args, **kwargs)
     28                max_length, min_length, *args, **kwargs)
    2929
    3030class BEPhoneNumberField(RegexField):
    3131    """
    class BEPhoneNumberField(RegexField):  
    5050                     '0xxxxxxxx or 04xxxxxxxx.'),
    5151    }
    5252
    53     def __init__(self, *args, **kwargs):
     53    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    5454        super(BEPhoneNumberField, self).__init__(r'^[0]\d{1}[/. ]?\d{3}[. ]\d{2}[. ]?\d{2}$|^[0]\d{2}[/. ]?\d{2}[. ]?\d{2}[. ]?\d{2}$|^[0][4]\d{2}[/. ]?\d{2}[. ]?\d{2}[. ]?\d{2}$',
    55             max_length=None, min_length=None, *args, **kwargs)
     55            max_length, min_length, *args, **kwargs)
    5656
    5757class BERegionSelect(Select):
    5858    """
  • django/contrib/localflavor/br/forms.py

    diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py
    index 7a7a858..992a58f 100644
    a b class BRZipCodeField(RegexField):  
    1717        'invalid': _('Enter a zip code in the format XXXXX-XXX.'),
    1818    }
    1919
    20     def __init__(self, *args, **kwargs):
     20    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2121        super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$',
    22             max_length=None, min_length=None, *args, **kwargs)
     22            max_length, min_length, *args, **kwargs)
    2323
    2424class BRPhoneNumberField(Field):
    2525    default_error_messages = {
    class BRCPFField(CharField):  
    9292        'digits_only': _("This field requires only numbers."),
    9393    }
    9494
    95     def __init__(self, *args, **kwargs):
    96         super(BRCPFField, self).__init__(max_length=14, min_length=11, *args, **kwargs)
     95    def __init__(self, max_length=14, min_length=11, *args, **kwargs):
     96        super(BRCPFField, self).__init__(max_length, min_length, *args, **kwargs)
    9797
    9898    def clean(self, value):
    9999        """
  • django/contrib/localflavor/ca/forms.py

    diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py
    index ae3c76e..788c9d0 100644
    a b class CAPostalCodeField(RegexField):  
    2525        'invalid': _(u'Enter a postal code in the format XXX XXX.'),
    2626    }
    2727
    28     def __init__(self, *args, **kwargs):
     28    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2929        super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] \d[ABCEGHJKLMNPRSTVWXYZ]\d$',
    30             max_length=None, min_length=None, *args, **kwargs)
     30            max_length, min_length, *args, **kwargs)
    3131
    3232class CAPhoneNumberField(Field):
    3333    """Canadian phone number field."""
  • django/contrib/localflavor/ch/forms.py

    diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py
    index eb1ae68..9ccfcf8 100644
    a b class CHZipCodeField(RegexField):  
    1717        'invalid': _('Enter a zip code in the format XXXX.'),
    1818    }
    1919
    20     def __init__(self, *args, **kwargs):
     20    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2121        super(CHZipCodeField, self).__init__(r'^\d{4}$',
    22         max_length=None, min_length=None, *args, **kwargs)
     22        max_length, min_length, *args, **kwargs)
    2323
    2424class CHPhoneNumberField(Field):
    2525    """
  • django/contrib/localflavor/cz/forms.py

    diff --git a/django/contrib/localflavor/cz/forms.py b/django/contrib/localflavor/cz/forms.py
    index 13a94af..26782d0 100644
    a b class CZPostalCodeField(RegexField):  
    2828        'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'),
    2929    }
    3030
    31     def __init__(self, *args, **kwargs):
     31    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    3232        super(CZPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
    33             max_length=None, min_length=None, *args, **kwargs)
     33            max_length, min_length, *args, **kwargs)
    3434
    3535    def clean(self, value):
    3636        """
  • django/contrib/localflavor/de/forms.py

    diff --git a/django/contrib/localflavor/de/forms.py b/django/contrib/localflavor/de/forms.py
    index a785a71..b467c2e 100644
    a b class DEZipCodeField(RegexField):  
    1414    default_error_messages = {
    1515        'invalid': _('Enter a zip code in the format XXXXX.'),
    1616    }
    17     def __init__(self, *args, **kwargs):
     17    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    1818        super(DEZipCodeField, self).__init__(r'^\d{5}$',
    19             max_length=None, min_length=None, *args, **kwargs)
     19            max_length, min_length, *args, **kwargs)
    2020
    2121class DEStateSelect(Select):
    2222    """
  • django/contrib/localflavor/es/forms.py

    diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py
    index 000f695..42e8e9d 100644
    a b class ESPostalCodeField(RegexField):  
    2020        'invalid': _('Enter a valid postal code in the range and format 01XXX - 52XXX.'),
    2121    }
    2222
    23     def __init__(self, *args, **kwargs):
     23    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2424        super(ESPostalCodeField, self).__init__(
    2525                r'^(0[1-9]|[1-4][0-9]|5[0-2])\d{3}$',
    26                 max_length=None, min_length=None, *args, **kwargs)
     26                max_length, min_length, *args, **kwargs)
    2727
    2828class ESPhoneNumberField(RegexField):
    2929    """
    class ESPhoneNumberField(RegexField):  
    4040        'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'),
    4141    }
    4242
    43     def __init__(self, *args, **kwargs):
     43    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    4444        super(ESPhoneNumberField, self).__init__(r'^(6|7|8|9)\d{8}$',
    45                 max_length=None, min_length=None, *args, **kwargs)
     45                max_length, min_length, *args, **kwargs)
    4646
    4747class ESIdentityCardNumberField(RegexField):
    4848    """
    class ESIdentityCardNumberField(RegexField):  
    7171        'invalid_cif': _('Invalid checksum for CIF.'),
    7272    }
    7373
    74     def __init__(self, only_nif=False, *args, **kwargs):
     74    def __init__(self, only_nif=False, max_length=None, min_length=None, *args, **kwargs):
    7575        self.only_nif = only_nif
    7676        self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE'
    7777        self.cif_control = 'JABCDEFGHI'
    7878        self.cif_types = 'ABCDEFGHKLMNPQS'
    7979        self.nie_types = 'XT'
    8080        id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE)
    81         super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None,
     81        super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length, min_length,
    8282                error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')],
    8383                *args, **kwargs)
    8484
    class ESCCCField(RegexField):  
    144144        'checksum': _('Invalid checksum for bank account number.'),
    145145    }
    146146
    147     def __init__(self, *args, **kwargs):
     147    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    148148        super(ESCCCField, self).__init__(r'^\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}$',
    149             max_length=None, min_length=None, *args, **kwargs)
     149            max_length, min_length, *args, **kwargs)
    150150
    151151    def clean(self, value):
    152152        super(ESCCCField, self).clean(value)
  • django/contrib/localflavor/fi/forms.py

    diff --git a/django/contrib/localflavor/fi/forms.py b/django/contrib/localflavor/fi/forms.py
    index 9c163c9..7556173 100644
    a b class FIZipCodeField(RegexField):  
    1212    default_error_messages = {
    1313        'invalid': _('Enter a zip code in the format XXXXX.'),
    1414    }
    15     def __init__(self, *args, **kwargs):
     15    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    1616        super(FIZipCodeField, self).__init__(r'^\d{5}$',
    17             max_length=None, min_length=None, *args, **kwargs)
     17            max_length, min_length, *args, **kwargs)
    1818
    1919class FIMunicipalitySelect(Select):
    2020    """
  • django/contrib/localflavor/fr/forms.py

    diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py
    index 963eadc..54f933a 100644
    a b class FRZipCodeField(RegexField):  
    1616        'invalid': _('Enter a zip code in the format XXXXX.'),
    1717    }
    1818
    19     def __init__(self, *args, **kwargs):
     19    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2020        super(FRZipCodeField, self).__init__(r'^\d{5}$',
    21             max_length=None, min_length=None, *args, **kwargs)
     21            max_length, min_length, *args, **kwargs)
    2222
    2323class FRPhoneNumberField(Field):
    2424    """
  • django/contrib/localflavor/hr/forms.py

    diff --git a/django/contrib/localflavor/hr/forms.py b/django/contrib/localflavor/hr/forms.py
    index 7bc9ba1..6d50b63 100644
    a b class HROIBField(RegexField):  
    120120        'invalid': _('Enter a valid 11 digit OIB'),
    121121    }
    122122
    123     def __init__(self, *args, **kwargs):
     123    def __init__(self, min_length=11, max_length=11, *args, **kwargs):
    124124        super(HROIBField, self).__init__(r'^\d{11}$',
    125             min_length=11, max_length=11, *args, **kwargs)
     125            min_length, max_length, *args, **kwargs)
    126126
    127127    def clean(self, value):
    128128        super(HROIBField, self).clean(value)
  • django/contrib/localflavor/in_/forms.py

    diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py
    index 0597623..c94c7e7 100644
    a b class INZipCodeField(RegexField):  
    1515        'invalid': gettext(u'Enter a zip code in the format XXXXXXX.'),
    1616    }
    1717
    18     def __init__(self, *args, **kwargs):
     18    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    1919        super(INZipCodeField, self).__init__(r'^\d{6}$',
    20             max_length=None, min_length=None, *args, **kwargs)
     20            max_length, min_length, *args, **kwargs)
    2121
    2222class INStateField(Field):
    2323    """
  • django/contrib/localflavor/is_/forms.py

    diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py
    index abf858d..d651cac 100644
    a b class ISIdNumberField(RegexField):  
    1919        'checksum': _(u'The Icelandic identification number is not valid.'),
    2020    }
    2121
    22     def __init__(self, *args, **kwargs):
    23         kwargs['min_length'],kwargs['max_length'] = 10,11
    24         super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', *args, **kwargs)
     22    def __init__(self, max_length=11, min_length=10, *args, **kwargs):
     23        super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$',
     24            max_length, min_length, *args, **kwargs)
    2525
    2626    def clean(self, value):
    2727        value = super(ISIdNumberField, self).clean(value)
    class ISPhoneNumberField(RegexField):  
    6161    Icelandic phone number. Seven digits with an optional hyphen or space after
    6262    the first three digits.
    6363    """
    64     def __init__(self, *args, **kwargs):
    65         kwargs['min_length'], kwargs['max_length'] = 7,8
    66         super(ISPhoneNumberField, self).__init__(r'^\d{3}(-| )?\d{4}$', *args, **kwargs)
     64    def __init__(self, max_length=8, min_length=7, *args, **kwargs):
     65        super(ISPhoneNumberField, self).__init__(r'^\d{3}(-| )?\d{4}$',
     66            max_length, min_length, *args, **kwargs)
    6767
    6868    def clean(self, value):
    6969        value = super(ISPhoneNumberField, self).clean(value)
  • django/contrib/localflavor/it/forms.py

    diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py
    index bf02276..460ebff 100644
    a b class ITZipCodeField(RegexField):  
    1414    default_error_messages = {
    1515        'invalid': _('Enter a valid zip code.'),
    1616    }
    17     def __init__(self, *args, **kwargs):
     17    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    1818        super(ITZipCodeField, self).__init__(r'^\d{5}$',
    19         max_length=None, min_length=None, *args, **kwargs)
     19              max_length, min_length, *args, **kwargs)
    2020
    2121class ITRegionSelect(Select):
    2222    """
    class ITSocialSecurityNumberField(RegexField):  
    4444        'invalid': _(u'Enter a valid Social Security number.'),
    4545    }
    4646
    47     def __init__(self, *args, **kwargs):
     47    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    4848        super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$',
    49         max_length=None, min_length=None, *args, **kwargs)
     49              max_length, min_length, *args, **kwargs)
    5050
    5151    def clean(self, value):
    5252        value = super(ITSocialSecurityNumberField, self).clean(value)
  • django/contrib/localflavor/jp/forms.py

    diff --git a/django/contrib/localflavor/jp/forms.py b/django/contrib/localflavor/jp/forms.py
    index 1d765c8..248a938 100644
    a b class JPPostalCodeField(RegexField):  
    1616        'invalid': _('Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
    1717    }
    1818
    19     def __init__(self, *args, **kwargs):
     19    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2020        super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$',
    21             max_length=None, min_length=None, *args, **kwargs)
     21            max_length, min_length, *args, **kwargs)
    2222
    2323    def clean(self, value):
    2424        """
  • django/contrib/localflavor/no/forms.py

    diff --git a/django/contrib/localflavor/no/forms.py b/django/contrib/localflavor/no/forms.py
    index 61a269c..abe3b80 100644
    a b class NOZipCodeField(RegexField):  
    1313        'invalid': _('Enter a zip code in the format XXXX.'),
    1414    }
    1515
    16     def __init__(self, *args, **kwargs):
     16    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    1717        super(NOZipCodeField, self).__init__(r'^\d{4}$',
    18             max_length=None, min_length=None, *args, **kwargs)
     18            max_length, min_length, *args, **kwargs)
    1919
    2020class NOMunicipalitySelect(Select):
    2121    """
  • django/contrib/localflavor/pe/forms.py

    diff --git a/django/contrib/localflavor/pe/forms.py b/django/contrib/localflavor/pe/forms.py
    index 7a4ac9e..c1b4195 100644
    a b class PEDNIField(CharField):  
    2525        'max_digits': _("This field requires 8 digits."),
    2626    }
    2727
    28     def __init__(self, *args, **kwargs):
    29         super(PEDNIField, self).__init__(max_length=8, min_length=8, *args,
     28    def __init__(self, max_length=8, min_length=8, *args, **kwargs):
     29        super(PEDNIField, self).__init__(max_length, min_length, *args,
    3030                **kwargs)
    3131
    3232    def clean(self, value):
    class PERUCField(RegexField):  
    5353        'max_digits': _("This field requires 11 digits."),
    5454    }
    5555
    56     def __init__(self, *args, **kwargs):
    57         super(PERUCField, self).__init__(max_length=11, min_length=11, *args,
     56    def __init__(self, max_length=11, min_length=11, *args, **kwargs):
     57        super(PERUCField, self).__init__(max_length, min_length, *args,
    5858            **kwargs)
    5959
    6060    def clean(self, value):
  • django/contrib/localflavor/pl/forms.py

    diff --git a/django/contrib/localflavor/pl/forms.py b/django/contrib/localflavor/pl/forms.py
    index ef4a38b..8b4d2f4 100644
    a b class PLPESELField(RegexField):  
    4040        'checksum': _(u'Wrong checksum for the National Identification Number.'),
    4141    }
    4242
    43     def __init__(self, *args, **kwargs):
     43    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    4444        super(PLPESELField, self).__init__(r'^\d{11}$',
    45             max_length=None, min_length=None, *args, **kwargs)
     45            max_length, min_length, *args, **kwargs)
    4646
    4747    def clean(self, value):
    4848        super(PLPESELField, self).clean(value)
    class PLNationalIDCardNumberField(RegexField):  
    7777        'checksum': _(u'Wrong checksum for the National ID Card Number.'),
    7878    }
    7979
    80     def __init__(self, *args, **kwargs):
     80    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    8181        super(PLNationalIDCardNumberField, self).__init__(r'^[A-Za-z]{3}\d{6}$',
    82             max_length=None, min_length=None, *args, **kwargs)
     82            max_length, min_length, *args, **kwargs)
    8383
    8484    def clean(self,value):
    8585        super(PLNationalIDCardNumberField, self).clean(value)
    class PLNIPField(RegexField):  
    129129        'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
    130130    }
    131131
    132     def __init__(self, *args, **kwargs):
     132    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    133133        super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
    134             max_length=None, min_length=None, *args, **kwargs)
     134            max_length, min_length, *args, **kwargs)
    135135
    136136    def clean(self,value):
    137137        super(PLNIPField, self).clean(value)
    class PLREGONField(RegexField):  
    169169        'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'),
    170170    }
    171171
    172     def __init__(self, *args, **kwargs):
     172    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    173173        super(PLREGONField, self).__init__(r'^\d{9,14}$',
    174             max_length=None, min_length=None, *args, **kwargs)
     174            max_length, min_length, *args, **kwargs)
    175175
    176176    def clean(self,value):
    177177        super(PLREGONField, self).clean(value)
    class PLPostalCodeField(RegexField):  
    209209        'invalid': _(u'Enter a postal code in the format XX-XXX.'),
    210210    }
    211211
    212     def __init__(self, *args, **kwargs):
     212    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    213213        super(PLPostalCodeField, self).__init__(r'^\d{2}-\d{3}$',
    214             max_length=None, min_length=None, *args, **kwargs)
     214            max_length, min_length, *args, **kwargs)
    215215
  • django/contrib/localflavor/pt/forms.py

    diff --git a/django/contrib/localflavor/pt/forms.py b/django/contrib/localflavor/pt/forms.py
    index 1f51679..2a563cf 100644
    a b class PTZipCodeField(RegexField):  
    1717        'invalid': _('Enter a zip code in the format XXXX-XXX.'),
    1818    }
    1919
    20     def __init__(self, *args, **kwargs):
     20    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2121        super(PTZipCodeField, self).__init__(r'^(\d{4}-\d{3}|\d{7})$',
    22             max_length=None, min_length=None, *args, **kwargs)
     22            max_length, min_length, *args, **kwargs)
    2323
    2424    def clean(self,value):
    2525        cleaned = super(PTZipCodeField, self).clean(value)
  • django/contrib/localflavor/ro/forms.py

    diff --git a/django/contrib/localflavor/ro/forms.py b/django/contrib/localflavor/ro/forms.py
    index a218bfd..3bfb0fa 100644
    a b class ROCIFField(RegexField):  
    1919        'invalid': _("Enter a valid CIF."),
    2020    }
    2121
    22     def __init__(self, *args, **kwargs):
    23         super(ROCIFField, self).__init__(r'^(RO)?[0-9]{2,10}', max_length=10,
    24                 min_length=2, *args, **kwargs)
     22    def __init__(self, max_length=10, min_length=2, *args, **kwargs):
     23        super(ROCIFField, self).__init__(r'^(RO)?[0-9]{2,10}', max_length,
     24                min_length, *args, **kwargs)
    2525
    2626    def clean(self, value):
    2727        """
    class ROCNPField(RegexField):  
    5656        'invalid': _("Enter a valid CNP."),
    5757    }
    5858
    59     def __init__(self, *args, **kwargs):
    60         super(ROCNPField, self).__init__(r'^[1-9][0-9]{12}', max_length=13,
    61             min_length=13, *args, **kwargs)
     59    def __init__(self, max_length=13, min_length=13, *args, **kwargs):
     60        super(ROCNPField, self).__init__(r'^[1-9][0-9]{12}', max_length,
     61            min_length, *args, **kwargs)
    6262
    6363    def clean(self, value):
    6464        """
    class ROIBANField(RegexField):  
    143143        'invalid': _('Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'),
    144144    }
    145145
    146     def __init__(self, *args, **kwargs):
     146    def __init__(self, max_length=40, min_length=24, *args, **kwargs):
    147147        super(ROIBANField, self).__init__(r'^[0-9A-Za-z\-\s]{24,40}$',
    148                 max_length=40, min_length=24, *args, **kwargs)
     148                max_length, min_length, *args, **kwargs)
    149149
    150150    def clean(self, value):
    151151        """
    class ROPhoneNumberField(RegexField):  
    175175        'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'),
    176176    }
    177177
    178     def __init__(self, *args, **kwargs):
     178    def __init__(self, max_length=20, min_length=10, *args, **kwargs):
    179179        super(ROPhoneNumberField, self).__init__(r'^[0-9\-\(\)\s]{10,20}$',
    180                 max_length=20, min_length=10, *args, **kwargs)
     180                max_length, min_length, *args, **kwargs)
    181181
    182182    def clean(self, value):
    183183        """
    class ROPostalCodeField(RegexField):  
    200200        'invalid': _('Enter a valid postal code in the format XXXXXX'),
    201201    }
    202202
    203     def __init__(self, *args, **kwargs):
     203    def __init__(self, max_length=6, min_length=6, *args, **kwargs):
    204204        super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$',
    205                 max_length=6, min_length=6, *args, **kwargs)
     205                max_length, min_length, *args, **kwargs)
    206206
  • django/contrib/localflavor/ru/forms.py

    diff --git a/django/contrib/localflavor/ru/forms.py b/django/contrib/localflavor/ru/forms.py
    index fa3c245..d091eab 100644
    a b class RUPostalCodeField(RegexField):  
    3737    default_error_messages = {
    3838        'invalid': _(u'Enter a postal code in the format XXXXXX.'),
    3939    }
    40     def __init__(self, *args, **kwargs):
     40    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    4141        super(RUPostalCodeField, self).__init__(r'^\d{6}$',
    42             max_length=None, min_length=None, *args, **kwargs)
     42            max_length, min_length, *args, **kwargs)
    4343
    4444
    4545class RUPassportNumberField(RegexField):
    class RUPassportNumberField(RegexField):  
    5050    default_error_messages = {
    5151        'invalid': _(u'Enter a passport number in the format XXXX XXXXXX.'),
    5252    }
    53     def __init__(self, *args, **kwargs):
     53    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    5454        super(RUPassportNumberField, self).__init__(r'^\d{4} \d{6}$',
    55             max_length=None, min_length=None, *args, **kwargs)
     55            max_length, min_length, *args, **kwargs)
    5656
    5757
    5858class RUAlienPassportNumberField(RegexField):
    class RUAlienPassportNumberField(RegexField):  
    6363    default_error_messages = {
    6464        'invalid': _(u'Enter a passport number in the format XX XXXXXXX.'),
    6565    }
    66     def __init__(self, *args, **kwargs):
     66    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    6767        super(RUAlienPassportNumberField, self).__init__(r'^\d{2} \d{7}$',
    68             max_length=None, min_length=None, *args, **kwargs)
     68            max_length, min_length, *args, **kwargs)
  • django/contrib/localflavor/sk/forms.py

    diff --git a/django/contrib/localflavor/sk/forms.py b/django/contrib/localflavor/sk/forms.py
    index 863a612..389e7b7 100644
    a b class SKPostalCodeField(RegexField):  
    3030        'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'),
    3131    }
    3232
    33     def __init__(self, *args, **kwargs):
     33    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    3434        super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
    35             max_length=None, min_length=None, *args, **kwargs)
     35            max_length, min_length, *args, **kwargs)
    3636
    3737    def clean(self, value):
    3838        """
  • django/contrib/localflavor/tr/forms.py

    diff --git a/django/contrib/localflavor/tr/forms.py b/django/contrib/localflavor/tr/forms.py
    index 51e4460..d2ae9bb 100644
    a b class TRPostalCodeField(RegexField):  
    1616        'invalid': _(u'Enter a postal code in the format XXXXX.'),
    1717    }
    1818
    19     def __init__(self, *args, **kwargs):
     19    def __init__(self, max_length=5, min_length=5, *args, **kwargs):
    2020        super(TRPostalCodeField, self).__init__(r'^\d{5}$',
    21             max_length=5, min_length=5, *args, **kwargs)
     21            max_length, min_length, *args, **kwargs)
    2222
    2323    def clean(self, value):
    2424        value = super(TRPostalCodeField, self).clean(value)
  • django/contrib/localflavor/us/forms.py

    diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
    index a41f7ab..36d7645 100644
    a b class USZipCodeField(RegexField):  
    1717        'invalid': _('Enter a zip code in the format XXXXX or XXXXX-XXXX.'),
    1818    }
    1919
    20     def __init__(self, *args, **kwargs):
     20    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    2121        super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
    22             max_length=None, min_length=None, *args, **kwargs)
     22            max_length, min_length, *args, **kwargs)
    2323
    2424class USPhoneNumberField(CharField):
    2525    default_error_messages = {
  • django/contrib/localflavor/za/forms.py

    diff --git a/django/contrib/localflavor/za/forms.py b/django/contrib/localflavor/za/forms.py
    index 4fb4203..a9e2cd6 100644
    a b South Africa-specific Form helpers  
    44
    55from django.core.validators import EMPTY_VALUES
    66from django.forms import ValidationError
    7 from django.forms.fields import Field, RegexField
     7from django.forms.fields import CharField, RegexField
    88from django.utils.checksums import luhn
    99from django.utils.translation import gettext as _
    1010import re
    from datetime import date  
    1212
    1313id_re = re.compile(r'^(?P<yy>\d\d)(?P<mm>\d\d)(?P<dd>\d\d)(?P<mid>\d{4})(?P<end>\d{3})')
    1414
    15 class ZAIDField(Field):
     15class ZAIDField(CharField):
    1616    """A form field for South African ID numbers -- the checksum is validated
    1717    using the Luhn checksum, and uses a simlistic (read: not entirely accurate)
    1818    check for the birthdate
    class ZAPostCodeField(RegexField):  
    5555        'invalid': _(u'Enter a valid South African postal code'),
    5656    }
    5757
    58     def __init__(self, *args, **kwargs):
     58    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    5959        super(ZAPostCodeField, self).__init__(r'^\d{4}$',
    60             max_length=None, min_length=None, *args, **kwargs)
     60            max_length, min_length, *args, **kwargs)
  • tests/regressiontests/forms/localflavor/utils.py

    diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py
    index 482f7ad..31d53dd 100644
    a b  
    11from django.core.exceptions import ValidationError
    22from django.core.validators import EMPTY_VALUES
     3from django.forms.fields import CharField
    34from django.test.utils import get_warnings_state, restore_warnings_state
    45from django.utils.unittest import TestCase
    56
    class LocalFlavorTestCase(TestCase):  
    1314    def restore_warnings_state(self):
    1415        restore_warnings_state(self._warnings_state)
    1516
    16     def assertFieldOutput(self, fieldclass, valid, invalid, field_args=[],
    17             field_kwargs={}, empty_value=u''):
     17    def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
     18            field_kwargs=None, empty_value=u''):
    1819        """
    1920        Asserts that a field behaves correctly with various inputs.
    2021
    class LocalFlavorTestCase(TestCase):  
    2930            empty_value: the expected clean output for inputs in EMPTY_VALUES
    3031
    3132        """
     33        if field_args is None:
     34            field_args = []
     35        if field_kwargs is None:
     36            field_kwargs = {}
    3237        required = fieldclass(*field_args, **field_kwargs)
    3338        optional = fieldclass(*field_args, **dict(field_kwargs, required=False))
    3439        # test valid inputs
    class LocalFlavorTestCase(TestCase):  
    4954            self.assertRaisesRegexp(ValidationError, error_required,
    5055                required.clean, e)
    5156            self.assertEqual(optional.clean(e), empty_value)
     57        # test that max_length and min_length are always accepted
     58        if issubclass(fieldclass, CharField):
     59            field_kwargs.update({'min_length':2, 'max_length':20})
     60            self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), fieldclass))
Back to Top