Navigation Menu

Skip to content

Commit

Permalink
Fixed #8276 -- Changed the names of a few Polish localflavor classes …
Browse files Browse the repository at this point in the history
…to match

their common names/acronyms, similar to other localflavors.

Backwards incompatible if you're using these classes.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8345 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Aug 14, 2008
1 parent 9d83444 commit 4adf048
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
33 changes: 16 additions & 17 deletions django/contrib/localflavor/pl/forms.py
Expand Up @@ -8,24 +8,23 @@
from django.forms.fields import Select, RegexField
from django.utils.translation import ugettext_lazy as _

class PLVoivodeshipSelect(Select):
class PLProvinceSelect(Select):
"""
A select widget with list of Polish voivodeships (administrative provinces)
as choices.
A select widget with list of Polish administrative provinces as choices.
"""
def __init__(self, attrs=None):
from pl_voivodeships import VOIVODESHIP_CHOICES
super(PLVoivodeshipSelect, self).__init__(attrs, choices=VOIVODESHIP_CHOICES)
super(PLProvinceSelect, self).__init__(attrs, choices=VOIVODESHIP_CHOICES)

class PLAdministrativeUnitSelect(Select):
class PLCountiesSelect(Select):
"""
A select widget with list of Polish administrative units as choices.
"""
def __init__(self, attrs=None):
from pl_administrativeunits import ADMINISTRATIVE_UNIT_CHOICES
super(PLAdministrativeUnitSelect, self).__init__(attrs, choices=ADMINISTRATIVE_UNIT_CHOICES)
super(PLCountiesSelect, self).__init__(attrs, choices=ADMINISTRATIVE_UNIT_CHOICES)

class PLNationalIdentificationNumberField(RegexField):
class PLPESELField(RegexField):
"""
A form field that validates as Polish Identification Number (PESEL).
Expand All @@ -41,11 +40,11 @@ class PLNationalIdentificationNumberField(RegexField):
}

def __init__(self, *args, **kwargs):
super(PLNationalIdentificationNumberField, self).__init__(r'^\d{11}$',
super(PLPESELField, self).__init__(r'^\d{11}$',
max_length=None, min_length=None, *args, **kwargs)

def clean(self,value):
super(PLNationalIdentificationNumberField, self).clean(value)
super(PLPESELField, self).clean(value)
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
return u'%s' % value
Expand All @@ -60,7 +59,7 @@ def has_valid_checksum(self, number):
result += int(number[i]) * multiple_table[i]
return result % 10 == 0

class PLTaxNumberField(RegexField):
class PLNIPField(RegexField):
"""
A form field that validates as Polish Tax Number (NIP).
Valid forms are: XXX-XXX-YY-YY or XX-XX-YYY-YYY.
Expand All @@ -74,11 +73,11 @@ class PLTaxNumberField(RegexField):
}

def __init__(self, *args, **kwargs):
super(PLTaxNumberField, 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{2}-\d{2}-\d{3}-\d{3}$',
max_length=None, min_length=None, *args, **kwargs)

def clean(self,value):
super(PLTaxNumberField, self).clean(value)
super(PLNIPField, self).clean(value)
value = re.sub("[-]", "", value)
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
Expand All @@ -99,10 +98,10 @@ def has_valid_checksum(self, number):
else:
return False

class PLNationalBusinessRegisterField(RegexField):
class PLREGONField(RegexField):
"""
A form field that validated as Polish National Official Business Register Number (REGON)
Valid forms are: 7 or 9 digits number
A form field that validated as Polish National Official Business Register
Number (REGON). Valid numbers contain 7 or 9 digits.
More on the field: http://www.stat.gov.pl/bip/regon_ENG_HTML.htm
Expand All @@ -114,11 +113,11 @@ class PLNationalBusinessRegisterField(RegexField):
}

def __init__(self, *args, **kwargs):
super(PLNationalBusinessRegisterField, self).__init__(r'^\d{7,9}$',
super(PLREGONField, self).__init__(r'^\d{7,9}$',
max_length=None, min_length=None, *args, **kwargs)

def clean(self,value):
super(PLNationalBusinessRegisterField, self).clean(value)
super(PLREGONField, self).clean(value)
if not self.has_valid_checksum(value):
raise ValidationError(self.error_messages['checksum'])
return u'%s' % value
Expand Down

0 comments on commit 4adf048

Please sign in to comment.