Django

Code

root/django/trunk/django/contrib/localflavor/sk/forms.py

Revision 7971, 1.4 kB (checked in by jacob, 4 months ago)

Fixed #7741: django.newforms is now django.forms. This is obviously a backwards-incompatible change. There's a warning upon import of django.newforms itself, but deeper imports will raise errors.

  • Property svn:eol-style set to native
Line 
1 """
2 Slovak-specific form helpers
3 """
4
5 from django.forms.fields import Select, RegexField
6 from django.utils.translation import ugettext_lazy as _
7
8 class SKRegionSelect(Select):
9     """
10     A select widget widget with list of Slovak regions as choices.
11     """
12     def __init__(self, attrs=None):
13         from sk_regions import REGION_CHOICES
14         super(SKRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
15
16 class SKDistrictSelect(Select):
17     """
18     A select widget with list of Slovak districts as choices.
19     """
20     def __init__(self, attrs=None):
21         from sk_districts import DISTRICT_CHOICES
22         super(SKDistrictSelect, self).__init__(attrs, choices=DISTRICT_CHOICES)
23
24 class SKPostalCodeField(RegexField):
25     """
26     A form field that validates its input as Slovak postal code.
27     Valid form is XXXXX or XXX XX, where X represents integer.
28     """
29     default_error_messages = {
30         'invalid': _(u'Enter a postal code in the format XXXXX or XXX XX.'),
31     }
32
33     def __init__(self, *args, **kwargs):
34         super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
35             max_length=None, min_length=None, *args, **kwargs)
36
37     def clean(self, value):
38         """
39         Validates the input and returns a string that contains only numbers.
40         Returns an empty string for empty values.
41         """
42         v = super(SKPostalCodeField, self).clean(value)
43         return v.replace(' ', '')
Note: See TracBrowser for help on using the browser.