Fixed #18102 -- Defined min/max_length on French localflavor form fields
Thanks mothsART for the report and the initial patch.
This commit is contained in:
parent
b9ecbedb31
commit
47da7b7a9a
|
@ -8,7 +8,7 @@ import re
|
|||
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)
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class FRLocalFlavorTests(SimpleTestCase):
|
|||
}
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue