Ticket #3897: de-localflavor2.diff

File de-localflavor2.diff, 4.7 KB (added by Jannis Leidel <jl@…>, 12 years ago)

Marked state names for translation

  • django/contrib/localflavor/de/de_states.py

     
     1# -*- coding: utf-8 -*
     2from django.utils.translation import gettext_lazy as _
     3
     4STATE_CHOICES = (
     5    ('BW', _('Baden-Wurttemberg')),
     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)
  • django/contrib/localflavor/de/forms.py

     
     1"""
     2DE-specific Form helpers
     3"""
     4
     5from django.newforms import ValidationError
     6from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
     7from django.newforms.util import smart_unicode
     8from django.utils.translation import gettext
     9import re
     10
     11class 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
     18class 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

     
    840840>>> w.render('states', 'PR')
    841841u'<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>'
    842842"""
     843
     844# DEZipCodeField ##############################################################
     845
     846>>> from django.contrib.localflavor.de.forms import DEZipCodeField
     847>>> f = DEZipCodeField()
     848>>> f.clean('99423')
     849u'99423'
     850>>> f.clean(' 99423')
     851Traceback (most recent call last):
     852...
     853ValidationError: [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')
     860u'<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>'
Back to Top