Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10756 -- Error in the formats accepted by PLNIPField. Thanks r…

…emik for the report, michalm for the patch and claudep for the review.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17346 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c3697a091b7ff0d19f13821b18516ec8eaa1b8f8 1 parent 56b37bf
Aymeric Augustin authored January 07, 2012
6  django/contrib/localflavor/pl/forms.py
@@ -122,18 +122,18 @@ def has_valid_checksum(self, number):
122 122
 class PLNIPField(RegexField):
123 123
     """
124 124
     A form field that validates as Polish Tax Number (NIP).
125  
-    Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY.
  125
+    Valid forms are: XXX-YYY-YY-YY, XXX-YY-YY-YYY or XXXYYYYYYY.
126 126
 
127 127
     Checksum algorithm based on documentation at
128 128
     http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
129 129
     """
130 130
     default_error_messages = {
131  
-        'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),
  131
+        'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX.'),
132 132
         'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
133 133
     }
134 134
 
135 135
     def __init__(self, max_length=None, min_length=None, *args, **kwargs):
136  
-        super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
  136
+        super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{3}-\d{2}-\d{2}-\d{3}$|^\d{10}$',
137 137
             max_length, min_length, *args, **kwargs)
138 138
 
139 139
     def clean(self,value):
4  docs/ref/contrib/localflavor.txt
@@ -960,8 +960,8 @@ Poland (``pl``)
960 960
 
961 961
 .. class:: pl.forms.PLNIPField
962 962
 
963  
-    A form field that validates input as a Polish Tax Number (NIP). Valid
964  
-    formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used
  963
+    A form field that validates input as a Polish Tax Number (NIP). Valid formats
  964
+    are XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX. The checksum algorithm used
965 965
     for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
966 966
 
967 967
 .. class:: pl.forms.PLCountySelect
6  tests/regressiontests/localflavor/pl/tests.py
@@ -420,14 +420,16 @@ def test_PLPostalCodeField(self):
420 420
         self.assertFieldOutput(PLPostalCodeField, valid, invalid)
421 421
 
422 422
     def test_PLNIPField(self):
423  
-        error_format = [u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.']
  423
+        error_format = [u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX.']
424 424
         error_checksum = [u'Wrong checksum for the Tax Number (NIP).']
425 425
         valid = {
426  
-            '64-62-414-124': '6462414124',
427 426
             '646-241-41-24': '6462414124',
  427
+            '646-24-14-124': '6462414124',
  428
+            '6462414124': '6462414124',
428 429
         }
429 430
         invalid = {
430 431
             '43-343-234-323': error_format,
  432
+	    '64-62-414-124': error_format,
431 433
             '646-241-41-23': error_checksum,
432 434
         }
433 435
         self.assertFieldOutput(PLNIPField, valid, invalid)

0 notes on commit c3697a0

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