Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18102 -- Defined min/max_length on French localflavor form fields

Thanks mothsART for the report and the initial patch.
  • Loading branch information...
commit 47da7b7a9aefce66fa2c54833b5ba308781fc95e 1 parent b9ecbed
Claude Paroz claudep authored
11 django/contrib/localflavor/fr/forms.py
View
@@ -8,7 +8,7 @@
from django.contrib.localflavor.fr.fr_department import DEPARTMENT_CHOICES
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select
+from django.forms.fields import CharField, RegexField, Select
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
@@ -20,11 +20,11 @@ class FRZipCodeField(RegexField):
'invalid': _('Enter a zip code in the format XXXXX.'),
}
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
+ def __init__(self, max_length=5, min_length=5, *args, **kwargs):
super(FRZipCodeField, self).__init__(r'^\d{5}$',
max_length, min_length, *args, **kwargs)
-class FRPhoneNumberField(Field):
+class FRPhoneNumberField(CharField):
"""
Validate local French phone number (not international ones)
The correct format is '0X XX XX XX XX'.
@@ -35,6 +35,10 @@ class FRPhoneNumberField(Field):
'invalid': _('Phone numbers must be in 0X XX XX XX XX format.'),
}
+ def __init__(self, max_length=14, min_length=10, *args, **kwargs):
+ super(FRPhoneNumberField, self).__init__(
+ max_length, min_length, *args, **kwargs)
+
def clean(self, value):
super(FRPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
@@ -51,4 +55,3 @@ class FRDepartmentSelect(Select):
"""
def __init__(self, attrs=None):
super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES)
-
3  tests/regressiontests/localflavor/fr/tests.py
View
@@ -16,7 +16,8 @@ def test_FRZipCodeField(self):
}
invalid = {
'2A200': error_format,
- '980001': error_format,
+ '980001': ['Ensure this value has at most 5 characters (it has 6).'
+ ] + error_format,
}
self.assertFieldOutput(FRZipCodeField, valid, invalid)
Please sign in to comment.
Something went wrong with that request. Please try again.