-
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):
|
28 | 28 | 'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."), |
29 | 29 | } |
30 | 30 | |
31 | | def __init__(self, *args, **kwargs): |
| 31 | def __init__(self, max_length=8, min_length=4, *args, **kwargs): |
32 | 32 | 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) |
34 | 34 | |
35 | 35 | def clean(self, value): |
36 | 36 | value = super(ARPostalCodeField, self).clean(value) |
… |
… |
class ARDNIField(CharField):
|
51 | 51 | 'max_digits': _("This field requires 7 or 8 digits."), |
52 | 52 | } |
53 | 53 | |
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, |
56 | 56 | **kwargs) |
57 | 57 | |
58 | 58 | def clean(self, value): |
… |
… |
class ARCUITField(RegexField):
|
81 | 81 | 'checksum': _("Invalid CUIT."), |
82 | 82 | } |
83 | 83 | |
84 | | def __init__(self, *args, **kwargs): |
| 84 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
85 | 85 | super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$', |
86 | | *args, **kwargs) |
| 86 | max_length, min_length, *args, **kwargs) |
87 | 87 | |
88 | 88 | def clean(self, value): |
89 | 89 | """ |
-
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):
|
21 | 21 | default_error_messages = { |
22 | 22 | 'invalid': _('Enter a zip code in the format XXXX.'), |
23 | 23 | } |
24 | | def __init__(self, *args, **kwargs): |
| 24 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
25 | 25 | super(ATZipCodeField, self).__init__(r'^\d{4}$', |
26 | | max_length=None, min_length=None, *args, **kwargs) |
| 26 | max_length, min_length, *args, **kwargs) |
27 | 27 | |
28 | 28 | class ATStateSelect(Select): |
29 | 29 | """ |
-
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):
|
21 | 21 | 'invalid': _('Enter a 4 digit postcode.'), |
22 | 22 | } |
23 | 23 | |
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): |
27 | 25 | super(AUPostCodeField, self).__init__(r'^\d{4}$', |
28 | | max_length=4, min_length=None, *args, **kwargs) |
| 26 | max_length, min_length, *args, **kwargs) |
29 | 27 | |
30 | 28 | |
31 | 29 | class AUPhoneNumberField(Field): |
-
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):
|
23 | 23 | 'Enter a valid postal code in the range and format 1XXX - 9XXX.'), |
24 | 24 | } |
25 | 25 | |
26 | | def __init__(self, *args, **kwargs): |
| 26 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
27 | 27 | 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) |
29 | 29 | |
30 | 30 | class BEPhoneNumberField(RegexField): |
31 | 31 | """ |
… |
… |
class BEPhoneNumberField(RegexField):
|
50 | 50 | '0xxxxxxxx or 04xxxxxxxx.'), |
51 | 51 | } |
52 | 52 | |
53 | | def __init__(self, *args, **kwargs): |
| 53 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
54 | 54 | 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) |
56 | 56 | |
57 | 57 | class BERegionSelect(Select): |
58 | 58 | """ |
-
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):
|
17 | 17 | 'invalid': _('Enter a zip code in the format XXXXX-XXX.'), |
18 | 18 | } |
19 | 19 | |
20 | | def __init__(self, *args, **kwargs): |
| 20 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
21 | 21 | 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) |
23 | 23 | |
24 | 24 | class BRPhoneNumberField(Field): |
25 | 25 | default_error_messages = { |
… |
… |
class BRCPFField(CharField):
|
92 | 92 | 'digits_only': _("This field requires only numbers."), |
93 | 93 | } |
94 | 94 | |
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) |
97 | 97 | |
98 | 98 | def clean(self, value): |
99 | 99 | """ |
-
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):
|
25 | 25 | 'invalid': _(u'Enter a postal code in the format XXX XXX.'), |
26 | 26 | } |
27 | 27 | |
28 | | def __init__(self, *args, **kwargs): |
| 28 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
29 | 29 | 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) |
31 | 31 | |
32 | 32 | class CAPhoneNumberField(Field): |
33 | 33 | """Canadian phone number field.""" |
-
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):
|
17 | 17 | 'invalid': _('Enter a zip code in the format XXXX.'), |
18 | 18 | } |
19 | 19 | |
20 | | def __init__(self, *args, **kwargs): |
| 20 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
21 | 21 | super(CHZipCodeField, self).__init__(r'^\d{4}$', |
22 | | max_length=None, min_length=None, *args, **kwargs) |
| 22 | max_length, min_length, *args, **kwargs) |
23 | 23 | |
24 | 24 | class CHPhoneNumberField(Field): |
25 | 25 | """ |
-
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):
|
28 | 28 | 'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'), |
29 | 29 | } |
30 | 30 | |
31 | | def __init__(self, *args, **kwargs): |
| 31 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
32 | 32 | 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) |
34 | 34 | |
35 | 35 | def clean(self, value): |
36 | 36 | """ |
-
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):
|
14 | 14 | default_error_messages = { |
15 | 15 | 'invalid': _('Enter a zip code in the format XXXXX.'), |
16 | 16 | } |
17 | | def __init__(self, *args, **kwargs): |
| 17 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
18 | 18 | super(DEZipCodeField, self).__init__(r'^\d{5}$', |
19 | | max_length=None, min_length=None, *args, **kwargs) |
| 19 | max_length, min_length, *args, **kwargs) |
20 | 20 | |
21 | 21 | class DEStateSelect(Select): |
22 | 22 | """ |
-
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):
|
20 | 20 | 'invalid': _('Enter a valid postal code in the range and format 01XXX - 52XXX.'), |
21 | 21 | } |
22 | 22 | |
23 | | def __init__(self, *args, **kwargs): |
| 23 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
24 | 24 | super(ESPostalCodeField, self).__init__( |
25 | 25 | 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) |
27 | 27 | |
28 | 28 | class ESPhoneNumberField(RegexField): |
29 | 29 | """ |
… |
… |
class ESPhoneNumberField(RegexField):
|
40 | 40 | 'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'), |
41 | 41 | } |
42 | 42 | |
43 | | def __init__(self, *args, **kwargs): |
| 43 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
44 | 44 | 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) |
46 | 46 | |
47 | 47 | class ESIdentityCardNumberField(RegexField): |
48 | 48 | """ |
… |
… |
class ESIdentityCardNumberField(RegexField):
|
71 | 71 | 'invalid_cif': _('Invalid checksum for CIF.'), |
72 | 72 | } |
73 | 73 | |
74 | | def __init__(self, only_nif=False, *args, **kwargs): |
| 74 | def __init__(self, only_nif=False, max_length=None, min_length=None, *args, **kwargs): |
75 | 75 | self.only_nif = only_nif |
76 | 76 | self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE' |
77 | 77 | self.cif_control = 'JABCDEFGHI' |
78 | 78 | self.cif_types = 'ABCDEFGHKLMNPQS' |
79 | 79 | self.nie_types = 'XT' |
80 | 80 | 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, |
82 | 82 | error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')], |
83 | 83 | *args, **kwargs) |
84 | 84 | |
… |
… |
class ESCCCField(RegexField):
|
144 | 144 | 'checksum': _('Invalid checksum for bank account number.'), |
145 | 145 | } |
146 | 146 | |
147 | | def __init__(self, *args, **kwargs): |
| 147 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
148 | 148 | 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) |
150 | 150 | |
151 | 151 | def clean(self, value): |
152 | 152 | super(ESCCCField, self).clean(value) |
-
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):
|
12 | 12 | default_error_messages = { |
13 | 13 | 'invalid': _('Enter a zip code in the format XXXXX.'), |
14 | 14 | } |
15 | | def __init__(self, *args, **kwargs): |
| 15 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
16 | 16 | super(FIZipCodeField, self).__init__(r'^\d{5}$', |
17 | | max_length=None, min_length=None, *args, **kwargs) |
| 17 | max_length, min_length, *args, **kwargs) |
18 | 18 | |
19 | 19 | class FIMunicipalitySelect(Select): |
20 | 20 | """ |
-
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):
|
16 | 16 | 'invalid': _('Enter a zip code in the format XXXXX.'), |
17 | 17 | } |
18 | 18 | |
19 | | def __init__(self, *args, **kwargs): |
| 19 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
20 | 20 | super(FRZipCodeField, self).__init__(r'^\d{5}$', |
21 | | max_length=None, min_length=None, *args, **kwargs) |
| 21 | max_length, min_length, *args, **kwargs) |
22 | 22 | |
23 | 23 | class FRPhoneNumberField(Field): |
24 | 24 | """ |
-
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):
|
120 | 120 | 'invalid': _('Enter a valid 11 digit OIB'), |
121 | 121 | } |
122 | 122 | |
123 | | def __init__(self, *args, **kwargs): |
| 123 | def __init__(self, min_length=11, max_length=11, *args, **kwargs): |
124 | 124 | super(HROIBField, self).__init__(r'^\d{11}$', |
125 | | min_length=11, max_length=11, *args, **kwargs) |
| 125 | min_length, max_length, *args, **kwargs) |
126 | 126 | |
127 | 127 | def clean(self, value): |
128 | 128 | super(HROIBField, self).clean(value) |
-
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):
|
15 | 15 | 'invalid': gettext(u'Enter a zip code in the format XXXXXXX.'), |
16 | 16 | } |
17 | 17 | |
18 | | def __init__(self, *args, **kwargs): |
| 18 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
19 | 19 | super(INZipCodeField, self).__init__(r'^\d{6}$', |
20 | | max_length=None, min_length=None, *args, **kwargs) |
| 20 | max_length, min_length, *args, **kwargs) |
21 | 21 | |
22 | 22 | class INStateField(Field): |
23 | 23 | """ |
-
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):
|
19 | 19 | 'checksum': _(u'The Icelandic identification number is not valid.'), |
20 | 20 | } |
21 | 21 | |
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) |
25 | 25 | |
26 | 26 | def clean(self, value): |
27 | 27 | value = super(ISIdNumberField, self).clean(value) |
… |
… |
class ISPhoneNumberField(RegexField):
|
61 | 61 | Icelandic phone number. Seven digits with an optional hyphen or space after |
62 | 62 | the first three digits. |
63 | 63 | """ |
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) |
67 | 67 | |
68 | 68 | def clean(self, value): |
69 | 69 | value = super(ISPhoneNumberField, self).clean(value) |
-
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):
|
14 | 14 | default_error_messages = { |
15 | 15 | 'invalid': _('Enter a valid zip code.'), |
16 | 16 | } |
17 | | def __init__(self, *args, **kwargs): |
| 17 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
18 | 18 | super(ITZipCodeField, self).__init__(r'^\d{5}$', |
19 | | max_length=None, min_length=None, *args, **kwargs) |
| 19 | max_length, min_length, *args, **kwargs) |
20 | 20 | |
21 | 21 | class ITRegionSelect(Select): |
22 | 22 | """ |
… |
… |
class ITSocialSecurityNumberField(RegexField):
|
44 | 44 | 'invalid': _(u'Enter a valid Social Security number.'), |
45 | 45 | } |
46 | 46 | |
47 | | def __init__(self, *args, **kwargs): |
| 47 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
48 | 48 | 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) |
50 | 50 | |
51 | 51 | def clean(self, value): |
52 | 52 | value = super(ITSocialSecurityNumberField, self).clean(value) |
-
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):
|
16 | 16 | 'invalid': _('Enter a postal code in the format XXXXXXX or XXX-XXXX.'), |
17 | 17 | } |
18 | 18 | |
19 | | def __init__(self, *args, **kwargs): |
| 19 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
20 | 20 | 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) |
22 | 22 | |
23 | 23 | def clean(self, value): |
24 | 24 | """ |
-
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):
|
13 | 13 | 'invalid': _('Enter a zip code in the format XXXX.'), |
14 | 14 | } |
15 | 15 | |
16 | | def __init__(self, *args, **kwargs): |
| 16 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
17 | 17 | super(NOZipCodeField, self).__init__(r'^\d{4}$', |
18 | | max_length=None, min_length=None, *args, **kwargs) |
| 18 | max_length, min_length, *args, **kwargs) |
19 | 19 | |
20 | 20 | class NOMunicipalitySelect(Select): |
21 | 21 | """ |
-
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):
|
25 | 25 | 'max_digits': _("This field requires 8 digits."), |
26 | 26 | } |
27 | 27 | |
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, |
30 | 30 | **kwargs) |
31 | 31 | |
32 | 32 | def clean(self, value): |
… |
… |
class PERUCField(RegexField):
|
53 | 53 | 'max_digits': _("This field requires 11 digits."), |
54 | 54 | } |
55 | 55 | |
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, |
58 | 58 | **kwargs) |
59 | 59 | |
60 | 60 | def clean(self, value): |
-
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):
|
40 | 40 | 'checksum': _(u'Wrong checksum for the National Identification Number.'), |
41 | 41 | } |
42 | 42 | |
43 | | def __init__(self, *args, **kwargs): |
| 43 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
44 | 44 | super(PLPESELField, self).__init__(r'^\d{11}$', |
45 | | max_length=None, min_length=None, *args, **kwargs) |
| 45 | max_length, min_length, *args, **kwargs) |
46 | 46 | |
47 | 47 | def clean(self, value): |
48 | 48 | super(PLPESELField, self).clean(value) |
… |
… |
class PLNationalIDCardNumberField(RegexField):
|
77 | 77 | 'checksum': _(u'Wrong checksum for the National ID Card Number.'), |
78 | 78 | } |
79 | 79 | |
80 | | def __init__(self, *args, **kwargs): |
| 80 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
81 | 81 | 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) |
83 | 83 | |
84 | 84 | def clean(self,value): |
85 | 85 | super(PLNationalIDCardNumberField, self).clean(value) |
… |
… |
class PLNIPField(RegexField):
|
129 | 129 | 'checksum': _(u'Wrong checksum for the Tax Number (NIP).'), |
130 | 130 | } |
131 | 131 | |
132 | | def __init__(self, *args, **kwargs): |
| 132 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
133 | 133 | 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) |
135 | 135 | |
136 | 136 | def clean(self,value): |
137 | 137 | super(PLNIPField, self).clean(value) |
… |
… |
class PLREGONField(RegexField):
|
169 | 169 | 'checksum': _(u'Wrong checksum for the National Business Register Number (REGON).'), |
170 | 170 | } |
171 | 171 | |
172 | | def __init__(self, *args, **kwargs): |
| 172 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
173 | 173 | super(PLREGONField, self).__init__(r'^\d{9,14}$', |
174 | | max_length=None, min_length=None, *args, **kwargs) |
| 174 | max_length, min_length, *args, **kwargs) |
175 | 175 | |
176 | 176 | def clean(self,value): |
177 | 177 | super(PLREGONField, self).clean(value) |
… |
… |
class PLPostalCodeField(RegexField):
|
209 | 209 | 'invalid': _(u'Enter a postal code in the format XX-XXX.'), |
210 | 210 | } |
211 | 211 | |
212 | | def __init__(self, *args, **kwargs): |
| 212 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
213 | 213 | 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) |
215 | 215 | |
-
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):
|
17 | 17 | 'invalid': _('Enter a zip code in the format XXXX-XXX.'), |
18 | 18 | } |
19 | 19 | |
20 | | def __init__(self, *args, **kwargs): |
| 20 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
21 | 21 | 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) |
23 | 23 | |
24 | 24 | def clean(self,value): |
25 | 25 | cleaned = super(PTZipCodeField, self).clean(value) |
-
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):
|
19 | 19 | 'invalid': _("Enter a valid CIF."), |
20 | 20 | } |
21 | 21 | |
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) |
25 | 25 | |
26 | 26 | def clean(self, value): |
27 | 27 | """ |
… |
… |
class ROCNPField(RegexField):
|
56 | 56 | 'invalid': _("Enter a valid CNP."), |
57 | 57 | } |
58 | 58 | |
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) |
62 | 62 | |
63 | 63 | def clean(self, value): |
64 | 64 | """ |
… |
… |
class ROIBANField(RegexField):
|
143 | 143 | 'invalid': _('Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'), |
144 | 144 | } |
145 | 145 | |
146 | | def __init__(self, *args, **kwargs): |
| 146 | def __init__(self, max_length=40, min_length=24, *args, **kwargs): |
147 | 147 | 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) |
149 | 149 | |
150 | 150 | def clean(self, value): |
151 | 151 | """ |
… |
… |
class ROPhoneNumberField(RegexField):
|
175 | 175 | 'invalid': _('Phone numbers must be in XXXX-XXXXXX format.'), |
176 | 176 | } |
177 | 177 | |
178 | | def __init__(self, *args, **kwargs): |
| 178 | def __init__(self, max_length=20, min_length=10, *args, **kwargs): |
179 | 179 | 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) |
181 | 181 | |
182 | 182 | def clean(self, value): |
183 | 183 | """ |
… |
… |
class ROPostalCodeField(RegexField):
|
200 | 200 | 'invalid': _('Enter a valid postal code in the format XXXXXX'), |
201 | 201 | } |
202 | 202 | |
203 | | def __init__(self, *args, **kwargs): |
| 203 | def __init__(self, max_length=6, min_length=6, *args, **kwargs): |
204 | 204 | 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) |
206 | 206 | |
-
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):
|
37 | 37 | default_error_messages = { |
38 | 38 | 'invalid': _(u'Enter a postal code in the format XXXXXX.'), |
39 | 39 | } |
40 | | def __init__(self, *args, **kwargs): |
| 40 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
41 | 41 | super(RUPostalCodeField, self).__init__(r'^\d{6}$', |
42 | | max_length=None, min_length=None, *args, **kwargs) |
| 42 | max_length, min_length, *args, **kwargs) |
43 | 43 | |
44 | 44 | |
45 | 45 | class RUPassportNumberField(RegexField): |
… |
… |
class RUPassportNumberField(RegexField):
|
50 | 50 | default_error_messages = { |
51 | 51 | 'invalid': _(u'Enter a passport number in the format XXXX XXXXXX.'), |
52 | 52 | } |
53 | | def __init__(self, *args, **kwargs): |
| 53 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
54 | 54 | 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) |
56 | 56 | |
57 | 57 | |
58 | 58 | class RUAlienPassportNumberField(RegexField): |
… |
… |
class RUAlienPassportNumberField(RegexField):
|
63 | 63 | default_error_messages = { |
64 | 64 | 'invalid': _(u'Enter a passport number in the format XX XXXXXXX.'), |
65 | 65 | } |
66 | | def __init__(self, *args, **kwargs): |
| 66 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
67 | 67 | 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) |
-
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):
|
30 | 30 | 'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'), |
31 | 31 | } |
32 | 32 | |
33 | | def __init__(self, *args, **kwargs): |
| 33 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
34 | 34 | 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) |
36 | 36 | |
37 | 37 | def clean(self, value): |
38 | 38 | """ |
-
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):
|
16 | 16 | 'invalid': _(u'Enter a postal code in the format XXXXX.'), |
17 | 17 | } |
18 | 18 | |
19 | | def __init__(self, *args, **kwargs): |
| 19 | def __init__(self, max_length=5, min_length=5, *args, **kwargs): |
20 | 20 | super(TRPostalCodeField, self).__init__(r'^\d{5}$', |
21 | | max_length=5, min_length=5, *args, **kwargs) |
| 21 | max_length, min_length, *args, **kwargs) |
22 | 22 | |
23 | 23 | def clean(self, value): |
24 | 24 | value = super(TRPostalCodeField, self).clean(value) |
-
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):
|
17 | 17 | 'invalid': _('Enter a zip code in the format XXXXX or XXXXX-XXXX.'), |
18 | 18 | } |
19 | 19 | |
20 | | def __init__(self, *args, **kwargs): |
| 20 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
21 | 21 | 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) |
23 | 23 | |
24 | 24 | class USPhoneNumberField(CharField): |
25 | 25 | default_error_messages = { |
-
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
|
4 | 4 | |
5 | 5 | from django.core.validators import EMPTY_VALUES |
6 | 6 | from django.forms import ValidationError |
7 | | from django.forms.fields import Field, RegexField |
| 7 | from django.forms.fields import CharField, RegexField |
8 | 8 | from django.utils.checksums import luhn |
9 | 9 | from django.utils.translation import gettext as _ |
10 | 10 | import re |
… |
… |
from datetime import date
|
12 | 12 | |
13 | 13 | id_re = re.compile(r'^(?P<yy>\d\d)(?P<mm>\d\d)(?P<dd>\d\d)(?P<mid>\d{4})(?P<end>\d{3})') |
14 | 14 | |
15 | | class ZAIDField(Field): |
| 15 | class ZAIDField(CharField): |
16 | 16 | """A form field for South African ID numbers -- the checksum is validated |
17 | 17 | using the Luhn checksum, and uses a simlistic (read: not entirely accurate) |
18 | 18 | check for the birthdate |
… |
… |
class ZAPostCodeField(RegexField):
|
55 | 55 | 'invalid': _(u'Enter a valid South African postal code'), |
56 | 56 | } |
57 | 57 | |
58 | | def __init__(self, *args, **kwargs): |
| 58 | def __init__(self, max_length=None, min_length=None, *args, **kwargs): |
59 | 59 | super(ZAPostCodeField, self).__init__(r'^\d{4}$', |
60 | | max_length=None, min_length=None, *args, **kwargs) |
| 60 | max_length, min_length, *args, **kwargs) |
-
diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py
index 482f7ad..31d53dd 100644
a
|
b
|
|
1 | 1 | from django.core.exceptions import ValidationError |
2 | 2 | from django.core.validators import EMPTY_VALUES |
| 3 | from django.forms.fields import CharField |
3 | 4 | from django.test.utils import get_warnings_state, restore_warnings_state |
4 | 5 | from django.utils.unittest import TestCase |
5 | 6 | |
… |
… |
class LocalFlavorTestCase(TestCase):
|
13 | 14 | def restore_warnings_state(self): |
14 | 15 | restore_warnings_state(self._warnings_state) |
15 | 16 | |
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''): |
18 | 19 | """ |
19 | 20 | Asserts that a field behaves correctly with various inputs. |
20 | 21 | |
… |
… |
class LocalFlavorTestCase(TestCase):
|
29 | 30 | empty_value: the expected clean output for inputs in EMPTY_VALUES |
30 | 31 | |
31 | 32 | """ |
| 33 | if field_args is None: |
| 34 | field_args = [] |
| 35 | if field_kwargs is None: |
| 36 | field_kwargs = {} |
32 | 37 | required = fieldclass(*field_args, **field_kwargs) |
33 | 38 | optional = fieldclass(*field_args, **dict(field_kwargs, required=False)) |
34 | 39 | # test valid inputs |
… |
… |
class LocalFlavorTestCase(TestCase):
|
49 | 54 | self.assertRaisesRegexp(ValidationError, error_required, |
50 | 55 | required.clean, e) |
51 | 56 | 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)) |