Ticket #3925: localflavor_sk.diff

File localflavor_sk.diff, 10.3 KB (added by Martin Kosír <martin@…>, 18 years ago)

Slovak localflavor. Tests included.

  • django/contrib/localflavor/sk/sk_regions.py

    Property changes on: django/contrib/localflavor/sk
    ___________________________________________________________________
    Name: svn:ignore
       + *.pyc
    
    
     
     1# -*- coding: utf-8 -*-
     2"""
     3Slovak regions according to http://sk.wikipedia.org/wiki/Administratívne_členenie_Slovenska
     4"""
     5
     6REGION_CHOICES = (
     7    ('BB', u'Banskobystrický'),
     8    ('BA', u'Bratislavský'),
     9    ('KE', u'Košický'),
     10    ('NR', u'Nitriansky'),
     11    ('PO', u'Prešovský'),
     12    ('TN', u'Trenčiansky'),
     13    ('TT', u'Trnavský'),
     14    ('ZA', u'Žilinský'),
     15)
     16 No newline at end of file
  • django/contrib/localflavor/sk/sk_districts.py

     
     1# -*- coding: utf-8 -*-
     2"""
     3Slovak districts according to http://sk.wikipedia.org/wiki/Administratívne_členenie_Slovenska
     4"""
     5
     6DISTRICT_CHOICES = (
     7    ("BB", u"Banská Bystrica"),
     8    ("BS", u"Banská Štiavnica"),
     9    ("BJ", u"Bardejov"),
     10    ("BN", u"Bánovce nad Bebravou"),
     11    ("BR", u"Brezno"),
     12    ("BA1", u"Bratislava I"),
     13    ("BA2", u"Bratislava II"),
     14    ("BA3", u"Bratislava III"),
     15    ("BA4", u"Bratislava IV"),
     16    ("BA5", u"Bratislava V"),
     17    ("BY", u"Bytča"),
     18    ("CA", u"Čadca"),
     19    ("DT", u"Detva"),
     20    ("DK", u"Dolný Kubín"),
     21    ("DS", u"Dunajská Streda"),
     22    ("GA", u"Galanta"),
     23    ("GL", u"Gelnica"),
     24    ("HC", u"Hlohovec"),
     25    ("HE", u"Humenné"),
     26    ("IL", u"Ilava"),
     27    ("KK", u"Kežmarok"),
     28    ("KN", u"Komárno"),
     29    ("KE1", u"Košice I"),
     30    ("KE2", u"Košice II"),
     31    ("KE3", u"Košice III"),
     32    ("KE4", u"Košice IV"),
     33    ("KEO", u"Košice - okolie"),
     34    ("KA", u"Krupina"),
     35    ("KM", u"Kysucké Nové Mesto"),
     36    ("LV", u"Levice"),
     37    ("LE", u"Levoča"),
     38    ("LM", u"Liptovský Mikuláš"),
     39    ("LC", u"Lučenec"),
     40    ("MA", u"Malacky"),
     41    ("MT", u"Martin"),
     42    ("ML", u"Medzilaborce"),
     43    ("MI", u"Michalovce"),
     44    ("MY", u"Myjava"),
     45    ("NO", u"Námestovo"),
     46    ("NR", u"Nitra"),
     47    ("NM", u"Nové Mesto nad Váhom"),
     48    ("NZ", u"Nové Zámky"),
     49    ("PE", u"Partizánske"),
     50    ("PK", u"Pezinok"),
     51    ("PN", u"Piešťany"),
     52    ("PT", u"Poltár"),
     53    ("PP", u"Poprad"),
     54    ("PB", u"Považská Bystrica"),
     55    ("PO", u"Prešov"),
     56    ("PD", u"Prievidza"),
     57    ("PU", u"Púchov"),
     58    ("RA", u"Revúca"),
     59    ("RS", u"Rimavská Sobota"),
     60    ("RV", u"Rožňava"),
     61    ("RK", u"Ružomberok"),
     62    ("SB", u"Sabinov"),
     63    ("SC", u"Senec"),
     64    ("SE", u"Senica"),
     65    ("SI", u"Skalica"),
     66    ("SV", u"Snina"),
     67    ("SO", u"Sobrance"),
     68    ("SN", u"Spišská Nová Ves"),
     69    ("SL", u"Stará Ľubovňa"),
     70    ("SP", u"Stropkov"),
     71    ("SK", u"Svidník"),
     72    ("SA", u"Šaľa"),
     73    ("TO", u"Topoľčany"),
     74    ("TV", u"Trebišov"),
     75    ("TN", u"Trenčín"),
     76    ("TT", u"Trnava"),
     77    ("TR", u"Turčianske Teplice"),
     78    ("TS", u"Tvrdošín"),
     79    ("VK", u"Veľký Krtíš"),
     80    ("VT", u"Vranov nad Topľou"),
     81    ("ZM", u"Zlaté Moravce"),
     82    ("ZV", u"Zvolen"),
     83    ("ZC", u"Žarnovica"),
     84    ("ZH", u"Žiar nad Hronom"),
     85    ("ZA", u"Žilina"),
     86)
     87 No newline at end of file
  • django/contrib/localflavor/sk/forms.py

     
     1"""
     2Slovak-specific form helpers
     3"""
     4
     5from django.newforms.fields import Select, RegexField
     6from django.utils.translation import gettext
     7
     8class SKRegionSelect(Select):
     9    """
     10    A select widget widget with list of Slovak regions as choices.
     11    """
     12    def __init__(self, attrs=None):
     13        from sk_regions import REGION_CHOICES
     14        super(SKRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
     15       
     16class SKDistrictSelect(Select):
     17    """
     18    A select widget with list of Slovak districts as choices.
     19    """
     20    def __init__(self, attrs=None):
     21        from sk_districts import DISTRICT_CHOICES
     22        super(SKDistrictSelect, self).__init__(attrs, choices=DISTRICT_CHOICES)
     23       
     24class SKPostalCodeField(RegexField):
     25    """
     26    A form field that validates its input as Slovak postal code.
     27    Valid form is XXXXX or XXX XX, where X represents integer.
     28    """
     29    def __init__(self, *args, **kwargs):
     30        super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
     31            max_length=None, min_length=None,
     32            error_message=gettext(u'Enter a postal code in the format XXXXX or XXX XX.'),
     33            *args, **kwargs)
     34
     35    def clean(self, value):
     36        """
     37        Validates the input and returns a string that contains only numbers.
     38        Returns an empty string for empty values.
     39        """
     40        v = super(SKPostalCodeField, self).clean(value)
     41        return v.replace(' ', '')
     42 No newline at end of file
  • tests/regressiontests/forms/localflavor.py

     
    882882Traceback (most recent call last):
    883883...
    884884ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format']
     885
     886
     887# SKPostalCodeField #########################################################
     888
     889>>> from django.contrib.localflavor.sk.forms import SKPostalCodeField
     890>>> f = SKPostalCodeField()
     891>>> f.clean('84545x')
     892Traceback (most recent call last):
     893...
     894ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
     895>>> f.clean('91909')
     896u'91909'
     897>>> f.clean('917 01')
     898u'91701'
     899
     900# SKRegionSelect ############################################################
     901
     902>>> from django.contrib.localflavor.sk.forms import SKRegionSelect
     903>>> w = SKRegionSelect()
     904>>> w.render('regions', 'TT')
     905u'<select name="regions">\n<option value="BB">Banskobystrick\xfd</option>\n<option value="BA">Bratislavsk\xfd</option>\n<option value="KE">Ko\u0161ick\xfd</option>\n<option value="NR">Nitriansky</option>\n<option value="PO">Pre\u0161ovsk\xfd</option>\n<option value="TN">Tren\u010diansky</option>\n<option value="TT" selected="selected">Trnavsk\xfd</option>\n<option value="ZA">\u017dilinsk\xfd</option>\n</select>'
     906
     907# SKDistrictSelect ##########################################################
     908
     909>>> from django.contrib.localflavor.sk.forms import SKDistrictSelect
     910>>> w = SKDistrictSelect()
     911>>> w.render('districts', 'RK')
     912u'<select name="districts">\n<option value="BB">Bansk\xe1 Bystrica</option>\n<option value="BS">Bansk\xe1 \u0160tiavnica</option>\n<option value="BJ">Bardejov</option>\n<option value="BN">B\xe1novce nad Bebravou</option>\n<option value="BR">Brezno</option>\n<option value="BA1">Bratislava I</option>\n<option value="BA2">Bratislava II</option>\n<option value="BA3">Bratislava III</option>\n<option value="BA4">Bratislava IV</option>\n<option value="BA5">Bratislava V</option>\n<option value="BY">Byt\u010da</option>\n<option value="CA">\u010cadca</option>\n<option value="DT">Detva</option>\n<option value="DK">Doln\xfd Kub\xedn</option>\n<option value="DS">Dunajsk\xe1 Streda</option>\n<option value="GA">Galanta</option>\n<option value="GL">Gelnica</option>\n<option value="HC">Hlohovec</option>\n<option value="HE">Humenn\xe9</option>\n<option value="IL">Ilava</option>\n<option value="KK">Ke\u017emarok</option>\n<option value="KN">Kom\xe1rno</option>\n<option value="KE1">Ko\u0161ice I</option>\n<option value="KE2">Ko\u0161ice II</option>\n<option value="KE3">Ko\u0161ice III</option>\n<option value="KE4">Ko\u0161ice IV</option>\n<option value="KEO">Ko\u0161ice - okolie</option>\n<option value="KA">Krupina</option>\n<option value="KM">Kysuck\xe9 Nov\xe9 Mesto</option>\n<option value="LV">Levice</option>\n<option value="LE">Levo\u010da</option>\n<option value="LM">Liptovsk\xfd Mikul\xe1\u0161</option>\n<option value="LC">Lu\u010denec</option>\n<option value="MA">Malacky</option>\n<option value="MT">Martin</option>\n<option value="ML">Medzilaborce</option>\n<option value="MI">Michalovce</option>\n<option value="MY">Myjava</option>\n<option value="NO">N\xe1mestovo</option>\n<option value="NR">Nitra</option>\n<option value="NM">Nov\xe9 Mesto nad V\xe1hom</option>\n<option value="NZ">Nov\xe9 Z\xe1mky</option>\n<option value="PE">Partiz\xe1nske</option>\n<option value="PK">Pezinok</option>\n<option value="PN">Pie\u0161\u0165any</option>\n<option value="PT">Polt\xe1r</option>\n<option value="PP">Poprad</option>\n<option value="PB">Pova\u017esk\xe1 Bystrica</option>\n<option value="PO">Pre\u0161ov</option>\n<option value="PD">Prievidza</option>\n<option value="PU">P\xfachov</option>\n<option value="RA">Rev\xfaca</option>\n<option value="RS">Rimavsk\xe1 Sobota</option>\n<option value="RV">Ro\u017e\u0148ava</option>\n<option value="RK" selected="selected">Ru\u017eomberok</option>\n<option value="SB">Sabinov</option>\n<option value="SC">Senec</option>\n<option value="SE">Senica</option>\n<option value="SI">Skalica</option>\n<option value="SV">Snina</option>\n<option value="SO">Sobrance</option>\n<option value="SN">Spi\u0161sk\xe1 Nov\xe1 Ves</option>\n<option value="SL">Star\xe1 \u013dubov\u0148a</option>\n<option value="SP">Stropkov</option>\n<option value="SK">Svidn\xedk</option>\n<option value="SA">\u0160a\u013ea</option>\n<option value="TO">Topo\u013e\u010dany</option>\n<option value="TV">Trebi\u0161ov</option>\n<option value="TN">Tren\u010d\xedn</option>\n<option value="TT">Trnava</option>\n<option value="TR">Tur\u010dianske Teplice</option>\n<option value="TS">Tvrdo\u0161\xedn</option>\n<option value="VK">Ve\u013ek\xfd Krt\xed\u0161</option>\n<option value="VT">Vranov nad Top\u013eou</option>\n<option value="ZM">Zlat\xe9 Moravce</option>\n<option value="ZV">Zvolen</option>\n<option value="ZC">\u017darnovica</option>\n<option value="ZH">\u017diar nad Hronom</option>\n<option value="ZA">\u017dilina</option>\n</select>'
     913
    885914"""
     915
     916
     917
Back to Top