diff --git a/django/contrib/localflavor/ar/forms.py b/django/contrib/localflavor/ar/forms.py index 53721a17b6..57b5f8b6eb 100644 --- a/django/contrib/localflavor/ar/forms.py +++ b/django/contrib/localflavor/ar/forms.py @@ -28,9 +28,9 @@ class ARPostalCodeField(RegexField): 'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=8, min_length=4, *args, **kwargs): super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$', - min_length=4, max_length=8, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): value = super(ARPostalCodeField, self).clean(value) @@ -51,8 +51,8 @@ class ARDNIField(CharField): 'max_digits': _("This field requires 7 or 8 digits."), } - def __init__(self, *args, **kwargs): - super(ARDNIField, self).__init__(max_length=10, min_length=7, *args, + def __init__(self, max_length=10, min_length=7, *args, **kwargs): + super(ARDNIField, self).__init__(max_length, min_length, *args, **kwargs) def clean(self, value): @@ -81,9 +81,9 @@ class ARCUITField(RegexField): 'checksum': _("Invalid CUIT."), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$', - *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ diff --git a/django/contrib/localflavor/at/forms.py b/django/contrib/localflavor/at/forms.py index cfe02063c2..52721368e0 100644 --- a/django/contrib/localflavor/at/forms.py +++ b/django/contrib/localflavor/at/forms.py @@ -21,9 +21,9 @@ class ATZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a zip code in the format XXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ATZipCodeField, self).__init__(r'^\d{4}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class ATStateSelect(Select): """ diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py index 12911ea8a3..db0bd78c9b 100644 --- a/django/contrib/localflavor/au/forms.py +++ b/django/contrib/localflavor/au/forms.py @@ -21,11 +21,9 @@ class AUPostCodeField(RegexField): 'invalid': _('Enter a 4 digit postcode.'), } - def __init__(self, *args, **kwargs): - if 'max_length' in kwargs: - kwargs.pop('max_length') + def __init__(self, max_length=4, min_length=None, *args, **kwargs): super(AUPostCodeField, self).__init__(r'^\d{4}$', - max_length=4, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class AUPhoneNumberField(Field): diff --git a/django/contrib/localflavor/be/forms.py b/django/contrib/localflavor/be/forms.py index 3b27f84252..6715e8755e 100644 --- a/django/contrib/localflavor/be/forms.py +++ b/django/contrib/localflavor/be/forms.py @@ -23,9 +23,9 @@ class BEPostalCodeField(RegexField): 'Enter a valid postal code in the range and format 1XXX - 9XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(BEPostalCodeField, self).__init__(r'^[1-9]\d{3}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class BEPhoneNumberField(RegexField): """ @@ -50,9 +50,9 @@ class BEPhoneNumberField(RegexField): '0xxxxxxxx or 04xxxxxxxx.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): 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}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class BERegionSelect(Select): """ diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py index 7a7a858779..992a58fd45 100644 --- a/django/contrib/localflavor/br/forms.py +++ b/django/contrib/localflavor/br/forms.py @@ -17,9 +17,9 @@ class BRZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXXX-XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class BRPhoneNumberField(Field): default_error_messages = { @@ -92,8 +92,8 @@ class BRCPFField(CharField): 'digits_only': _("This field requires only numbers."), } - def __init__(self, *args, **kwargs): - super(BRCPFField, self).__init__(max_length=14, min_length=11, *args, **kwargs) + def __init__(self, max_length=14, min_length=11, *args, **kwargs): + super(BRCPFField, self).__init__(max_length, min_length, *args, **kwargs) def clean(self, value): """ diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py index ae3c76e24a..788c9d0a6f 100644 --- a/django/contrib/localflavor/ca/forms.py +++ b/django/contrib/localflavor/ca/forms.py @@ -25,9 +25,9 @@ class CAPostalCodeField(RegexField): 'invalid': _(u'Enter a postal code in the format XXX XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(CAPostalCodeField, self).__init__(r'^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] \d[ABCEGHJKLMNPRSTVWXYZ]\d$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class CAPhoneNumberField(Field): """Canadian phone number field.""" diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py index eb1ae68844..9ccfcf8f18 100644 --- a/django/contrib/localflavor/ch/forms.py +++ b/django/contrib/localflavor/ch/forms.py @@ -17,9 +17,9 @@ class CHZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(CHZipCodeField, self).__init__(r'^\d{4}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class CHPhoneNumberField(Field): """ diff --git a/django/contrib/localflavor/cz/forms.py b/django/contrib/localflavor/cz/forms.py index 13a94af05c..26782d06cb 100644 --- a/django/contrib/localflavor/cz/forms.py +++ b/django/contrib/localflavor/cz/forms.py @@ -28,9 +28,9 @@ class CZPostalCodeField(RegexField): 'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(CZPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ diff --git a/django/contrib/localflavor/de/forms.py b/django/contrib/localflavor/de/forms.py index a785a7194e..b467c2e287 100644 --- a/django/contrib/localflavor/de/forms.py +++ b/django/contrib/localflavor/de/forms.py @@ -14,9 +14,9 @@ class DEZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a zip code in the format XXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(DEZipCodeField, self).__init__(r'^\d{5}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class DEStateSelect(Select): """ diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py index 000f695630..42e8e9df2c 100644 --- a/django/contrib/localflavor/es/forms.py +++ b/django/contrib/localflavor/es/forms.py @@ -20,10 +20,10 @@ class ESPostalCodeField(RegexField): 'invalid': _('Enter a valid postal code in the range and format 01XXX - 52XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ESPostalCodeField, self).__init__( r'^(0[1-9]|[1-4][0-9]|5[0-2])\d{3}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class ESPhoneNumberField(RegexField): """ @@ -40,9 +40,9 @@ class ESPhoneNumberField(RegexField): 'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ESPhoneNumberField, self).__init__(r'^(6|7|8|9)\d{8}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class ESIdentityCardNumberField(RegexField): """ @@ -71,14 +71,14 @@ class ESIdentityCardNumberField(RegexField): 'invalid_cif': _('Invalid checksum for CIF.'), } - def __init__(self, only_nif=False, *args, **kwargs): + def __init__(self, only_nif=False, max_length=None, min_length=None, *args, **kwargs): self.only_nif = only_nif self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE' self.cif_control = 'JABCDEFGHI' self.cif_types = 'ABCDEFGHKLMNPQS' self.nie_types = 'XT' id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE) - super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None, + super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length, min_length, error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')], *args, **kwargs) @@ -144,9 +144,9 @@ class ESCCCField(RegexField): 'checksum': _('Invalid checksum for bank account number.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ESCCCField, self).__init__(r'^\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): super(ESCCCField, self).clean(value) diff --git a/django/contrib/localflavor/fi/forms.py b/django/contrib/localflavor/fi/forms.py index 9c163c9143..7556173ece 100644 --- a/django/contrib/localflavor/fi/forms.py +++ b/django/contrib/localflavor/fi/forms.py @@ -12,9 +12,9 @@ class FIZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a zip code in the format XXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(FIZipCodeField, self).__init__(r'^\d{5}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class FIMunicipalitySelect(Select): """ diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py index 963eadc86a..54f933a31d 100644 --- a/django/contrib/localflavor/fr/forms.py +++ b/django/contrib/localflavor/fr/forms.py @@ -16,9 +16,9 @@ class FRZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(FRZipCodeField, self).__init__(r'^\d{5}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class FRPhoneNumberField(Field): """ diff --git a/django/contrib/localflavor/hr/forms.py b/django/contrib/localflavor/hr/forms.py index 7bc9ba153a..6d50b6335f 100644 --- a/django/contrib/localflavor/hr/forms.py +++ b/django/contrib/localflavor/hr/forms.py @@ -120,9 +120,9 @@ class HROIBField(RegexField): 'invalid': _('Enter a valid 11 digit OIB'), } - def __init__(self, *args, **kwargs): + def __init__(self, min_length=11, max_length=11, *args, **kwargs): super(HROIBField, self).__init__(r'^\d{11}$', - min_length=11, max_length=11, *args, **kwargs) + min_length, max_length, *args, **kwargs) def clean(self, value): super(HROIBField, self).clean(value) diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py index 0597623400..c94c7e7a1e 100644 --- a/django/contrib/localflavor/in_/forms.py +++ b/django/contrib/localflavor/in_/forms.py @@ -15,9 +15,9 @@ class INZipCodeField(RegexField): 'invalid': gettext(u'Enter a zip code in the format XXXXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(INZipCodeField, self).__init__(r'^\d{6}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class INStateField(Field): """ diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py index abf858df2b..d651cac33f 100644 --- a/django/contrib/localflavor/is_/forms.py +++ b/django/contrib/localflavor/is_/forms.py @@ -19,9 +19,9 @@ class ISIdNumberField(RegexField): 'checksum': _(u'The Icelandic identification number is not valid.'), } - def __init__(self, *args, **kwargs): - kwargs['min_length'],kwargs['max_length'] = 10,11 - super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', *args, **kwargs) + def __init__(self, max_length=11, min_length=10, *args, **kwargs): + super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', + max_length, min_length, *args, **kwargs) def clean(self, value): value = super(ISIdNumberField, self).clean(value) @@ -61,9 +61,9 @@ class ISPhoneNumberField(RegexField): Icelandic phone number. Seven digits with an optional hyphen or space after the first three digits. """ - def __init__(self, *args, **kwargs): - kwargs['min_length'], kwargs['max_length'] = 7,8 - super(ISPhoneNumberField, self).__init__(r'^\d{3}(-| )?\d{4}$', *args, **kwargs) + def __init__(self, max_length=8, min_length=7, *args, **kwargs): + super(ISPhoneNumberField, self).__init__(r'^\d{3}(-| )?\d{4}$', + max_length, min_length, *args, **kwargs) def clean(self, value): value = super(ISPhoneNumberField, self).clean(value) diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py index bf0227608a..460ebffaa1 100644 --- a/django/contrib/localflavor/it/forms.py +++ b/django/contrib/localflavor/it/forms.py @@ -14,9 +14,9 @@ class ITZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a valid zip code.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ITZipCodeField, self).__init__(r'^\d{5}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class ITRegionSelect(Select): """ @@ -44,9 +44,9 @@ class ITSocialSecurityNumberField(RegexField): 'invalid': _(u'Enter a valid Social Security number.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): value = super(ITSocialSecurityNumberField, self).clean(value) diff --git a/django/contrib/localflavor/jp/forms.py b/django/contrib/localflavor/jp/forms.py index 1d765c8b17..248a93819e 100644 --- a/django/contrib/localflavor/jp/forms.py +++ b/django/contrib/localflavor/jp/forms.py @@ -16,9 +16,9 @@ class JPPostalCodeField(RegexField): 'invalid': _('Enter a postal code in the format XXXXXXX or XXX-XXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ diff --git a/django/contrib/localflavor/no/forms.py b/django/contrib/localflavor/no/forms.py index 61a269c0fe..abe3b80bec 100644 --- a/django/contrib/localflavor/no/forms.py +++ b/django/contrib/localflavor/no/forms.py @@ -13,9 +13,9 @@ class NOZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(NOZipCodeField, self).__init__(r'^\d{4}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class NOMunicipalitySelect(Select): """ diff --git a/django/contrib/localflavor/pe/forms.py b/django/contrib/localflavor/pe/forms.py index 7a4ac9e8d9..c1b41957fa 100644 --- a/django/contrib/localflavor/pe/forms.py +++ b/django/contrib/localflavor/pe/forms.py @@ -25,8 +25,8 @@ class PEDNIField(CharField): 'max_digits': _("This field requires 8 digits."), } - def __init__(self, *args, **kwargs): - super(PEDNIField, self).__init__(max_length=8, min_length=8, *args, + def __init__(self, max_length=8, min_length=8, *args, **kwargs): + super(PEDNIField, self).__init__(max_length, min_length, *args, **kwargs) def clean(self, value): @@ -53,8 +53,8 @@ class PERUCField(RegexField): 'max_digits': _("This field requires 11 digits."), } - def __init__(self, *args, **kwargs): - super(PERUCField, self).__init__(max_length=11, min_length=11, *args, + def __init__(self, max_length=11, min_length=11, *args, **kwargs): + super(PERUCField, self).__init__(max_length, min_length, *args, **kwargs) def clean(self, value): diff --git a/django/contrib/localflavor/pl/forms.py b/django/contrib/localflavor/pl/forms.py index ef4a38b7de..8b4d2f4aaa 100644 --- a/django/contrib/localflavor/pl/forms.py +++ b/django/contrib/localflavor/pl/forms.py @@ -40,9 +40,9 @@ class PLPESELField(RegexField): 'checksum': _(u'Wrong checksum for the National Identification Number.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PLPESELField, self).__init__(r'^\d{11}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): super(PLPESELField, self).clean(value) @@ -77,9 +77,9 @@ class PLNationalIDCardNumberField(RegexField): 'checksum': _(u'Wrong checksum for the National ID Card Number.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PLNationalIDCardNumberField, self).__init__(r'^[A-Za-z]{3}\d{6}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self,value): super(PLNationalIDCardNumberField, self).clean(value) @@ -129,9 +129,9 @@ class PLNIPField(RegexField): 'checksum': _(u'Wrong checksum for the Tax Number (NIP).'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self,value): super(PLNIPField, self).clean(value) @@ -169,9 +169,9 @@ class PLREGONField(RegexField): 'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PLREGONField, self).__init__(r'^\d{9,14}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self,value): super(PLREGONField, self).clean(value) @@ -209,7 +209,7 @@ class PLPostalCodeField(RegexField): 'invalid': _(u'Enter a postal code in the format XX-XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PLPostalCodeField, self).__init__(r'^\d{2}-\d{3}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) diff --git a/django/contrib/localflavor/pt/forms.py b/django/contrib/localflavor/pt/forms.py index 1f51679c4a..2a563cf99b 100644 --- a/django/contrib/localflavor/pt/forms.py +++ b/django/contrib/localflavor/pt/forms.py @@ -17,9 +17,9 @@ class PTZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXX-XXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(PTZipCodeField, self).__init__(r'^(\d{4}-\d{3}|\d{7})$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self,value): cleaned = super(PTZipCodeField, self).clean(value) diff --git a/django/contrib/localflavor/ro/forms.py b/django/contrib/localflavor/ro/forms.py index a218bfd167..3bfb0fab0d 100644 --- a/django/contrib/localflavor/ro/forms.py +++ b/django/contrib/localflavor/ro/forms.py @@ -19,9 +19,9 @@ class ROCIFField(RegexField): 'invalid': _("Enter a valid CIF."), } - def __init__(self, *args, **kwargs): - super(ROCIFField, self).__init__(r'^(RO)?[0-9]{2,10}', max_length=10, - min_length=2, *args, **kwargs) + def __init__(self, max_length=10, min_length=2, *args, **kwargs): + super(ROCIFField, self).__init__(r'^(RO)?[0-9]{2,10}', max_length, + min_length, *args, **kwargs) def clean(self, value): """ @@ -56,9 +56,9 @@ class ROCNPField(RegexField): 'invalid': _("Enter a valid CNP."), } - def __init__(self, *args, **kwargs): - super(ROCNPField, self).__init__(r'^[1-9][0-9]{12}', max_length=13, - min_length=13, *args, **kwargs) + def __init__(self, max_length=13, min_length=13, *args, **kwargs): + super(ROCNPField, self).__init__(r'^[1-9][0-9]{12}', max_length, + min_length, *args, **kwargs) def clean(self, value): """ @@ -143,9 +143,9 @@ class ROIBANField(RegexField): 'invalid': _('Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=40, min_length=24, *args, **kwargs): super(ROIBANField, self).__init__(r'^[0-9A-Za-z\-\s]{24,40}$', - max_length=40, min_length=24, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ @@ -175,9 +175,9 @@ class ROPhoneNumberField(RegexField): 'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=20, min_length=10, *args, **kwargs): super(ROPhoneNumberField, self).__init__(r'^[0-9\-\(\)\s]{10,20}$', - max_length=20, min_length=10, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ @@ -200,7 +200,7 @@ class ROPostalCodeField(RegexField): 'invalid': _('Enter a valid postal code in the format XXXXXX'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=6, min_length=6, *args, **kwargs): super(ROPostalCodeField, self).__init__(r'^[0-9][0-8][0-9]{4}$', - max_length=6, min_length=6, *args, **kwargs) + max_length, min_length, *args, **kwargs) diff --git a/django/contrib/localflavor/ru/forms.py b/django/contrib/localflavor/ru/forms.py index fa3c245c27..d091eabe4b 100644 --- a/django/contrib/localflavor/ru/forms.py +++ b/django/contrib/localflavor/ru/forms.py @@ -37,9 +37,9 @@ class RUPostalCodeField(RegexField): default_error_messages = { 'invalid': _(u'Enter a postal code in the format XXXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(RUPostalCodeField, self).__init__(r'^\d{6}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class RUPassportNumberField(RegexField): @@ -50,9 +50,9 @@ class RUPassportNumberField(RegexField): default_error_messages = { 'invalid': _(u'Enter a passport number in the format XXXX XXXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(RUPassportNumberField, self).__init__(r'^\d{4} \d{6}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class RUAlienPassportNumberField(RegexField): @@ -63,6 +63,6 @@ class RUAlienPassportNumberField(RegexField): default_error_messages = { 'invalid': _(u'Enter a passport number in the format XX XXXXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(RUAlienPassportNumberField, self).__init__(r'^\d{2} \d{7}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) diff --git a/django/contrib/localflavor/sk/forms.py b/django/contrib/localflavor/sk/forms.py index 863a61217a..389e7b7594 100644 --- a/django/contrib/localflavor/sk/forms.py +++ b/django/contrib/localflavor/sk/forms.py @@ -30,9 +30,9 @@ class SKPostalCodeField(RegexField): 'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): """ diff --git a/django/contrib/localflavor/tr/forms.py b/django/contrib/localflavor/tr/forms.py index 51e446078b..d2ae9bb804 100644 --- a/django/contrib/localflavor/tr/forms.py +++ b/django/contrib/localflavor/tr/forms.py @@ -16,9 +16,9 @@ class TRPostalCodeField(RegexField): 'invalid': _(u'Enter a postal code in the format XXXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=5, min_length=5, *args, **kwargs): super(TRPostalCodeField, self).__init__(r'^\d{5}$', - max_length=5, min_length=5, *args, **kwargs) + max_length, min_length, *args, **kwargs) def clean(self, value): value = super(TRPostalCodeField, self).clean(value) diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py index a41f7ab72f..36d7645027 100644 --- a/django/contrib/localflavor/us/forms.py +++ b/django/contrib/localflavor/us/forms.py @@ -17,9 +17,9 @@ class USZipCodeField(RegexField): 'invalid': _('Enter a zip code in the format XXXXX or XXXXX-XXXX.'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) class USPhoneNumberField(CharField): default_error_messages = { diff --git a/django/contrib/localflavor/za/forms.py b/django/contrib/localflavor/za/forms.py index 4fb4203e45..a9e2cd60c8 100644 --- a/django/contrib/localflavor/za/forms.py +++ b/django/contrib/localflavor/za/forms.py @@ -4,7 +4,7 @@ South Africa-specific Form helpers from django.core.validators import EMPTY_VALUES from django.forms import ValidationError -from django.forms.fields import Field, RegexField +from django.forms.fields import CharField, RegexField from django.utils.checksums import luhn from django.utils.translation import gettext as _ import re @@ -12,7 +12,7 @@ from datetime import date id_re = re.compile(r'^(?P\d\d)(?P\d\d)(?P
\d\d)(?P\d{4})(?P\d{3})') -class ZAIDField(Field): +class ZAIDField(CharField): """A form field for South African ID numbers -- the checksum is validated using the Luhn checksum, and uses a simlistic (read: not entirely accurate) check for the birthdate @@ -55,6 +55,6 @@ class ZAPostCodeField(RegexField): 'invalid': _(u'Enter a valid South African postal code'), } - def __init__(self, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(ZAPostCodeField, self).__init__(r'^\d{4}$', - max_length=None, min_length=None, *args, **kwargs) + max_length, min_length, *args, **kwargs) diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py index 482f7adeab..31d53dd255 100644 --- a/tests/regressiontests/forms/localflavor/utils.py +++ b/tests/regressiontests/forms/localflavor/utils.py @@ -1,5 +1,6 @@ from django.core.exceptions import ValidationError from django.core.validators import EMPTY_VALUES +from django.forms.fields import CharField from django.test.utils import get_warnings_state, restore_warnings_state from django.utils.unittest import TestCase @@ -13,8 +14,8 @@ class LocalFlavorTestCase(TestCase): def restore_warnings_state(self): restore_warnings_state(self._warnings_state) - def assertFieldOutput(self, fieldclass, valid, invalid, field_args=[], - field_kwargs={}, empty_value=u''): + def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None, + field_kwargs=None, empty_value=u''): """ Asserts that a field behaves correctly with various inputs. @@ -29,6 +30,10 @@ class LocalFlavorTestCase(TestCase): empty_value: the expected clean output for inputs in EMPTY_VALUES """ + if field_args is None: + field_args = [] + if field_kwargs is None: + field_kwargs = {} required = fieldclass(*field_args, **field_kwargs) optional = fieldclass(*field_args, **dict(field_kwargs, required=False)) # test valid inputs @@ -49,3 +54,7 @@ class LocalFlavorTestCase(TestCase): self.assertRaisesRegexp(ValidationError, error_required, required.clean, e) self.assertEqual(optional.clean(e), empty_value) + # test that max_length and min_length are always accepted + if issubclass(fieldclass, CharField): + field_kwargs.update({'min_length':2, 'max_length':20}) + self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), fieldclass))