
Property changes on: django/contrib/localflavor/sk
___________________________________________________________________
Name: svn:ignore
   + *.pyc


Index: django/contrib/localflavor/sk/__init__.py
===================================================================
Index: django/contrib/localflavor/sk/sk_regions.py
===================================================================
--- django/contrib/localflavor/sk/sk_regions.py	(revision 0)
+++ django/contrib/localflavor/sk/sk_regions.py	(revision 0)
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+"""
+Slovak regions according to http://sk.wikipedia.org/wiki/Administratívne_členenie_Slovenska
+"""
+
+REGION_CHOICES = (
+    ('BB', u'Banskobystrický'),
+    ('BA', u'Bratislavský'),
+    ('KE', u'Košický'),
+    ('NR', u'Nitriansky'),
+    ('PO', u'Prešovský'),
+    ('TN', u'Trenčiansky'),
+    ('TT', u'Trnavský'),
+    ('ZA', u'Žilinský'),
+)
\ No newline at end of file
Index: django/contrib/localflavor/sk/sk_districts.py
===================================================================
--- django/contrib/localflavor/sk/sk_districts.py	(revision 0)
+++ django/contrib/localflavor/sk/sk_districts.py	(revision 0)
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+"""
+Slovak districts according to http://sk.wikipedia.org/wiki/Administratívne_členenie_Slovenska
+"""
+
+DISTRICT_CHOICES = (
+    ("BB", u"Banská Bystrica"), 
+    ("BS", u"Banská Štiavnica"), 
+    ("BJ", u"Bardejov"), 
+    ("BN", u"Bánovce nad Bebravou"), 
+    ("BR", u"Brezno"), 
+    ("BA1", u"Bratislava I"), 
+    ("BA2", u"Bratislava II"), 
+    ("BA3", u"Bratislava III"), 
+    ("BA4", u"Bratislava IV"), 
+    ("BA5", u"Bratislava V"), 
+    ("BY", u"Bytča"), 
+    ("CA", u"Čadca"), 
+    ("DT", u"Detva"), 
+    ("DK", u"Dolný Kubín"), 
+    ("DS", u"Dunajská Streda"), 
+    ("GA", u"Galanta"), 
+    ("GL", u"Gelnica"), 
+    ("HC", u"Hlohovec"), 
+    ("HE", u"Humenné"), 
+    ("IL", u"Ilava"), 
+    ("KK", u"Kežmarok"), 
+    ("KN", u"Komárno"), 
+    ("KE1", u"Košice I"), 
+    ("KE2", u"Košice II"), 
+    ("KE3", u"Košice III"), 
+    ("KE4", u"Košice IV"), 
+    ("KEO", u"Košice - okolie"), 
+    ("KA", u"Krupina"), 
+    ("KM", u"Kysucké Nové Mesto"), 
+    ("LV", u"Levice"), 
+    ("LE", u"Levoča"), 
+    ("LM", u"Liptovský Mikuláš"), 
+    ("LC", u"Lučenec"), 
+    ("MA", u"Malacky"), 
+    ("MT", u"Martin"), 
+    ("ML", u"Medzilaborce"), 
+    ("MI", u"Michalovce"), 
+    ("MY", u"Myjava"), 
+    ("NO", u"Námestovo"), 
+    ("NR", u"Nitra"), 
+    ("NM", u"Nové Mesto nad Váhom"), 
+    ("NZ", u"Nové Zámky"), 
+    ("PE", u"Partizánske"), 
+    ("PK", u"Pezinok"), 
+    ("PN", u"Piešťany"), 
+    ("PT", u"Poltár"), 
+    ("PP", u"Poprad"), 
+    ("PB", u"Považská Bystrica"), 
+    ("PO", u"Prešov"), 
+    ("PD", u"Prievidza"), 
+    ("PU", u"Púchov"), 
+    ("RA", u"Revúca"), 
+    ("RS", u"Rimavská Sobota"), 
+    ("RV", u"Rožňava"), 
+    ("RK", u"Ružomberok"), 
+    ("SB", u"Sabinov"), 
+    ("SC", u"Senec"), 
+    ("SE", u"Senica"), 
+    ("SI", u"Skalica"), 
+    ("SV", u"Snina"), 
+    ("SO", u"Sobrance"), 
+    ("SN", u"Spišská Nová Ves"), 
+    ("SL", u"Stará Ľubovňa"), 
+    ("SP", u"Stropkov"), 
+    ("SK", u"Svidník"), 
+    ("SA", u"Šaľa"), 
+    ("TO", u"Topoľčany"), 
+    ("TV", u"Trebišov"), 
+    ("TN", u"Trenčín"), 
+    ("TT", u"Trnava"), 
+    ("TR", u"Turčianske Teplice"), 
+    ("TS", u"Tvrdošín"), 
+    ("VK", u"Veľký Krtíš"), 
+    ("VT", u"Vranov nad Topľou"), 
+    ("ZM", u"Zlaté Moravce"), 
+    ("ZV", u"Zvolen"), 
+    ("ZC", u"Žarnovica"), 
+    ("ZH", u"Žiar nad Hronom"),
+    ("ZA", u"Žilina"),
+)
\ No newline at end of file
Index: django/contrib/localflavor/sk/forms.py
===================================================================
--- django/contrib/localflavor/sk/forms.py	(revision 0)
+++ django/contrib/localflavor/sk/forms.py	(revision 0)
@@ -0,0 +1,41 @@
+"""
+Slovak-specific form helpers
+"""
+
+from django.newforms.fields import Select, RegexField
+from django.utils.translation import gettext
+
+class SKRegionSelect(Select):
+    """
+    A select widget widget with list of Slovak regions as choices.
+    """
+    def __init__(self, attrs=None):
+        from sk_regions import REGION_CHOICES
+        super(SKRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
+        
+class SKDistrictSelect(Select):
+    """
+    A select widget with list of Slovak districts as choices.
+    """
+    def __init__(self, attrs=None):
+        from sk_districts import DISTRICT_CHOICES
+        super(SKDistrictSelect, self).__init__(attrs, choices=DISTRICT_CHOICES)
+        
+class SKPostalCodeField(RegexField):
+    """
+    A form field that validates its input as Slovak postal code.
+    Valid form is XXXXX or XXX XX, where X represents integer.
+    """
+    def __init__(self, *args, **kwargs):
+        super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
+            max_length=None, min_length=None,
+            error_message=gettext(u'Enter a postal code in the format XXXXX or XXX XX.'),
+            *args, **kwargs)
+
+    def clean(self, value):
+        """
+        Validates the input and returns a string that contains only numbers.
+        Returns an empty string for empty values.
+        """
+        v = super(SKPostalCodeField, self).clean(value)
+        return v.replace(' ', '')
\ No newline at end of file
Index: tests/regressiontests/forms/localflavor.py
===================================================================
--- tests/regressiontests/forms/localflavor.py	(revision 4926)
+++ tests/regressiontests/forms/localflavor.py	(working copy)
@@ -882,4 +882,36 @@
 Traceback (most recent call last):
 ...
 ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format']
+
+
+# SKPostalCodeField #########################################################
+
+>>> from django.contrib.localflavor.sk.forms import SKPostalCodeField
+>>> f = SKPostalCodeField()
+>>> f.clean('84545x')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
+>>> f.clean('91909')
+u'91909'
+>>> f.clean('917 01')
+u'91701'
+
+# SKRegionSelect ############################################################
+
+>>> from django.contrib.localflavor.sk.forms import SKRegionSelect
+>>> w = SKRegionSelect()
+>>> w.render('regions', 'TT')
+u'<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>'
+
+# SKDistrictSelect ##########################################################
+
+>>> from django.contrib.localflavor.sk.forms import SKDistrictSelect
+>>> w = SKDistrictSelect()
+>>> w.render('districts', 'RK')
+u'<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>'
+
 """
+
+
+
