diff --git a/django/contrib/localflavor/si/__init__.py b/django/contrib/localflavor/si/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/contrib/localflavor/si/forms.py b/django/contrib/localflavor/si/forms.py new file mode 100644 index 0000000000..103b142213 --- /dev/null +++ b/django/contrib/localflavor/si/forms.py @@ -0,0 +1,164 @@ +""" +Slovenian specific form helpers. +""" + +import datetime +import re + +from django.forms.fields import CharField, Select, ChoiceField +from django.core.validators import EMPTY_VALUES +from django.forms import ValidationError +from django.utils.translation import ugettext_lazy as _ + + +class SIEMSOField(CharField): + """A form for validating Slovenian personal identification number. + + Additionally stores gender, nationality and birthday to self.info dictionary. + """ + + default_error_messages = { + 'invalid': _(u'This field should contain exactly 13 digits.'), + 'date': _(u'The first 7 digits of the EMSO must represent a valid past date.'), + 'checksum': _(u'The EMSO is not valid.'), + } + emso_regex = re.compile('^(\d{2})(\d{2})(\d{3})(\d{2})(\d{3})(\d)$') + + def clean(self, value): + super(SIEMSOField, self).clean(value) + if value in EMPTY_VALUES: + return u'' + + value = value.strip() + + m = self.emso_regex.match(value) + if m is None: + raise ValidationError(self.default_error_messages['invalid']) + + # Validate EMSO + s = 0 + int_values = [int(i) for i in value] + for a, b in zip(int_values, range(7, 1, -1) * 2): + s += a * b + chk = s % 11 + if chk == 0: + K = 0 + else: + K = 11 - chk + + if K == 10 or int_values[-1] != K: + raise ValidationError(self.default_error_messages['checksum']) + + # Extract extra info in the identification number + day, month, year, nationality, gender, chksum = [int(i) for i in m.groups()] + + if year < 890: + year += 2000 + else: + year += 1000 + + # validate birthday + try: + birthday = datetime.date(year, month, day) + except ValueError: + raise ValidationError(self.error_messages['date']) + if datetime.date.today() < birthday: + raise ValidationError(self.error_messages['date']) + + self.info = { + 'gender': gender < 500 and 'male' or 'female', + 'birthdate': birthday, + 'nationality': nationality, + } + return value + + +class SITaxNumberField(CharField): + """Slovenian tax number field. + + Valid input is SIXXXXXXXX or XXXXXXXX where X is a number. + """ + + default_error_messages = { + 'invalid': _(u'Enter a valid tax number in form SIXXXXXXXX'), + } + sitax_regex = re.compile('^(?:SI)?([1-9]\d{7})$') + + def clean(self, value): + super(SITaxNumberField, self).clean(value) + if value in EMPTY_VALUES: + return u'' + + value = value.strip() + + m = self.sitax_regex.match(value) + if m is None: + raise ValidationError(self.default_error_messages['invalid']) + value = m.groups()[0] + + # Validate Tax number + s = 0 + int_values = [int(i) for i in value] + for a, b in zip(int_values, range(8, 1, -1)): + s += a * b + chk = 11 - (s % 11) + if chk == 10: + chk = 0 + + if int_values[-1] != chk: + raise ValidationError(self.default_error_messages['invalid']) + + return value + + +class SIPostalCodeField(ChoiceField): + """Slovenian post codes field. + """ + + def __init__(self, *args, **kwargs): + from si_postalcodes import SI_POSTALCODES_CHOICES + kwargs.setdefault('choices', SI_POSTALCODES_CHOICES) + super(SIPostalCodeField, self).__init__(*args, **kwargs) + + +class SIPostalCodeSelect(Select): + """A Select widget that uses Slovenian postal codes as its choices. + """ + def __init__(self, attrs=None): + from si_postalcodes import SI_POSTALCODES_CHOICES + super(SIPostalCodeSelect, self).__init__(attrs, + choices=SI_POSTALCODES_CHOICES) + + +class SIPhoneNumberField(CharField): + """Slovenian phone number field. + + Phone number must contain at least local area code. + Country code can be present. + + Examples: + + * +38640XXXXXX + * 0038640XXXXXX + * 040XXXXXX + * 01XXXXXX + * 0590XXXXX + + """ + + default_error_messages = { + 'invalid': _(u'Enter phone number in form +386XXXXXXXX or 0XXXXXXXX.'), + } + phone_regex = re.compile('^(?:(?:00|\+)386|0)(\d{7,8})$') + + def clean(self, value): + super(SIPhoneNumberField, self).clean(value) + if value in EMPTY_VALUES: + return u'' + + value = value.replace(' ', '').replace('-', '').replace('/', '') + m = self.phone_regex.match(value) + + if m is None: + raise ValidationError(self.default_error_messages['invalid']) + return m.groups()[0] diff --git a/django/contrib/localflavor/si/si_postalcodes.py b/django/contrib/localflavor/si/si_postalcodes.py new file mode 100644 index 0000000000..6f4e6240d5 --- /dev/null +++ b/django/contrib/localflavor/si/si_postalcodes.py @@ -0,0 +1,468 @@ +# *-* coding: utf-8 *-* + +SI_POSTALCODES = [ + (1000, u'Ljubljana'), + (1215, u'Medvode'), + (1216, u'Smlednik'), + (1217, u'Vodice'), + (1218, u'Komenda'), + (1219, u'Laze v Tuhinju'), + (1221, u'Motnik'), + (1222, u'Trojane'), + (1223, u'Blagovica'), + (1225, u'Lukovica'), + (1230, u'Dom\u017eale'), + (1233, u'Dob'), + (1234, u'Menge\u0161'), + (1235, u'Radomlje'), + (1236, u'Trzin'), + (1241, u'Kamnik'), + (1242, u'Stahovica'), + (1251, u'Morav\u010de'), + (1252, u'Va\u010de'), + (1262, u'Dol pri Ljubljani'), + (1270, u'Litija'), + (1272, u'Pol\u0161nik'), + (1273, u'Dole pri Litiji'), + (1274, u'Gabrovka'), + (1275, u'\u0160martno pri Litiji'), + (1276, u'Primskovo'), + (1281, u'Kresnice'), + (1282, u'Sava'), + (1290, u'Grosuplje'), + (1291, u'\u0160kofljica'), + (1292, u'Ig'), + (1293, u'\u0160marje - Sap'), + (1294, u'Vi\u0161nja Gora'), + (1295, u'Ivan\u010dna Gorica'), + (1296, u'\u0160entvid pri Sti\u010dni'), + (1301, u'Krka'), + (1303, u'Zagradec'), + (1310, u'Ribnica'), + (1311, u'Turjak'), + (1312, u'Videm - Dobrepolje'), + (1313, u'Struge'), + (1314, u'Rob'), + (1315, u'Velike La\u0161\u010de'), + (1316, u'Ortnek'), + (1317, u'Sodra\u017eica'), + (1318, u'Lo\u0161ki Potok'), + (1319, u'Draga'), + (1330, u'Ko\u010devje'), + (1331, u'Dolenja vas'), + (1332, u'Stara Cerkev'), + (1336, u'Kostel'), + (1337, u'Osilnica'), + (1338, u'Ko\u010devska Reka'), + (1351, u'Brezovica pri Ljubljani'), + (1352, u'Preserje'), + (1353, u'Borovnica'), + (1354, u'Horjul'), + (1355, u'Polhov Gradec'), + (1356, u'Dobrova'), + (1357, u'Notranje Gorice'), + (1358, u'Log pri Brezovici'), + (1360, u'Vrhnika'), + (1370, u'Logatec'), + (1372, u'Hotedr\u0161ica'), + (1373, u'Rovte'), + (1380, u'Cerknica'), + (1381, u'Rakek'), + (1382, u'Begunje pri Cerknici'), + (1384, u'Grahovo'), + (1385, u'Nova vas'), + (1386, u'Stari trg pri Lo\u017eu'), + (1410, u'Zagorje ob Savi'), + (1411, u'Izlake'), + (1412, u'Kisovec'), + (1413, u'\u010cem\u0161enik'), + (1414, u'Podkum'), + (1420, u'Trbovlje'), + (1423, u'Dobovec'), + (1430, u'Hrastnik'), + (1431, u'Dol pri Hrastniku'), + (1432, u'Zidani Most'), + (1433, u'Rade\u010de'), + (1434, u'Loka pri Zidanem Mostu'), + (2000, u'Maribor'), + (2201, u'Zgornja Kungota'), + (2204, u'Miklav\u017e na Dravskem polju'), + (2205, u'Star\u0161e'), + (2206, u'Marjeta na Dravskem polju'), + (2208, u'Pohorje'), + (2211, u'Pesnica pri Mariboru'), + (2212, u'\u0160entilj v Slovenskih goricah'), + (2213, u'Zgornja Velka'), + (2214, u'Sladki vrh'), + (2215, u'Cer\u0161ak'), + (2221, u'Jarenina'), + (2222, u'Jakobski Dol'), + (2223, u'Jurovski Dol'), + (2229, u'Male\u010dnik'), + (2230, u'Lenart v Slovenskih goricah'), + (2231, u'Pernica'), + (2232, u'Voli\u010dina'), + (2233, u'Sveta Ana v Slovenskih goricah'), + (2234, u'Benedikt'), + (2235, u'Sveta Trojica v Slovenskih goricah'), + (2236, u'Cerkvenjak'), + (2241, u'Spodnji Duplek'), + (2242, u'Zgornja Korena'), + (2250, u'Ptuj'), + (2252, u'Dornava'), + (2253, u'Destrnik'), + (2254, u'Trnovska vas'), + (2255, u'Vitomarci'), + (2256, u'Jur\u0161inci'), + (2257, u'Polen\u0161ak'), + (2258, u'Sveti Toma\u017e'), + (2259, u'Ivanjkovci'), + (2270, u'Ormo\u017e'), + (2272, u'Gori\u0161nica'), + (2273, u'Podgorci'), + (2274, u'Velika Nedelja'), + (2275, u'Miklav\u017e pri Ormo\u017eu'), + (2276, u'Kog'), + (2277, u'Sredi\u0161\u010de ob Dravi'), + (2281, u'Markovci'), + (2282, u'Cirkulane'), + (2283, u'Zavr\u010d'), + (2284, u'Videm pri Ptuju'), + (2285, u'Zgornji Leskovec'), + (2286, u'Podlehnik'), + (2287, u'\u017detale'), + (2288, u'Hajdina'), + (2289, u'Stoperce'), + (2310, u'Slovenska Bistrica'), + (2311, u'Ho\u010de'), + (2312, u'Orehova vas'), + (2313, u'Fram'), + (2314, u'Zgornja Polskava'), + (2315, u'\u0160martno na Pohorju'), + (2316, u'Zgornja Lo\u017enica'), + (2317, u'Oplotnica'), + (2318, u'Laporje'), + (2319, u'Polj\u010dane'), + (2321, u'Makole'), + (2322, u'Maj\u0161perk'), + (2323, u'Ptujska Gora'), + (2324, u'Lovrenc na Dravskem polju'), + (2325, u'Kidri\u010devo'), + (2326, u'Cirkovce'), + (2327, u'Ra\u010de'), + (2331, u'Pragersko'), + (2341, u'Limbu\u0161'), + (2342, u'Ru\u0161e'), + (2343, u'Fala'), + (2344, u'Lovrenc na Pohorju'), + (2345, u'Bistrica ob Dravi'), + (2351, u'Kamnica'), + (2352, u'Selnica ob Dravi'), + (2353, u'Sv. Duh na Ostrem Vrhu'), + (2354, u'Bresternica'), + (2360, u'Radlje ob Dravi'), + (2361, u'O\u017ebalt'), + (2362, u'Kapla'), + (2363, u'Podvelka'), + (2364, u'Ribnica na Pohorju'), + (2365, u'Vuhred'), + (2366, u'Muta'), + (2367, u'Vuzenica'), + (2370, u'Dravograd'), + (2371, u'Trbonje'), + (2372, u'Libeli\u010de'), + (2373, u'\u0160entjan\u017e pri Dravogradu'), + (2380, u'Slovenj Gradec'), + (2381, u'Podgorje pri Slovenj Gradcu'), + (2382, u'Mislinja'), + (2383, u'\u0160martno pri Slovenj Gradcu'), + (2390, u'Ravne na Koro\u0161kem'), + (2391, u'Prevalje'), + (2392, u'Me\u017eica'), + (2393, u'\u010crna na Koro\u0161kem'), + (2394, u'Kotlje'), + (3000, u'Celje'), + (3201, u'\u0160martno v Ro\u017eni dolini'), + (3202, u'Ljube\u010dna'), + (3203, u'Nova Cerkev'), + (3204, u'Dobrna'), + (3205, u'Vitanje'), + (3206, u'Stranice'), + (3210, u'Slovenske Konjice'), + (3211, u'\u0160kofja vas'), + (3212, u'Vojnik'), + (3213, u'Frankolovo'), + (3214, u'Zre\u010de'), + (3215, u'Lo\u010de'), + (3220, u'\u0160tore'), + (3221, u'Teharje'), + (3222, u'Dramlje'), + (3223, u'Loka pri \u017dusmu'), + (3224, u'Dobje pri Planini'), + (3225, u'Planina pri Sevnici'), + (3230, u'\u0160entjur'), + (3231, u'Grobelno'), + (3232, u'Ponikva'), + (3233, u'Kalobje'), + (3240, u'\u0160marje pri Jel\u0161ah'), + (3241, u'Podplat'), + (3250, u'Roga\u0161ka Slatina'), + (3252, u'Rogatec'), + (3253, u'Pristava pri Mestinju'), + (3254, u'Pod\u010detrtek'), + (3255, u'Bu\u010de'), + (3256, u'Bistrica ob Sotli'), + (3257, u'Podsreda'), + (3260, u'Kozje'), + (3261, u'Lesi\u010dno'), + (3262, u'Prevorje'), + (3263, u'Gorica pri Slivnici'), + (3264, u'Sveti \u0160tefan'), + (3270, u'La\u0161ko'), + (3271, u'\u0160entrupert'), + (3272, u'Rimske Toplice'), + (3273, u'Jurklo\u0161ter'), + (3301, u'Petrov\u010de'), + (3302, u'Gri\u017ee'), + (3303, u'Gomilsko'), + (3304, u'Tabor'), + (3305, u'Vransko'), + (3310, u'\u017dalec'), + (3311, u'\u0160empeter v Savinjski dolini'), + (3312, u'Prebold'), + (3313, u'Polzela'), + (3314, u'Braslov\u010de'), + (3320, u'Velenje - dostava'), + (3322, u'Velenje - po\u0161tni predali'), + (3325, u'\u0160o\u0161tanj'), + (3326, u'Topol\u0161ica'), + (3327, u'\u0160martno ob Paki'), + (3330, u'Mozirje'), + (3331, u'Nazarje'), + (3332, u'Re\u010dica ob Savinji'), + (3333, u'Ljubno ob Savinji'), + (3334, u'Lu\u010de'), + (3335, u'Sol\u010dava'), + (3341, u'\u0160martno ob Dreti'), + (3342, u'Gornji Grad'), + (4000, u'Kranj'), + (4201, u'Zgornja Besnica'), + (4202, u'Naklo'), + (4203, u'Duplje'), + (4204, u'Golnik'), + (4205, u'Preddvor'), + (4206, u'Zgornje Jezersko'), + (4207, u'Cerklje na Gorenjskem'), + (4208, u'\u0160en\u010dur'), + (4209, u'\u017dabnica'), + (4210, u'Brnik - aerodrom'), + (4211, u'Mav\u010di\u010de'), + (4212, u'Visoko'), + (4220, u'\u0160kofja Loka'), + (4223, u'Poljane nad \u0160kofjo Loko'), + (4224, u'Gorenja vas'), + (4225, u'Sovodenj'), + (4226, u'\u017diri'), + (4227, u'Selca'), + (4228, u'\u017delezniki'), + (4229, u'Sorica'), + (4240, u'Radovljica'), + (4243, u'Brezje'), + (4244, u'Podnart'), + (4245, u'Kropa'), + (4246, u'Kamna Gorica'), + (4247, u'Zgornje Gorje'), + (4248, u'Lesce'), + (4260, u'Bled'), + (4263, u'Bohinjska Bela'), + (4264, u'Bohinjska Bistrica'), + (4265, u'Bohinjsko jezero'), + (4267, u'Srednja vas v Bohinju'), + (4270, u'Jesenice'), + (4273, u'Blejska Dobrava'), + (4274, u'\u017dirovnica'), + (4275, u'Begunje na Gorenjskem'), + (4276, u'Hru\u0161ica'), + (4280, u'Kranjska Gora'), + (4281, u'Mojstrana'), + (4282, u'Gozd Martuljek'), + (4283, u'Rate\u010de - Planica'), + (4290, u'Tr\u017ei\u010d'), + (4294, u'Kri\u017ee'), + (5000, u'Nova Gorica'), + (5210, u'Deskle'), + (5211, u'Kojsko'), + (5212, u'Dobrovo v Brdih'), + (5213, u'Kanal'), + (5214, u'Kal nad Kanalom'), + (5215, u'Ro\u010dinj'), + (5216, u'Most na So\u010di'), + (5220, u'Tolmin'), + (5222, u'Kobarid'), + (5223, u'Breginj'), + (5224, u'Srpenica'), + (5230, u'Bovec'), + (5231, u'Log pod Mangartom'), + (5232, u'So\u010da'), + (5242, u'Grahovo ob Ba\u010di'), + (5243, u'Podbrdo'), + (5250, u'Solkan'), + (5251, u'Grgar'), + (5252, u'Trnovo pri Gorici'), + (5253, u'\u010cepovan'), + (5261, u'\u0160empas'), + (5262, u'\u010crni\u010de'), + (5263, u'Dobravlje'), + (5270, u'Ajdov\u0161\u010dina'), + (5271, u'Vipava'), + (5272, u'Podnanos'), + (5273, u'Col'), + (5274, u'\u010crni Vrh nad Idrijo'), + (5275, u'Godovi\u010d'), + (5280, u'Idrija'), + (5281, u'Spodnja Idrija'), + (5282, u'Cerkno'), + (5283, u'Slap ob Idrijci'), + (5290, u'\u0160empeter pri Gorici'), + (5291, u'Miren'), + (5292, u'Ren\u010de'), + (5293, u'Vol\u010dja Draga'), + (5294, u'Dornberk'), + (5295, u'Branik'), + (5296, u'Kostanjevica na Krasu'), + (5297, u'Prva\u010dina'), + (6000, u'Koper'), + (6210, u'Se\u017eana'), + (6215, u'Diva\u010da'), + (6216, u'Podgorje'), + (6217, u'Vremski Britof'), + (6219, u'Lokev'), + (6221, u'Dutovlje'), + (6222, u'\u0160tanjel'), + (6223, u'Komen'), + (6224, u'Seno\u017ee\u010de'), + (6225, u'Hru\u0161evje'), + (6230, u'Postojna'), + (6232, u'Planina'), + (6240, u'Kozina'), + (6242, u'Materija'), + (6243, u'Obrov'), + (6244, u'Podgrad'), + (6250, u'Ilirska Bistrica'), + (6251, u'Ilirska Bistrica - Trnovo'), + (6253, u'Kne\u017eak'), + (6254, u'Jel\u0161ane'), + (6255, u'Prem'), + (6256, u'Ko\u0161ana'), + (6257, u'Pivka'), + (6258, u'Prestranek'), + (6271, u'Dekani'), + (6272, u'Gra\u010di\u0161\u010de'), + (6273, u'Marezige'), + (6274, u'\u0160marje'), + (6275, u'\u010crni Kal'), + (6276, u'Pobegi'), + (6280, u'Ankaran - Ancarano'), + (6281, u'\u0160kofije'), + (6310, u'Izola - Isola'), + (6320, u'Portoro\u017e - Portorose'), + (6330, u'Piran - Pirano'), + (6333, u'Se\u010dovlje - Sicciole'), + (8000, u'Novo mesto'), + (8210, u'Trebnje'), + (8211, u'Dobrni\u010d'), + (8212, u'Velika Loka'), + (8213, u'Veliki Gaber'), + (8216, u'Mirna Pe\u010d'), + (8220, u'\u0160marje\u0161ke Toplice'), + (8222, u'Oto\u010dec'), + (8230, u'Mokronog'), + (8231, u'Trebelno'), + (8232, u'\u0160entrupert'), + (8233, u'Mirna'), + (8250, u'Bre\u017eice'), + (8251, u'\u010cate\u017e ob Savi'), + (8253, u'Arti\u010de'), + (8254, u'Globoko'), + (8255, u'Pi\u0161ece'), + (8256, u'Sromlje'), + (8257, u'Dobova'), + (8258, u'Kapele'), + (8259, u'Bizeljsko'), + (8261, u'Jesenice na Dolenjskem'), + (8262, u'Kr\u0161ka vas'), + (8263, u'Cerklje ob Krki'), + (8270, u'Kr\u0161ko'), + (8272, u'Zdole'), + (8273, u'Leskovec pri Kr\u0161kem'), + (8274, u'Raka'), + (8275, u'\u0160kocjan'), + (8276, u'Bu\u010dka'), + (8280, u'Brestanica'), + (8281, u'Senovo'), + (8282, u'Koprivnica'), + (8283, u'Blanca'), + (8290, u'Sevnica'), + (8292, u'Zabukovje'), + (8293, u'Studenec'), + (8294, u'Bo\u0161tanj'), + (8295, u'Tr\u017ei\u0161\u010de'), + (8296, u'Krmelj'), + (8297, u'\u0160entjan\u017e'), + (8310, u'\u0160entjernej'), + (8311, u'Kostanjevica na Krki'), + (8312, u'Podbo\u010dje'), + (8321, u'Brusnice'), + (8322, u'Stopi\u010de'), + (8323, u'Ur\u0161na sela'), + (8330, u'Metlika'), + (8331, u'Suhor'), + (8332, u'Gradac'), + (8333, u'Semi\u010d'), + (8340, u'\u010crnomelj'), + (8341, u'Adle\u0161i\u010di'), + (8342, u'Stari trg ob Kolpi'), + (8343, u'Dragatu\u0161'), + (8344, u'Vinica pri \u010crnomlju'), + (8350, u'Dolenjske Toplice'), + (8351, u'Stra\u017ea'), + (8360, u'\u017du\u017eemberk'), + (8361, u'Dvor'), + (8362, u'Hinje'), + (9000, u'Murska Sobota'), + (9201, u'Puconci'), + (9202, u'Ma\u010dkovci'), + (9203, u'Petrovci'), + (9204, u'\u0160alovci'), + (9205, u'Hodo\u0161 - Hodos'), + (9206, u'Kri\u017eevci'), + (9207, u'Prosenjakovci - Partosfalva'), + (9208, u'Fokovci'), + (9220, u'Lendava - Lendva'), + (9221, u'Martjanci'), + (9222, u'Bogojina'), + (9223, u'Dobrovnik - Dobronak'), + (9224, u'Turni\u0161\u010de'), + (9225, u'Velika Polana'), + (9226, u'Moravske Toplice'), + (9227, u'Kobilje'), + (9231, u'Beltinci'), + (9232, u'\u010cren\u0161ovci'), + (9233, u'Odranci'), + (9240, u'Ljutomer'), + (9241, u'Ver\u017eej'), + (9242, u'Kri\u017eevci pri Ljutomeru'), + (9243, u'Mala Nedelja'), + (9244, u'Sveti Jurij ob \u0160\u010davnici'), + (9245, u'Spodnji Ivanjci'), + (9250, u'Gornja Radgona'), + (9251, u'Ti\u0161ina'), + (9252, u'Radenci'), + (9253, u'Apa\u010de'), + (9261, u'Cankova'), + (9262, u'Roga\u0161ovci'), + (9263, u'Kuzma'), + (9264, u'Grad'), + (9265, u'Bodonci')] + +SI_POSTALCODES_CHOICES = sorted(SI_POSTALCODES, key=lambda k: k[1]) diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt index 0f99f35b4d..fbb10a6a35 100644 --- a/docs/ref/contrib/localflavor.txt +++ b/docs/ref/contrib/localflavor.txt @@ -70,6 +70,7 @@ Countries currently supported by :mod:`~django.contrib.localflavor` are: * Romania_ * Russia_ * Slovakia_ + * Slovenia_ * `South Africa`_ * Spain_ * Sweden_ @@ -126,6 +127,7 @@ Here's an example of how to use them:: .. _Romania: `Romania (ro)`_ .. _Russia: `Russia (ru)`_ .. _Slovakia: `Slovakia (sk)`_ +.. _Slovenia: `Slovenia (si)`_ .. _South Africa: `South Africa (za)`_ .. _Spain: `Spain (es)`_ .. _Sweden: `Sweden (se)`_ @@ -1068,6 +1070,35 @@ Slovakia (``sk``) A ``Select`` widget that uses a list of Slovak regions as its choices. +Slovenia (``si``) +================= + +.. class:: si.forms.SIEMSOField + + A form field that validates input as Slovenian personal identification + number and stores gender and birthday to self.info dictionary. + +.. class:: si.forms.SITaxNumberField + + A form field that validates input as a Slovenian tax number. Valid input + is SIXXXXXXXX or XXXXXXXX. + +.. class:: si.forms.SIPhoneNumberField + + A form field that validates input as a Slovenian phone number. Phone + number must contain at least local area code with optional country code. + +.. class:: si.forms.SIPostalCodeField + + A form field that provides a choice field of major Slovenian postal + codes. + +.. class:: si.forms.SIPostalCodeSelect + + A ``Select`` widget that uses a list of major Slovenian postal codes as + its choices. + + South Africa (``za``) ===================== diff --git a/tests/regressiontests/localflavor/si/__init__.py b/tests/regressiontests/localflavor/si/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/localflavor/si/tests.py b/tests/regressiontests/localflavor/si/tests.py new file mode 100644 index 0000000000..b5c86cdd3c --- /dev/null +++ b/tests/regressiontests/localflavor/si/tests.py @@ -0,0 +1,556 @@ +# -*- coding: utf-8 -*- + +from datetime import date + +from django.contrib.localflavor.si.forms import (SIEMSOField, SITaxNumberField, + SIPhoneNumberField, SIPostalCodeField, SIPostalCodeSelect) +from django.test import SimpleTestCase + + +class SILocalFlavorTests(SimpleTestCase): + def test_SITaxNumberField(self): + error_invalid = [u'Enter a valid tax number in form SIXXXXXXXX'] + valid = { + '15012557': '15012557', + 'SI15012557': '15012557', + '22111310': '22111310', + } + invalid = { + '22241310': error_invalid, + '15012558': error_invalid, + '1501': error_invalid, + '1501123123123': error_invalid, + 'abcdabcd': error_invalid, + '01234579': error_invalid, + } + self.assertFieldOutput(SITaxNumberField, valid, invalid) + + def test_SIEMSOField(self): + error_invalid = [u'This field should contain exactly 13 digits.'] + error_invalid_date = [u'The first 7 digits of the EMSO must represent a valid past date.'] + error_invalid_chksum = [u'The EMSO is not valid.'] + valid = { + '0205951500462': '0205951500462', + '2309002500068': '2309002500068', + '1010985500400': '1010985500400', + } + invalid = { + '0205951500463': error_invalid_chksum, + '020': error_invalid, + '020020595150046020595150046': error_invalid, + 'aaaabbbbccccd': error_invalid, + '1010985500800': error_invalid_chksum, + '2020095500070': error_invalid_date, + '5050095500078': error_invalid_date, + '1010889500408': error_invalid_date, + } + self.assertFieldOutput(SIEMSOField, valid, invalid) + + def test_SIEMSOField_info_dict(self): + valid = { + '0205951500462': {'nationality': 50, 'gender': 'male', 'birthdate': date(1951, 5, 2)}, + '2309002504063': {'nationality': 50, 'gender': 'male', 'birthdate': date(2002, 9, 23)}, + '1010985505402': {'nationality': 50, 'gender': 'female', 'birthdate': date(1985, 10, 10)}, + } + for input, info in valid.items(): + f = SIEMSOField() + f.clean(input) + self.assertEqual(f.info, info) + + def test_SIPhoneNumberField(self): + error_invalid = [u'Enter phone number in form +386XXXXXXXX or 0XXXXXXXX.'] + valid = { + '+38640999999': '40999999', + '+3861999999': '1999999', + '0038640999999': '40999999', + '040999999': '40999999', + '01999999': '1999999', + '059099999': '59099999', + '059 09 99 99': '59099999', + '0590/999-99': '59099999', + } + invalid = { + '03861999999': error_invalid, + '3861999999': error_invalid, + } + self.assertFieldOutput(SIPhoneNumberField, valid, invalid) + + def test_SIPostalCodeField(self): + valid = { + '4000': '4000', + '1000': '1000' + } + invalid = { + '1113': [u'Select a valid choice. 1113 is not one of the available choices.'], + '111': [u'Select a valid choice. 111 is not one of the available choices.'], + } + self.assertFieldOutput(SIPostalCodeField, valid, invalid) + + def test_SIPostalCodeSelect(self): + f = SIPostalCodeSelect() + out = u'''''' + self.assertEqual(f.render('Kranj', '4000'), out) diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py index 155f7f759f..12c052bf2a 100644 --- a/tests/regressiontests/localflavor/tests.py +++ b/tests/regressiontests/localflavor/tests.py @@ -34,6 +34,7 @@ from py.tests import * from ro.tests import * from ru.tests import * from se.tests import * +from si.tests import * from sk.tests import * from tr.tests import * from us.tests import *