Fixed #10756 -- Error in the formats accepted by PLNIPField. Thanks remik 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
This commit is contained in:
parent
56b37bf1cf
commit
c3697a091b
|
@ -122,18 +122,18 @@ class PLNationalIDCardNumberField(RegexField):
|
||||||
class PLNIPField(RegexField):
|
class PLNIPField(RegexField):
|
||||||
"""
|
"""
|
||||||
A form field that validates as Polish Tax Number (NIP).
|
A form field that validates as Polish Tax Number (NIP).
|
||||||
Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY.
|
Valid forms are: XXX-YYY-YY-YY, XXX-YY-YY-YYY or XXXYYYYYYY.
|
||||||
|
|
||||||
Checksum algorithm based on documentation at
|
Checksum algorithm based on documentation at
|
||||||
http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
|
http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
|
||||||
"""
|
"""
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),
|
'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX.'),
|
||||||
'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
|
'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
||||||
super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
|
super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{3}-\d{2}-\d{2}-\d{3}$|^\d{10}$',
|
||||||
max_length, min_length, *args, **kwargs)
|
max_length, min_length, *args, **kwargs)
|
||||||
|
|
||||||
def clean(self,value):
|
def clean(self,value):
|
||||||
|
|
|
@ -960,8 +960,8 @@ Poland (``pl``)
|
||||||
|
|
||||||
.. class:: pl.forms.PLNIPField
|
.. class:: pl.forms.PLNIPField
|
||||||
|
|
||||||
A form field that validates input as a Polish Tax Number (NIP). Valid
|
A form field that validates input as a Polish Tax Number (NIP). Valid formats
|
||||||
formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used
|
are XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX. The checksum algorithm used
|
||||||
for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
|
for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
|
||||||
|
|
||||||
.. class:: pl.forms.PLCountySelect
|
.. class:: pl.forms.PLCountySelect
|
||||||
|
|
|
@ -420,14 +420,16 @@ class PLLocalFlavorTests(SimpleTestCase):
|
||||||
self.assertFieldOutput(PLPostalCodeField, valid, invalid)
|
self.assertFieldOutput(PLPostalCodeField, valid, invalid)
|
||||||
|
|
||||||
def test_PLNIPField(self):
|
def test_PLNIPField(self):
|
||||||
error_format = [u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.']
|
error_format = [u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX.']
|
||||||
error_checksum = [u'Wrong checksum for the Tax Number (NIP).']
|
error_checksum = [u'Wrong checksum for the Tax Number (NIP).']
|
||||||
valid = {
|
valid = {
|
||||||
'64-62-414-124': '6462414124',
|
|
||||||
'646-241-41-24': '6462414124',
|
'646-241-41-24': '6462414124',
|
||||||
|
'646-24-14-124': '6462414124',
|
||||||
|
'6462414124': '6462414124',
|
||||||
}
|
}
|
||||||
invalid = {
|
invalid = {
|
||||||
'43-343-234-323': error_format,
|
'43-343-234-323': error_format,
|
||||||
|
'64-62-414-124': error_format,
|
||||||
'646-241-41-23': error_checksum,
|
'646-241-41-23': error_checksum,
|
||||||
}
|
}
|
||||||
self.assertFieldOutput(PLNIPField, valid, invalid)
|
self.assertFieldOutput(PLNIPField, valid, invalid)
|
||||||
|
|
Loading…
Reference in New Issue