Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #3897 -- Added German localflavor. Thanks, Jannis Leidel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4920 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7a0441b712609999b1d45884d8113c8f98c956ab 1 parent 5212911
@malcolmt malcolmt authored
View
1  AUTHORS
@@ -128,6 +128,7 @@ answer newbie questions, and generally made Django that much better:
Nicola Larosa <nico@teknico.net>
Eugene Lazutkin <http://lazutkin.com/blog/>
Jeong-Min Lee <falsetru@gmail.com>
+ Jannis Leidel <jl@websushi.org>
Christopher Lenz <http://www.cmlenz.net/>
lerouxb@gmail.com
Waylan Limberg <waylan@gmail.com>
View
0  django/contrib/localflavor/de/__init__.py
No changes.
View
21 django/contrib/localflavor/de/de_states.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*
+from django.utils.translation import gettext_lazy as _
+
+STATE_CHOICES = (
+ ('BW', _(u'Baden-Württemberg')),
+ ('BY', _('Bavaria')),
+ ('BE', _('Berlin')),
+ ('BB', _('Brandenburg')),
+ ('HB', _('Bremen')),
+ ('HH', _('Hamburg')),
+ ('HE', _('Hessen')),
+ ('MV', _('Mecklenburg-Western Pomerania')),
+ ('NI', _('Lower Saxony')),
+ ('NW', _('North Rhine-Westphalia')),
+ ('RP', _('Rhineland-Palatinate')),
+ ('SL', _('Saarland')),
+ ('SN', _('Saxony')),
+ ('ST', _('Saxony-Anhalt')),
+ ('SH', _('Schleswig-Holstein')),
+ ('TH', _('Thuringia')),
+)
View
23 django/contrib/localflavor/de/forms.py
@@ -0,0 +1,23 @@
+"""
+DE-specific Form helpers
+"""
+
+from django.newforms import ValidationError
+from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.utils.translation import gettext
+import re
+
+class DEZipCodeField(RegexField):
+ def __init__(self, *args, **kwargs):
+ super(DEZipCodeField, self).__init__(r'^\d{5}$',
+ max_length=None, min_length=None,
+ error_message=gettext(u'Enter a zip code in the format XXXXX.'),
+ *args, **kwargs)
+
+class DEStateSelect(Select):
+ """
+ A Select widget that uses a list of DE states as its choices.
+ """
+ def __init__(self, attrs=None):
+ from de_states import STATE_CHOICES # relative import
+ super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
View
18 tests/regressiontests/forms/localflavor.py
@@ -851,4 +851,22 @@
>>> w = BRStateSelect()
>>> w.render('states', 'PR')
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>'
+
+# DEZipCodeField ##############################################################
+
+>>> from django.contrib.localflavor.de.forms import DEZipCodeField
+>>> f = DEZipCodeField()
+>>> f.clean('99423')
+u'99423'
+>>> f.clean(' 99423')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a zip code in the format XXXXX.']
+
+# DEStateSelect #############################################################
+
+>>> from django.contrib.localflavor.de.forms import DEStateSelect
+>>> w = DEStateSelect()
+>>> w.render('states', 'TH')
+u'<select name="states">\n<option value="BW">Baden-W\xfcrttemberg</option>\n<option value="BY">Bavaria</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-Western Pomerania</option>\n<option value="NI">Lower Saxony</option>\n<option value="NW">North Rhine-Westphalia</option>\n<option value="RP">Rhineland-Palatinate</option>\n<option value="SL">Saarland</option>\n<option value="SN">Saxony</option>\n<option value="ST">Saxony-Anhalt</option>\n<option value="SH">Schleswig-Holstein</option>\n<option value="TH" selected="selected">Thuringia</option>\n</select>'
"""
Please sign in to comment.
Something went wrong with that request. Please try again.