Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Malcolm Tredinnick authored April 04, 2007
1  AUTHORS
@@ -128,6 +128,7 @@ answer newbie questions, and generally made Django that much better:
128 128
     Nicola Larosa <nico@teknico.net>
129 129
     Eugene Lazutkin <http://lazutkin.com/blog/>
130 130
     Jeong-Min Lee <falsetru@gmail.com>
  131
+    Jannis Leidel <jl@websushi.org>
131 132
     Christopher Lenz <http://www.cmlenz.net/>
132 133
     lerouxb@gmail.com
133 134
     Waylan Limberg <waylan@gmail.com>
21  django/contrib/localflavor/de/de_states.py
... ...
@@ -0,0 +1,21 @@
  1
+# -*- coding: utf-8 -*
  2
+from django.utils.translation import gettext_lazy as _
  3
+
  4
+STATE_CHOICES = (
  5
+    ('BW', _(u'Baden-Württemberg')),
  6
+    ('BY', _('Bavaria')),
  7
+    ('BE', _('Berlin')),
  8
+    ('BB', _('Brandenburg')),
  9
+    ('HB', _('Bremen')),
  10
+    ('HH', _('Hamburg')),
  11
+    ('HE', _('Hessen')),
  12
+    ('MV', _('Mecklenburg-Western Pomerania')),
  13
+    ('NI', _('Lower Saxony')),
  14
+    ('NW', _('North Rhine-Westphalia')),
  15
+    ('RP', _('Rhineland-Palatinate')),
  16
+    ('SL', _('Saarland')),
  17
+    ('SN', _('Saxony')),
  18
+    ('ST', _('Saxony-Anhalt')),
  19
+    ('SH', _('Schleswig-Holstein')),
  20
+    ('TH', _('Thuringia')),
  21
+)
23  django/contrib/localflavor/de/forms.py
... ...
@@ -0,0 +1,23 @@
  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.utils.translation import gettext
  8
+import re
  9
+
  10
+class DEZipCodeField(RegexField):
  11
+    def __init__(self, *args, **kwargs):
  12
+        super(DEZipCodeField, self).__init__(r'^\d{5}$',
  13
+        max_length=None, min_length=None,
  14
+        error_message=gettext(u'Enter a zip code in the format XXXXX.'),
  15
+        *args, **kwargs)
  16
+
  17
+class DEStateSelect(Select):
  18
+    """
  19
+    A Select widget that uses a list of DE states as its choices.
  20
+    """
  21
+    def __init__(self, attrs=None):
  22
+        from de_states import STATE_CHOICES # relative import
  23
+        super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
0  localflavor/de/__init__.py b/django/contrib/localflavor/de/__init__.py
No changes.
18  tests/regressiontests/forms/localflavor.py
@@ -851,4 +851,22 @@
851 851
 >>> w = BRStateSelect()
852 852
 >>> w.render('states', 'PR')
853 853
 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>'
  854
+
  855
+# DEZipCodeField ##############################################################
  856
+
  857
+>>> from django.contrib.localflavor.de.forms import DEZipCodeField
  858
+>>> f = DEZipCodeField()
  859
+>>> f.clean('99423')
  860
+u'99423'
  861
+>>> f.clean(' 99423')
  862
+Traceback (most recent call last):
  863
+...
  864
+ValidationError: [u'Enter a zip code in the format XXXXX.']
  865
+
  866
+# DEStateSelect #############################################################
  867
+
  868
+>>> from django.contrib.localflavor.de.forms import DEStateSelect
  869
+>>> w = DEStateSelect()
  870
+>>> w.render('states', 'TH')
  871
+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>'
854 872
 """

0 notes on commit 7a0441b

Please sign in to comment.
Something went wrong with that request. Please try again.