Ticket #7686: atlocalgflavor3.diff
File atlocalgflavor3.diff, 5.1 KB (added by , 16 years ago) |
---|
-
tests.py
4 4 from forms import tests as form_tests 5 5 from error_messages import tests as custom_error_message_tests 6 6 from localflavor.ar import tests as localflavor_ar_tests 7 from localflavor.at import tests as localflavor_at_tests 7 8 from localflavor.au import tests as localflavor_au_tests 8 9 from localflavor.br import tests as localflavor_br_tests 9 10 from localflavor.ca import tests as localflavor_ca_tests … … 33 34 'form_tests': form_tests, 34 35 'custom_error_message_tests': custom_error_message_tests, 35 36 'localflavor_ar_tests': localflavor_ar_tests, 37 'localflavor_at_tests': localflavor_at_tests, 36 38 'localflavor_au_tests': localflavor_au_tests, 37 39 'localflavor_br_tests': localflavor_br_tests, 38 40 'localflavor_ca_tests': localflavor_ca_tests, -
django/contrib/localflavor/at/forms.py
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 -
django/contrib/localflavor/at/at_states.py
1 # -*- coding: utf-8 -* 2 from django.utils.translation import ugettext_lazy as _ 3 4 STATE_CHOICES = ( 5 ('BL', _('Burgenland')), 6 ('KA', _('Carinthia')), 7 ('NO', _('Lower Austria')), 8 ('OO', _('Upper Austria')), 9 ('SA', _('Salzburg')), 10 ('ST', _('Styria')), 11 ('TI', _('Tyrol')), 12 ('VO', _('Vorarlberg')), 13 ('WI', _('Vienna')), 14 ) 15 No newline at end of file -
tests/regressiontests/forms/localflavor/at.py
1 # -*- coding: utf-8 -*- 2 # Tests for the contrib/localflavor/ AT form fields. 3 4 tests = r""" 5 # ATZipCodeField ########################################################### 6 7 >>> from django.contrib.localflavor.at.forms import ATZipCodeField 8 >>> f = ATZipCodeField() 9 >>> f.clean('1150') 10 u'1150' 11 >>> f.clean('4020') 12 u'4020' 13 >>> f.clean('8020') 14 u'8020' 15 >>> f.clean('111222') 16 Traceback (most recent call last): 17 ... 18 ValidationError: [u'Enter a zip code in the format XXXX.'] 19 >>> f.clean('eeffee') 20 Traceback (most recent call last): 21 ... 22 ValidationError: [u'Enter a zip code in the format XXXX.'] 23 >>> f.clean(u'') 24 Traceback (most recent call last): 25 ... 26 ValidationError: [u'This field is required.'] 27 >>> f.clean(None) 28 Traceback (most recent call last): 29 ... 30 ValidationError: [u'This field is required.'] 31 >>> f.clean('') 32 Traceback (most recent call last): 33 ... 34 ValidationError: [u'This field is required.'] 35 36 37 >>> f = ATZipCodeField(required=False) 38 >>> f.clean('1150') 39 u'1150' 40 >>> f.clean('4020') 41 u'4020' 42 >>> f.clean('8020') 43 u'8020' 44 >>> f.clean('111222') 45 Traceback (most recent call last): 46 ... 47 ValidationError: [u'Enter a zip code in the format XXXX.'] 48 >>> f.clean('eeffee') 49 Traceback (most recent call last): 50 ... 51 ValidationError: [u'Enter a zip code in the format XXXX.'] 52 >>> f.clean(None) 53 u'' 54 >>> f.clean('') 55 u'' 56 >>> f.clean(u'') 57 u'' 58 59 # ATStateSelect ################################################################## 60 61 >>> from django.contrib.localflavor.at.forms import ATStateSelect 62 >>> f = ATStateSelect() 63 >>> f.render('bundesland', 'WI') 64 u'<select name="bundesland">\n<option value="BL">Burgenland</option>\n<option value="KA">Carinthia</option>\n<option value="NO">Lower Austria</option>\n<option value="OO">Upper Austria</option>\n<option value="SA">Salzburg</option>\n<option value="ST">Styria</option>\n<option value="TI">Tyrol</option>\n<option value="VO">Vorarlberg</option>\n<option value="WI" selected="selected">Vienna</option>\n</select>' 65 66 """