Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored June 30, 2012
11  django/contrib/localflavor/fr/forms.py
@@ -8,7 +8,7 @@
8 8
 from django.contrib.localflavor.fr.fr_department import DEPARTMENT_CHOICES
9 9
 from django.core.validators import EMPTY_VALUES
10 10
 from django.forms import ValidationError
11  
-from django.forms.fields import Field, RegexField, Select
  11
+from django.forms.fields import CharField, RegexField, Select
12 12
 from django.utils.encoding import smart_unicode
13 13
 from django.utils.translation import ugettext_lazy as _
14 14
 
@@ -20,11 +20,11 @@ class FRZipCodeField(RegexField):
20 20
         'invalid': _('Enter a zip code in the format XXXXX.'),
21 21
     }
22 22
 
23  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
  23
+    def __init__(self, max_length=5, min_length=5, *args, **kwargs):
24 24
         super(FRZipCodeField, self).__init__(r'^\d{5}$',
25 25
             max_length, min_length, *args, **kwargs)
26 26
 
27  
-class FRPhoneNumberField(Field):
  27
+class FRPhoneNumberField(CharField):
28 28
     """
29 29
     Validate local French phone number (not international ones)
30 30
     The correct format is '0X XX XX XX XX'.
@@ -35,6 +35,10 @@ class FRPhoneNumberField(Field):
35 35
         'invalid': _('Phone numbers must be in 0X XX XX XX XX format.'),
36 36
     }
37 37
 
  38
+    def __init__(self, max_length=14, min_length=10, *args, **kwargs):
  39
+        super(FRPhoneNumberField, self).__init__(
  40
+            max_length, min_length, *args, **kwargs)
  41
+
38 42
     def clean(self, value):
39 43
         super(FRPhoneNumberField, self).clean(value)
40 44
         if value in EMPTY_VALUES:
@@ -51,4 +55,3 @@ class FRDepartmentSelect(Select):
51 55
     """
52 56
     def __init__(self, attrs=None):
53 57
         super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES)
54  
-
3  tests/regressiontests/localflavor/fr/tests.py
@@ -16,7 +16,8 @@ def test_FRZipCodeField(self):
16 16
         }
17 17
         invalid = {
18 18
             '2A200': error_format,
19  
-            '980001': error_format,
  19
+            '980001': ['Ensure this value has at most 5 characters (it has 6).'
  20
+                      ] + error_format,
20 21
         }
21 22
         self.assertFieldOutput(FRZipCodeField, valid, invalid)
22 23
 

0 notes on commit 47da7b7

Please sign in to comment.
Something went wrong with that request. Please try again.