Ticket #3897: de-localflavor.diff
File de-localflavor.diff, 4.6 KB (added by , 18 years ago) |
---|
-
django/contrib/localflavor/de/de_states.py
1 # -*- coding: utf-8 -* 2 3 STATE_CHOICES = ( 4 ('BW', u'Baden-Württemberg'), 5 ('BY', 'Bayern'), 6 ('BE', 'Berlin'), 7 ('BB', 'Brandenburg'), 8 ('HB', 'Bremen'), 9 ('HH', 'Hamburg'), 10 ('HE', 'Hessen'), 11 ('MV', 'Mecklenburg-Vorpommern'), 12 ('NI', 'Niedersachsen'), 13 ('NW', 'Nordrhein-Westfalen'), 14 ('RP', 'Rheinland-Pfalz'), 15 ('SL', 'Saarland'), 16 ('SN', 'Sachsen'), 17 ('ST', 'Sachsen-Anhalt'), 18 ('SH', 'Schleswig-Holstein'), 19 ('TH', u'Thüringen'), 20 ) -
django/contrib/localflavor/de/forms.py
1 """ 2 DE-specific Form helpers 3 """ 4 5 from django.newforms import ValidationError 6 from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 7 from django.newforms.util import smart_unicode 8 from django.utils.translation import gettext 9 import re 10 11 class DEZipCodeField(RegexField): 12 def __init__(self, *args, **kwargs): 13 super(DEZipCodeField, self).__init__(r'^\d{5}$', 14 max_length=None, min_length=None, 15 error_message=gettext(u'Enter a zip code in the format XXXXX.'), 16 *args, **kwargs) 17 18 class DEStateSelect(Select): 19 """ 20 A Select widget that uses a list of DE states as its choices. 21 """ 22 def __init__(self, attrs=None): 23 from de_states import STATE_CHOICES # relative import 24 super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES) -
tests/regressiontests/forms/localflavor.py
840 840 >>> w.render('states', 'PR') 841 841 u'<select name="states">\n<option value="AC">Acre</option>\n<option value="AL">Alagoas</option>\n<option value="AP">Amap\xe1</option>\n<option value="AM">Amazonas</option>\n<option value="BA">Bahia</option>\n<option value="CE">Cear\xe1</option>\n<option value="DF">Distrito Federal</option>\n<option value="ES">Esp\xedrito Santo</option>\n<option value="GO">Goi\xe1s</option>\n<option value="MA">Maranh\xe3o</option>\n<option value="MT">Mato Grosso</option>\n<option value="MS">Mato Grosso do Sul</option>\n<option value="MG">Minas Gerais</option>\n<option value="PA">Par\xe1</option>\n<option value="PB">Para\xedba</option>\n<option value="PR" selected="selected">Paran\xe1</option>\n<option value="PE">Pernambuco</option>\n<option value="PI">Piau\xed</option>\n<option value="RJ">Rio de Janeiro</option>\n<option value="RN">Rio Grande do Norte</option>\n<option value="RS">Rio Grande do Sul</option>\n<option value="RO">Rond\xf4nia</option>\n<option value="RR">Roraima</option>\n<option value="SC">Santa Catarina</option>\n<option value="SP">S\xe3o Paulo</option>\n<option value="SE">Sergipe</option>\n<option value="TO">Tocantins</option>\n</select>' 842 842 """ 843 844 # DEZipCodeField ############################################################## 845 846 >>> from django.contrib.localflavor.de.forms import DEZipCodeField 847 >>> f = DEZipCodeField() 848 >>> f.clean('99423') 849 u'99423' 850 >>> f.clean(' 99423') 851 Traceback (most recent call last): 852 ... 853 ValidationError: [u'Enter a zip code in the format XXXXX.'] 854 855 # DEStateSelect ############################################################# 856 857 >>> from django.contrib.localflavor.de.forms import DEStateSelect 858 >>> w = DEStateSelect() 859 >>> w.render('states', 'TH') 860 u'<select name="states">\n<option value="BW">Baden-W\xfcrttemberg</option>\n<option value="BY">Bayern</option>\n<option value="BE">Berlin</option>\n<option value="BB">Brandenburg</option>\n<option value="HB">Bremen</option>\n<option value="HH">Hamburg</option>\n<option value="HE">Hessen</option>\n<option value="MV">Mecklenburg-Vorpommern</option>\n<option value="NI">Niedersachsen</option>\n<option value="NW">Nordrhein-Westfalen</option>\n<option value="RP">Rheinland-Pfalz</option>\n<option value="SL">Saarland</option>\n<option value="SN">Sachsen</option>\n<option value="ST">Sachsen-Anhalt</option>\n<option value="SH">Schleswig-Holstein</option>\n<option value="TH" selected="selected">Th\xfcringen</option>\n</select>'