Code

Ticket #12761: paraguayan_local_flavor_2.diff

File paraguayan_local_flavor_2.diff, 6.7 KB (added by BernhardEssl, 3 years ago)
Line 
1Index: docs/ref/contrib/localflavor.txt
2===================================================================
3--- docs/ref/contrib/localflavor.txt    (revision 16452)
4+++ docs/ref/contrib/localflavor.txt    (working copy)
5@@ -784,6 +784,17 @@
6     A ``Select`` widget that uses a list of Norwegian municipalities (fylker) as
7     its choices.
8 
9+Paraguay (``py``)
10+=================
11+
12+.. class:: py.forms.PyDepartmentSelect
13+
14+    A ``Select`` widget with a list of Paraguayan departments as choices.
15+
16+.. class:: py.forms.PyNumeratedDepartmentSelect
17+
18+    A ``Select`` widget with a roman numerated list of Paraguayan departments as choices.
19+
20 Peru (``pe``)
21 =============
22 
23Index: django/contrib/localflavor/py/py_department.py
24===================================================================
25--- django/contrib/localflavor/py/py_department.py      (revision 0)
26+++ django/contrib/localflavor/py/py_department.py      (revision 0)
27@@ -0,0 +1,45 @@
28+# -*- coding: utf-8 -*-
29+
30+# http://www.statoids.com/upy.html
31+
32+DEPARTMENT_CHOICES = (
33+    ('AG', u'Alto Paraguay'),
34+    ('AA', u'Alto Paraná'),
35+    ('AM', u'Amambay'),
36+    ('AS', u'Asunción'),
37+    ('BQ', u'Boquerón'),
38+    ('CG', u'Caaguazú'),
39+    ('CZ', u'Caazapá'),
40+    ('CY', u'Canindeyú'),
41+    ('CE', u'Central'),
42+    ('CN', u'Concepción'),
43+    ('CR', u'Cordillera'),
44+    ('GU', u'Guairá'),
45+    ('IT', u'Itapúa'),
46+    ('MI', u'Misiones'),
47+    ('NE', u'Ñeembucú'),
48+    ('PG', u'Paraguarí'),
49+    ('PH', u'Pdte. Hayes'),
50+    ('SP', u'San Pedro'),
51+)
52+
53+DEPARTMENT_ROMAN_CHOICES = (
54+    ('CN',  u'I    Concepción'),
55+    ('SP',  u'II   San Pedro'),
56+    ('CR',  u'III  Cordillera'),
57+    ('GU',  u'IV   Guairá'),
58+    ('CG',  u'V    Caaguazú'),
59+    ('CZ',  u'VI   Caazapá'),
60+    ('IT',  u'VII  Itapúa'),
61+    ('MI',  u'VIII Misiones'),
62+    ('PG',  u'IX   Paraguarí'),
63+    ('AA',  u'X    Alto Paraná'),
64+    ('CE',  u'XI   Central'),
65+    ('NE',  u'XII  Ñeembucú'),
66+    ('AM',  u'XIII Amambay'),
67+    ('CY',  u'XIV  Canindeyú'),
68+    ('PH',  u'XV   Pdte. Hayes'),
69+    ('AG',  u'XVI  Alto Paraguay'),
70+    ('BQ',  u'XVII Boquerón'),
71+    ('AS',  u'XVIII Asunción'),
72+)
73Index: django/contrib/localflavor/py/__init__.py
74===================================================================
75Index: django/contrib/localflavor/py/forms.py
76===================================================================
77--- django/contrib/localflavor/py/forms.py      (revision 0)
78+++ django/contrib/localflavor/py/forms.py      (revision 0)
79@@ -0,0 +1,24 @@
80+# -*- coding: utf-8 -*-
81+"""
82+PY-specific Form helpers.
83+"""
84+
85+from django.forms import ValidationError
86+from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES
87+
88+class PyDepartmentSelect(Select):
89+    """
90+    A Select widget with a list of Paraguayan departments as choices.
91+    """
92+    def __init__(self, attrs=None):
93+        from py_department import DEPARTMENT_CHOICES
94+        super(PyDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES)
95+
96+
97+class PyNumeratedDepartmentSelect(Select):
98+    """
99+    A Select widget with a roman numerated list of Paraguayan departments as choices.
100+    """
101+    def __init__(self, attrs=None):
102+        from py_department import DEPARTMENT_ROMAN_CHOICES
103+        super(PyNumeratedDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ROMAN_CHOICES)
104Index: tests/regressiontests/forms/tests/__init__.py
105===================================================================
106--- tests/regressiontests/forms/tests/__init__.py       (revision 16452)
107+++ tests/regressiontests/forms/tests/__init__.py       (working copy)
108@@ -40,6 +40,7 @@
109     NLLocalFlavorTests,
110     PLLocalFlavorTests,
111     PTLocalFlavorTests,
112+    PYLocalFlavorTests,
113     ROLocalFlavorTests,
114     RULocalFlavorTests,
115     SELocalFlavorTests,
116Index: tests/regressiontests/forms/localflavor/py.py
117===================================================================
118--- tests/regressiontests/forms/localflavor/py.py       (revision 0)
119+++ tests/regressiontests/forms/localflavor/py.py       (revision 0)
120@@ -0,0 +1,53 @@
121+from django.contrib.localflavor.py.forms import (PyDepartmentSelect,
122+    PyNumeratedDepartmentSelect)
123+
124+from utils import LocalFlavorTestCase
125+
126+class PYLocalFlavorTests(LocalFlavorTestCase):
127+    def test_PyDepartmentSelect(self):
128+        py = PyDepartmentSelect()
129+        out = u'''<select name="department">
130+<option value="AG">Alto Paraguay</option>
131+<option value="AA">Alto Paran\xe1</option>
132+<option value="AM">Amambay</option>
133+<option value="AS">Asunci\xf3n</option>
134+<option value="BQ">Boquer\xf3n</option>
135+<option value="CG">Caaguaz\xfa</option>
136+<option value="CZ">Caazap\xe1</option>
137+<option value="CY">Canindey\xfa</option>
138+<option value="CE">Central</option>
139+<option value="CN">Concepci\xf3n</option>
140+<option value="CR">Cordillera</option>
141+<option value="GU">Guair\xe1</option>
142+<option value="IT">Itap\xfaa</option>
143+<option value="MI">Misiones</option>
144+<option value="NE">\xd1eembuc\xfa</option>
145+<option value="PG">Paraguar\xed</option>
146+<option value="PH">Pdte. Hayes</option>
147+<option value="SP">San Pedro</option>
148+</select>'''
149+        self.assertEqual(py.render('department', 'M'), out)
150+
151+    def test_PyNumeratedDepartmentSelect(self):
152+        py = PyNumeratedDepartmentSelect()
153+        out = u'''<select name="department">
154+<option value="CN">I    Concepci\xf3n</option>
155+<option value="SP">II   San Pedro</option>
156+<option value="CR">III  Cordillera</option>
157+<option value="GU">IV   Guair\xe1</option>
158+<option value="CG">V    Caaguaz\xfa</option>
159+<option value="CZ">VI   Caazap\xe1</option>
160+<option value="IT">VII  Itap\xfaa</option>
161+<option value="MI">VIII Misiones</option>
162+<option value="PG">IX   Paraguar\xed</option>
163+<option value="AA">X    Alto Paran\xe1</option>
164+<option value="CE">XI   Central</option>
165+<option value="NE">XII  \xd1eembuc\xfa</option>
166+<option value="AM" selected="selected">XIII Amambay</option>
167+<option value="CY">XIV  Canindey\xfa</option>
168+<option value="PH">XV   Pdte. Hayes</option>
169+<option value="AG">XVI  Alto Paraguay</option>
170+<option value="BQ">XVII Boquer\xf3n</option>
171+<option value="AS">XVIII Asunci\xf3n</option>
172+</select>'''
173+        self.assertEqual(py.render('department', 'AM'), out)
174Index: tests/regressiontests/forms/localflavortests.py
175===================================================================
176--- tests/regressiontests/forms/localflavortests.py     (revision 16452)
177+++ tests/regressiontests/forms/localflavortests.py     (working copy)
178@@ -27,6 +27,7 @@
179 from localflavor.nl import NLLocalFlavorTests
180 from localflavor.pl import PLLocalFlavorTests
181 from localflavor.pt import PTLocalFlavorTests
182+from localflavor.py import PYLocalFlavorTests
183 from localflavor.ro import ROLocalFlavorTests
184 from localflavor.ru import RULocalFlavorTests
185 from localflavor.se import SELocalFlavorTests