Code

Ticket #3866: it_localflavor.diff

File it_localflavor.diff, 5.3 KB (added by flavio.curella@…, 7 years ago)

localflavor for Italy

Line 
1Index: django/contrib/localflavor/it/__init__.py
2===================================================================
3Index: django/contrib/localflavor/it/it_region.py
4===================================================================
5--- django/contrib/localflavor/it/it_region.py  (revision 0)
6+++ django/contrib/localflavor/it/it_region.py  (revision 0)
7@@ -0,0 +1,24 @@
8+# -*- coding: utf-8 -*
9+
10+REGION_CHOICES = (
11+    ('ABR', 'Abruzzo'),
12+    ('BAS', 'Basilicata'),
13+    ('CAL', 'Calabria'),
14+    ('CAM', 'Campania'),
15+    ('EMR', 'Emilia-Romagna'),
16+    ('FVG', 'Friuli-Venezia Giulia'),
17+    ('LAZ', 'Lazio'),
18+    ('LIG', 'Liguria'),
19+    ('LOM', 'Lombardia'),
20+    ('MAR', 'Marche'),
21+    ('MOL', 'Molise'),
22+    ('PMN', 'Piemonte'),
23+    ('PUG', 'Puglia'),
24+    ('SAR', 'Sardegna'),
25+    ('SIC', 'Sicilia'),
26+    ('TOS', 'Toscana'),
27+    ('TAA', 'Trentino-Alto Adige'),
28+    ('UMB', 'Umbria'),
29+    ('VAO', 'Valle d’Aosta'),
30+    ('VEN', 'Veneto'),
31+)
32Index: django/contrib/localflavor/it/it_province.py
33===================================================================
34--- django/contrib/localflavor/it/it_province.py        (revision 0)
35+++ django/contrib/localflavor/it/it_province.py        (revision 0)
36@@ -0,0 +1,114 @@
37+# -*- coding: utf-8 -*
38+
39+PROVINCE_CHOICES = (
40+    ('AG', 'Agrigento'),
41+    ('AL', 'Alessandria'),
42+    ('AN', 'Ancona'),
43+    ('AO', 'Aosta'),
44+    ('AR', 'Arezzo'),
45+    ('AP', 'Ascoli Piceno'),
46+    ('AT', 'Asti'),
47+    ('AV', 'Avellino'),
48+    ('BA', 'Bari'),
49+#    ('BT', 'Barletta-Andria-Trani'), # active starting from 2009
50+    ('BL', 'Belluno'),
51+    ('BN', 'Benevento'),
52+    ('BG', 'Bergamo'),
53+    ('BI', 'Biella'),
54+    ('BO', 'Bologna'),
55+    ('BZ', 'Bolzano/Bozen'),
56+    ('BS', 'Brescia'),
57+    ('BR', 'Brindisi'),
58+    ('CA', 'Cagliari'),
59+    ('CL', 'Caltanissetta'),
60+    ('CB', 'Campobasso'),
61+    ('CI', 'Carbonia-Iglesias'),
62+    ('CE', 'Caserta'),
63+    ('CT', 'Catania'),
64+    ('CZ', 'Catanzaro'),
65+    ('CH', 'Chieti'),
66+    ('CO', 'Como'),
67+    ('CS', 'Cosenza'),
68+    ('CR', 'Cremona'),
69+    ('KR', 'Crotone'),
70+    ('CN', 'Cuneo'),
71+    ('EN', 'Enna'),
72+#    ('FM', 'Fermo'), # active starting from 2009   
73+    ('FE', 'Ferrara'),
74+    ('FI', 'Firenze'),
75+    ('FG', 'Foggia'),
76+    ('FC', 'Forlì-Cesena'),
77+    ('FR', 'Frosinone'),
78+    ('GE', 'Genova'),
79+    ('GO', 'Gorizia'),
80+    ('GR', 'Grosseto'),
81+    ('IM', 'Imperia'),
82+    ('IS', 'Isernia'),
83+    ('SP', 'La Spezia'),
84+    ('AQ', 'L’Acquila'),
85+    ('LT', 'Latina'),
86+    ('LE', 'Lecce'),
87+    ('LC', 'Lecco'),
88+    ('LI', 'Livorno'),
89+    ('LO', 'Lodi'),
90+    ('LU', 'Lucca'),
91+    ('MC', 'Macerata'),
92+    ('MN', 'Mantova'),
93+    ('MS', 'Massa-Carrara'),
94+    ('MT', 'Matera'),
95+    ('VS', 'Medio Campidano'),
96+    ('ME', 'Messina'),
97+    ('MI', 'Milano'),
98+    ('MO', 'Modena'),
99+#    ('MB', 'Monza e Brianza'), # active starting from 2009
100+    ('NA', 'Napoli'),
101+    ('NO', 'Novara'),
102+    ('NU', 'Nuoro'),
103+    ('OG', 'Ogliastra'),
104+    ('OT', 'Olbia-Tempio'),
105+    ('OR', 'Oristano'),
106+    ('PD', 'Padova'),
107+    ('PA', 'Palermo'),
108+    ('PR', 'Parma'),
109+    ('PV', 'Pavia'),
110+    ('PG', 'Perugia'),
111+    ('PU', 'Pesaro e Urbino'),
112+    ('PE', 'Pescara'),
113+    ('PC', 'Piacenza'),
114+    ('PI', 'Pisa'),
115+    ('PT', 'Pistoia'),
116+    ('PN', 'Pordenone'),
117+    ('PZ', 'Potenza'),
118+    ('PO', 'Prato'),
119+    ('RG', 'Ragusa'),
120+    ('RA', 'Ravenna'),
121+    ('RC', 'Reggio Calabria'),
122+    ('RE', 'Reggio Emilia'),
123+    ('RI', 'Rieti'),
124+    ('RN', 'Rimini')
125+    ('RM', 'Roma'),
126+    ('RO', 'Rovigo'),
127+    ('SA', 'Salerno'),
128+    ('SS', 'Sassari'),
129+    ('SV', 'Savona'),
130+    ('SI', 'Siena'),
131+    ('SR', 'Siracusa'),
132+    ('SO', 'Sondrio'),
133+    ('TA', 'Taranto'),
134+    ('TE', 'Teramo'),
135+    ('TR', 'Terni'),
136+    ('TO', 'Torino'),
137+    ('TP', 'Trapani'),
138+    ('TN', 'Trento'),
139+    ('TV', 'Treviso'),
140+    ('TS', 'Trieste'),
141+    ('UD', 'Udine'),
142+    ('VA', 'Varese'),
143+    ('VE', 'Venezia'),
144+    ('VB', 'Verbano Cusio Ossola'),
145+    ('VC', 'Vercelli'),
146+    ('VR', 'Verona'),
147+    ('VV', 'Vibo Valentia'),
148+    ('VI', 'Vicenza'),
149+    ('VT', 'Viterbo'),
150+)
151Index: django/contrib/localflavor/it/forms.py
152===================================================================
153--- django/contrib/localflavor/it/forms.py      (revision 0)
154+++ django/contrib/localflavor/it/forms.py      (revision 0)
155@@ -0,0 +1,32 @@
156+"""
157+IT-specific Form helpers
158+"""
159+
160+from django.newforms import ValidationError
161+from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
162+from django.newforms.util import smart_unicode
163+from django.utils.translation import gettext
164+import re
165+
166+class ITZipCodeField(RegexField):
167+    def __init__(self, *args, **kwargs):
168+        super(ITZipCodeField, self).__init__(r'^\d{5}$',
169+        max_length=None, min_length=None,
170+        error_message=gettext(u'Enter a zip code in the format XXXXX.'),
171+        *args, **kwargs)
172+
173+class ITRegionSelect(Select):
174+    """
175+    A Select widget that uses a list of IT regions as its choices.
176+    """
177+    def __init__(self, attrs=None):
178+        from it_region import REGION_CHOICES # relative import
179+        super(ITRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
180+
181+class ITProvinceSelect(Select):
182+    """
183+    A Select widget that uses a list of IT regions as its choices.
184+    """
185+    def __init__(self, attrs=None):
186+        from it_province import PROVINCE_CHOICES # relative import
187+        super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)