| | 1 | """ |
| | 2 | AT-specific Form helpers |
| | 3 | """ |
| | 4 | |
| | 5 | from django.utils.translation import ugettext_lazy as _ |
| | 6 | from django.newforms.fields import Field, RegexField, Select |
| | 7 | import re |
| | 8 | |
| | 9 | class ATZipCodeField(RegexField): |
| | 10 | """ |
| | 11 | A form field that validates its input is a Austrian postcode. |
| | 12 | |
| | 13 | Accepts 4 digits |
| | 14 | """ |
| | 15 | default_error_messages = { |
| | 16 | 'invalid': _('Enter a zip code in the format XXXX.'), |
| | 17 | } |
| | 18 | def __init__(self, *args, **kwargs): |
| | 19 | super(ATZipCodeField, self).__init__(r'^\d{4}$', |
| | 20 | max_length=None, min_length=None, *args, **kwargs) |
| | 21 | |
| | 22 | class ATStateSelect(Select): |
| | 23 | """ |
| | 24 | A Select widget that uses a list of AT states as its choices. |
| | 25 | """ |
| | 26 | def __init__(self, attrs=None): |
| | 27 | from at_states import STATE_CHOICES |
| | 28 | super(ATStateSelect, self).__init__(attrs, choices=STATE_CHOICES) |
| | 29 | No newline at end of file |