Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3925 -- Added Slovak localflavor items. Thanks, Martin Kosír.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5724 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f5ef3bec6868cc4e04f2a7816821a44ec104c923 1 parent 9ff1060
Malcolm Tredinnick authored July 19, 2007
41  django/contrib/localflavor/sk/forms.py
... ...
@@ -0,0 +1,41 @@
  1
+"""
  2
+Slovak-specific form helpers
  3
+"""
  4
+
  5
+from django.newforms.fields import Select, RegexField
  6
+from django.utils.translation import ugettext
  7
+
  8
+class 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
+
  16
+class 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
+
  24
+class 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=ugettext(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(' ', '')
87  django/contrib/localflavor/sk/sk_districts.py
... ...
@@ -0,0 +1,87 @@
  1
+"""
  2
+Slovak districts according to http://sk.wikipedia.org/wiki/Administrat%C3%ADvne_%C4%8Dlenenie_Slovenska
  3
+"""
  4
+
  5
+from django.utils.translation import ugettext_lazy as _
  6
+
  7
+DISTRICT_CHOICES = (
  8
+    ('BB', _('Banska Bystrica')),
  9
+    ('BS', _('Banska Stiavnica')),
  10
+    ('BJ', _('Bardejov')),
  11
+    ('BN', _('Banovce nad Bebravou')),
  12
+    ('BR', _('Brezno')),
  13
+    ('BA1', _('Bratislava I')),
  14
+    ('BA2', _('Bratislava II')),
  15
+    ('BA3', _('Bratislava III')),
  16
+    ('BA4', _('Bratislava IV')),
  17
+    ('BA5', _('Bratislava V')),
  18
+    ('BY', _('Bytca')),
  19
+    ('CA', _('Cadca')),
  20
+    ('DT', _('Detva')),
  21
+    ('DK', _('Dolny Kubin')),
  22
+    ('DS', _('Dunajska Streda')),
  23
+    ('GA', _('Galanta')),
  24
+    ('GL', _('Gelnica')),
  25
+    ('HC', _('Hlohovec')),
  26
+    ('HE', _('Humenne')),
  27
+    ('IL', _('Ilava')),
  28
+    ('KK', _('Kezmarok')),
  29
+    ('KN', _('Komarno')),
  30
+    ('KE1', _('Kosice I')),
  31
+    ('KE2', _('Kosice II')),
  32
+    ('KE3', _('Kosice III')),
  33
+    ('KE4', _('Kosice IV')),
  34
+    ('KEO', _('Kosice - okolie')),
  35
+    ('KA', _('Krupina')),
  36
+    ('KM', _('Kysucke Nove Mesto')),
  37
+    ('LV', _('Levice')),
  38
+    ('LE', _('Levoca')),
  39
+    ('LM', _('Liptovsky Mikulas')),
  40
+    ('LC', _('Lucenec')),
  41
+    ('MA', _('Malacky')),
  42
+    ('MT', _('Martin')),
  43
+    ('ML', _('Medzilaborce')),
  44
+    ('MI', _('Michalovce')),
  45
+    ('MY', _('Myjava')),
  46
+    ('NO', _('Namestovo')),
  47
+    ('NR', _('Nitra')),
  48
+    ('NM', _('Nove Mesto nad Vahom')),
  49
+    ('NZ', _('Nove Zamky')),
  50
+    ('PE', _('Partizanske')),
  51
+    ('PK', _('Pezinok')),
  52
+    ('PN', _('Piestany')),
  53
+    ('PT', _('Poltar')),
  54
+    ('PP', _('Poprad')),
  55
+    ('PB', _('Povazska Bystrica')),
  56
+    ('PO', _('Presov')),
  57
+    ('PD', _('Prievidza')),
  58
+    ('PU', _('Puchov')),
  59
+    ('RA', _('Revuca')),
  60
+    ('RS', _('Rimavska Sobota')),
  61
+    ('RV', _('Roznava')),
  62
+    ('RK', _('Ruzomberok')),
  63
+    ('SB', _('Sabinov')),
  64
+    ('SC', _('Senec')),
  65
+    ('SE', _('Senica')),
  66
+    ('SI', _('Skalica')),
  67
+    ('SV', _('Snina')),
  68
+    ('SO', _('Sobrance')),
  69
+    ('SN', _('Spisska Nova Ves')),
  70
+    ('SL', _('Stara Lubovna')),
  71
+    ('SP', _('Stropkov')),
  72
+    ('SK', _('Svidnik')),
  73
+    ('SA', _('Sala')),
  74
+    ('TO', _('Topolcany')),
  75
+    ('TV', _('Trebisov')),
  76
+    ('TN', _('Trencin')),
  77
+    ('TT', _('Trnava')),
  78
+    ('TR', _('Turcianske Teplice')),
  79
+    ('TS', _('Tvrdosin')),
  80
+    ('VK', _('Velky Krtis')),
  81
+    ('VT', _('Vranov nad Toplou')),
  82
+    ('ZM', _('Zlate Moravce')),
  83
+    ('ZV', _('Zvolen')),
  84
+    ('ZC', _('Zarnovica')),
  85
+    ('ZH', _('Ziar nad Hronom')),
  86
+    ('ZA', _('Zilina')),
  87
+)
16  django/contrib/localflavor/sk/sk_regions.py
... ...
@@ -0,0 +1,16 @@
  1
+"""
  2
+Slovak regions according to http://sk.wikipedia.org/wiki/Administrat%C3%ADvne_%C4%8Dlenenie_Slovenska
  3
+"""
  4
+
  5
+from django.utils.translation import ugettext_lazy as _
  6
+
  7
+REGION_CHOICES = (
  8
+    ('BB', _('Banska Bystrica region')),
  9
+    ('BA', _('Bratislava region')),
  10
+    ('KE', _('Kosice region')),
  11
+    ('NR', _('Nitra region')),
  12
+    ('PO', _('Presov region')),
  13
+    ('TN', _('Trencin region')),
  14
+    ('TT', _('Trnava region')),
  15
+    ('ZA', _('Zilina region')),
  16
+)
0  localflavor/sk/__init__.py b/django/contrib/localflavor/sk/__init__.py
No changes.
27  tests/regressiontests/forms/localflavor.py
@@ -1363,5 +1363,32 @@
1363 1363
 >>> f.render('foo', 'bar')
1364 1364
 u'<select name="foo">\n<option value="RM">Regi\xf3n Metropolitana de Santiago</option>\n<option value="I">Regi\xf3n de Tarapac\xe1</option>\n<option value="II">Regi\xf3n de Antofagasta</option>\n<option value="III">Regi\xf3n de Atacama</option>\n<option value="IV">Regi\xf3n de Coquimbo</option>\n<option value="V">Regi\xf3n de Valpara\xedso</option>\n<option value="VI">Regi\xf3n del Libertador Bernardo O&#39;Higgins</option>\n<option value="VII">Regi\xf3n del Maule</option>\n<option value="VIII">Regi\xf3n del B\xedo B\xedo</option>\n<option value="IX">Regi\xf3n de la Araucan\xeda</option>\n<option value="X">Regi\xf3n de los Lagos</option>\n<option value="XI">Regi\xf3n de Ays\xe9n del General Carlos Ib\xe1\xf1ez del Campo</option>\n<option value="XII">Regi\xf3n de Magallanes y la Ant\xe1rtica Chilena</option>\n<option value="XIV">Regi\xf3n de Los R\xedos</option>\n<option value="XV">Regi\xf3n de Arica-Parinacota</option>\n</select>'
1365 1365
 
  1366
+# SKPostalCodeField #########################################################
  1367
+
  1368
+>>> from django.contrib.localflavor.sk.forms import SKPostalCodeField
  1369
+>>> f = SKPostalCodeField()
  1370
+>>> f.clean('84545x')
  1371
+Traceback (most recent call last):
  1372
+...
  1373
+ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
  1374
+>>> f.clean('91909')
  1375
+u'91909'
  1376
+>>> f.clean('917 01')
  1377
+u'91701'
  1378
+
  1379
+# SKRegionSelect ############################################################
  1380
+
  1381
+>>> from django.contrib.localflavor.sk.forms import SKRegionSelect
  1382
+>>> w = SKRegionSelect()
  1383
+>>> w.render('regions', 'TT')
  1384
+u'<select name="regions">\n<option value="BB">Banska Bystrica region</option>\n<option value="BA">Bratislava region</option>\n<option value="KE">Kosice region</option>\n<option value="NR">Nitra region</option>\n<option value="PO">Presov region</option>\n<option value="TN">Trencin region</option>\n<option value="TT" selected="selected">Trnava region</option>\n<option value="ZA">Zilina region</option>\n</select>'
  1385
+
  1386
+# SKDistrictSelect ##########################################################
  1387
+
  1388
+>>> from django.contrib.localflavor.sk.forms import SKDistrictSelect
  1389
+>>> w = SKDistrictSelect()
  1390
+>>> w.render('Districts', 'RK')
  1391
+u'<select name="Districts">\n<option value="BB">Banska Bystrica</option>\n<option value="BS">Banska Stiavnica</option>\n<option value="BJ">Bardejov</option>\n<option value="BN">Banovce 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">Bytca</option>\n<option value="CA">Cadca</option>\n<option value="DT">Detva</option>\n<option value="DK">Dolny Kubin</option>\n<option value="DS">Dunajska Streda</option>\n<option value="GA">Galanta</option>\n<option value="GL">Gelnica</option>\n<option value="HC">Hlohovec</option>\n<option value="HE">Humenne</option>\n<option value="IL">Ilava</option>\n<option value="KK">Kezmarok</option>\n<option value="KN">Komarno</option>\n<option value="KE1">Kosice I</option>\n<option value="KE2">Kosice II</option>\n<option value="KE3">Kosice III</option>\n<option value="KE4">Kosice IV</option>\n<option value="KEO">Kosice - okolie</option>\n<option value="KA">Krupina</option>\n<option value="KM">Kysucke Nove Mesto</option>\n<option value="LV">Levice</option>\n<option value="LE">Levoca</option>\n<option value="LM">Liptovsky Mikulas</option>\n<option value="LC">Lucenec</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">Namestovo</option>\n<option value="NR">Nitra</option>\n<option value="NM">Nove Mesto nad Vahom</option>\n<option value="NZ">Nove Zamky</option>\n<option value="PE">Partizanske</option>\n<option value="PK">Pezinok</option>\n<option value="PN">Piestany</option>\n<option value="PT">Poltar</option>\n<option value="PP">Poprad</option>\n<option value="PB">Povazska Bystrica</option>\n<option value="PO">Presov</option>\n<option value="PD">Prievidza</option>\n<option value="PU">Puchov</option>\n<option value="RA">Revuca</option>\n<option value="RS">Rimavska Sobota</option>\n<option value="RV">Roznava</option>\n<option value="RK" selected="selected">Ruzomberok</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">Spisska Nova Ves</option>\n<option value="SL">Stara Lubovna</option>\n<option value="SP">Stropkov</option>\n<option value="SK">Svidnik</option>\n<option value="SA">Sala</option>\n<option value="TO">Topolcany</option>\n<option value="TV">Trebisov</option>\n<option value="TN">Trencin</option>\n<option value="TT">Trnava</option>\n<option value="TR">Turcianske Teplice</option>\n<option value="TS">Tvrdosin</option>\n<option value="VK">Velky Krtis</option>\n<option value="VT">Vranov nad Toplou</option>\n<option value="ZM">Zlate Moravce</option>\n<option value="ZV">Zvolen</option>\n<option value="ZC">Zarnovica</option>\n<option value="ZH">Ziar nad Hronom</option>\n<option value="ZA">Zilina</option>\n</select>'
  1392
+
1366 1393
 """
1367 1394
 

0 notes on commit f5ef3be

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