Ticket #10756: ticket10756.diff

File ticket10756.diff, 3.1 KB (added by Michał Modzelewski, 13 years ago)

patch that changes the accepted formats, details in the comments

  • django/contrib/localflavor/pl/forms.py

    diff --git a/django/contrib/localflavor/pl/forms.py b/django/contrib/localflavor/pl/forms.py
    index 8b4d2f4..35d7e87 100644
    a b class PLNationalIDCardNumberField(RegexField):  
    119119class PLNIPField(RegexField):
    120120    """
    121121    A form field that validates as Polish Tax Number (NIP).
    122     Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY.
     122    Valid forms are: XXX-YYY-YY-YY, XXX-YY-YY-YYY or XXXYYYYYYY.
    123123
    124124    Checksum algorithm based on documentation at
    125125    http://wipos.p.lodz.pl/zylla/ut/nip-rego.html
    126126    """
    127127    default_error_messages = {
    128         'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX or XX-XX-XXX-XXX.'),
     128        'invalid': _(u'Enter a tax number field (NIP) in the format XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX.'),
    129129        'checksum': _(u'Wrong checksum for the Tax Number (NIP).'),
    130130    }
    131131
    132132    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
    133         super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$',
     133        super(PLNIPField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{3}-\d{2}-\d{2}-\d{3}$|^\d{10}$',
    134134            max_length, min_length, *args, **kwargs)
    135135
    136136    def clean(self,value):
  • docs/ref/contrib/localflavor.txt

    diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt
    index f6dab64..0a97615 100644
    a b Poland (``pl``)  
    786786
    787787.. class:: pl.forms.PLNIPField
    788788
    789     A form field that validates input as a Polish Tax Number (NIP). Valid
    790     formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used
     789    A form field that validates input as a Polish Tax Number (NIP). Valid formats
     790    are XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX. The checksum algorithm used
    791791    for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
    792792
    793793.. class:: pl.forms.PLCountySelect
  • tests/regressiontests/forms/localflavor/pl.py

    diff --git a/tests/regressiontests/forms/localflavor/pl.py b/tests/regressiontests/forms/localflavor/pl.py
    index 7225abe..7f4069c 100644
    a b class PLLocalFlavorTests(LocalFlavorTestCase):  
    420420        self.assertFieldOutput(PLPostalCodeField, valid, invalid)
    421421
    422422    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.']
    424424        error_checksum = [u'Wrong checksum for the Tax Number (NIP).']
    425425        valid = {
    426             '64-62-414-124': '6462414124',
    427426            '646-241-41-24': '6462414124',
     427            '646-24-14-124': '6462414124',
     428            '6462414124': '6462414124',
    428429        }
    429430        invalid = {
    430431            '43-343-234-323': error_format,
     432            '64-62-414-124': error_format,
    431433            '646-241-41-23': error_checksum,
    432434        }
    433435        self.assertFieldOutput(PLNIPField, valid, invalid)
Back to Top