Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8013 -- Added Columbian and Ecuadorian local flavor. Thanks, i…

…kks and Bernhard Essl.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16570 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4a6e1b56135b1a413576ea1a6d469387a1a5eb6d 1 parent 2ccfb6d
Jannis Leidel authored July 29, 2011
44  django/contrib/localflavor/co/co_departments.py
... ...
@@ -0,0 +1,44 @@
  1
+# -*- coding: utf-8 -*-
  2
+"""
  3
+A list of Colombian departaments as `choices` in a
  4
+formfield.
  5
+
  6
+This exists in this standalone file so that it's only
  7
+imported into memory when explicitly needed.
  8
+"""
  9
+
  10
+DEPARTMENT_CHOICES = (
  11
+    ('AMA', u'Amazonas'),
  12
+    ('ANT', u'Antioquia'),
  13
+    ('ARA', u'Arauca'),
  14
+    ('ATL', u'Atlántico'),
  15
+    ('DC',  u'Bogotá'),
  16
+    ('BOL', u'Bolívar'),
  17
+    ('BOY', u'Boyacá'),
  18
+    ('CAL', u'Caldas'),
  19
+    ('CAQ', u'Caquetá'),
  20
+    ('CAS', u'Casanare'),
  21
+    ('CAU', u'Cauca'),
  22
+    ('CES', u'Cesar'),
  23
+    ('CHO', u'Chocó'),
  24
+    ('COR', u'Córdoba'),
  25
+    ('CUN', u'Cundinamarca'),
  26
+    ('GUA', u'Guainía'),
  27
+    ('GUV', u'Guaviare'),
  28
+    ('HUI', u'Huila'),
  29
+    ('LAG', u'La Guajira'),
  30
+    ('MAG', u'Magdalena'),
  31
+    ('MET', u'Meta'),
  32
+    ('NAR', u'Nariño'),
  33
+    ('NSA', u'Norte de Santander'),
  34
+    ('PUT', u'Putumayo'),
  35
+    ('QUI', u'Quindío'),
  36
+    ('RIS', u'Risaralda'),
  37
+    ('SAP', u'San Andrés and Providencia'),
  38
+    ('SAN', u'Santander'),
  39
+    ('SUC', u'Sucre'),
  40
+    ('TOL', u'Tolima'),
  41
+    ('VAC', u'Valle del Cauca'),
  42
+    ('VAU', u'Vaupés'),
  43
+    ('VID', u'Vichada'),
  44
+)
13  django/contrib/localflavor/co/forms.py
... ...
@@ -0,0 +1,13 @@
  1
+"""
  2
+Colombian-specific form helpers.
  3
+"""
  4
+
  5
+from django.forms.fields import Select
  6
+
  7
+class CODepartmentSelect(Select):
  8
+    """
  9
+    A Select widget that uses a list of Colombian states as its choices.
  10
+    """
  11
+    def __init__(self, attrs=None):
  12
+        from co_departments import DEPARTMENT_CHOICES
  13
+        super(CODepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES)
35  django/contrib/localflavor/ec/ec_provinces.py
... ...
@@ -0,0 +1,35 @@
  1
+# -*- coding: utf-8 -*-
  2
+"""
  3
+A list of Ecuador departaments as `choices` in a
  4
+formfield.
  5
+
  6
+This exists in this standalone file so that it's only
  7
+imported into memory when explicitly needed.
  8
+"""
  9
+
  10
+PROVINCE_CHOICES = (
  11
+    ('A', u'Azuay'),
  12
+    ('B', u'Bolívar'),
  13
+    ('F', u'Cañar'),
  14
+    ('C', u'Carchi'),
  15
+    ('H', u'Chimborazo'),
  16
+    ('X', u'Cotopaxi'),
  17
+    ('O', u'El Oro'),
  18
+    ('E', u'Esmeraldas'),
  19
+    ('W', u'Galápagos'),
  20
+    ('G', u'Guayas'),
  21
+    ('I', u'Imbabura'),
  22
+    ('L', u'Loja'),
  23
+    ('R', u'Los Ríos'),
  24
+    ('M', u'Manabí'),
  25
+    ('S', u'Morona Santiago'),
  26
+    ('N', u'Napo'),
  27
+    ('D', u'Orellana'),
  28
+    ('Y', u'Pastaza'),
  29
+    ('P', u'Pichincha'),
  30
+    ('SE', u'Santa Elena'),
  31
+    ('SD', u'Santo Domingo de los Tsáchilas'),
  32
+    ('U', u'Sucumbíos'),
  33
+    ('T', u'Tungurahua'),
  34
+    ('Z', u'Zamora Chinchipe'),
  35
+)
13  django/contrib/localflavor/ec/forms.py
... ...
@@ -0,0 +1,13 @@
  1
+"""
  2
+Ecuador-specific form helpers.
  3
+"""
  4
+
  5
+from django.forms.fields import Select
  6
+
  7
+class ECProvinceSelect(Select):
  8
+    """
  9
+    A Select widget that uses a list of Ecuador provinces as its choices.
  10
+    """
  11
+    def __init__(self, attrs=None):
  12
+        from ec_provinces import PROVINCE_CHOICES
  13
+        super(ECProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
24  docs/ref/contrib/localflavor.txt
@@ -44,8 +44,10 @@ Countries currently supported by :mod:`~django.contrib.localflavor` are:
44 44
     * Canada_
45 45
     * Chile_
46 46
     * China_
  47
+    * Colombia_
47 48
     * Croatia_
48 49
     * Czech_
  50
+    * Ecuador_
49 51
     * Finland_
50 52
     * France_
51 53
     * Germany_
@@ -98,8 +100,10 @@ Here's an example of how to use them::
98 100
 .. _Canada: `Canada (ca)`_
99 101
 .. _Chile: `Chile (cl)`_
100 102
 .. _China: `China (cn)`_
  103
+.. _Colombia: `Colombia (co)`_
101 104
 .. _Croatia: `Croatia (hr)`_
102 105
 .. _Czech: `Czech (cz)`_
  106
+.. _Ecuador: `Ecuador (ec)`_
103 107
 .. _Finland: `Finland (fi)`_
104 108
 .. _France: `France (fr)`_
105 109
 .. _Germany: `Germany (de)`_
@@ -392,6 +396,16 @@ China (``cn``)
392 396
     Valid formats are like 1XXXXXXXXXX, where X is digit.
393 397
     The second digit could only be 3, 5 and 8.
394 398
 
  399
+Colombia (``co``)
  400
+=================
  401
+
  402
+.. versionadded:: 1.4
  403
+
  404
+.. class:: co.forms.CoDepartmentSelect
  405
+
  406
+    A ``Select`` widget that uses a list of Colombian departments
  407
+    as its choices.
  408
+
395 409
 Croatia (``hr``)
396 410
 ================
397 411
 
@@ -479,6 +493,16 @@ Czech (``cz``)
479 493
 
480 494
     A ``Select`` widget that uses a list of Czech regions as its choices.
481 495
 
  496
+Ecuador (``ec``)
  497
+================
  498
+
  499
+.. versionadded:: 1.4
  500
+
  501
+.. class:: ec.forms.EcProvinceSelect
  502
+
  503
+    A ``Select`` widget that uses a list of Ecuatorian provinces as
  504
+    its choices.
  505
+
482 506
 Finland (``fi``)
483 507
 ================
484 508
 
0  localflavor/co/__init__.py b/django/contrib/localflavor/co/__init__.py
No changes.
0  localflavor/ec/__init__.py b/django/contrib/localflavor/ec/__init__.py
No changes.
43  tests/regressiontests/forms/localflavor/co.py
... ...
@@ -0,0 +1,43 @@
  1
+from django.contrib.localflavor.co.forms import CODepartmentSelect
  2
+
  3
+from utils import LocalFlavorTestCase
  4
+
  5
+class COLocalFlavorTests(LocalFlavorTestCase):
  6
+    def test_CODepartmentSelect(self):
  7
+        d = CODepartmentSelect()
  8
+        out = u"""<select name="department">
  9
+<option value="AMA">Amazonas</option>
  10
+<option value="ANT">Antioquia</option>
  11
+<option value="ARA">Arauca</option>
  12
+<option value="ATL">Atl\xe1ntico</option>
  13
+<option value="DC">Bogot\xe1</option>
  14
+<option value="BOL">Bol\xedvar</option>
  15
+<option value="BOY">Boyac\xe1</option>
  16
+<option value="CAL">Caldas</option>
  17
+<option value="CAQ">Caquet\xe1</option>
  18
+<option value="CAS">Casanare</option>
  19
+<option value="CAU">Cauca</option>
  20
+<option value="CES">Cesar</option>
  21
+<option value="CHO">Choc\xf3</option>
  22
+<option value="COR" selected="selected">C\xf3rdoba</option>
  23
+<option value="CUN">Cundinamarca</option>
  24
+<option value="GUA">Guain\xeda</option>
  25
+<option value="GUV">Guaviare</option>
  26
+<option value="HUI">Huila</option>
  27
+<option value="LAG">La Guajira</option>
  28
+<option value="MAG">Magdalena</option>
  29
+<option value="MET">Meta</option>
  30
+<option value="NAR">Nari\xf1o</option>
  31
+<option value="NSA">Norte de Santander</option>
  32
+<option value="PUT">Putumayo</option>
  33
+<option value="QUI">Quind\xedo</option>
  34
+<option value="RIS">Risaralda</option>
  35
+<option value="SAP">San Andr\xe9s and Providencia</option>
  36
+<option value="SAN">Santander</option>
  37
+<option value="SUC">Sucre</option>
  38
+<option value="TOL">Tolima</option>
  39
+<option value="VAC">Valle del Cauca</option>
  40
+<option value="VAU">Vaup\xe9s</option>
  41
+<option value="VID">Vichada</option>
  42
+</select>"""
  43
+        self.assertEqual(d.render('department', 'COR'), out)
34  tests/regressiontests/forms/localflavor/ec.py
... ...
@@ -0,0 +1,34 @@
  1
+from django.contrib.localflavor.ec.forms import ECProvinceSelect
  2
+
  3
+from utils import LocalFlavorTestCase
  4
+
  5
+class ECLocalFlavorTests(LocalFlavorTestCase):
  6
+    def test_ECProvinceSelect(self):
  7
+        p = ECProvinceSelect()
  8
+        out = u"""<select name="province">
  9
+<option value="A">Azuay</option>
  10
+<option value="B">Bol\xedvar</option>
  11
+<option value="F">Ca\xf1ar</option>
  12
+<option value="C">Carchi</option>
  13
+<option value="H">Chimborazo</option>
  14
+<option value="X">Cotopaxi</option>
  15
+<option value="O">El Oro</option>
  16
+<option value="E">Esmeraldas</option>
  17
+<option value="W">Gal\xe1pagos</option>
  18
+<option value="G">Guayas</option>
  19
+<option value="I">Imbabura</option>
  20
+<option value="L">Loja</option>
  21
+<option value="R">Los R\xedos</option>
  22
+<option value="M">Manab\xed</option>
  23
+<option value="S">Morona Santiago</option>
  24
+<option value="N">Napo</option>
  25
+<option value="D">Orellana</option>
  26
+<option value="Y">Pastaza</option>
  27
+<option value="P">Pichincha</option>
  28
+<option value="SE">Santa Elena</option>
  29
+<option value="SD">Santo Domingo de los Ts\xe1chilas</option>
  30
+<option value="U" selected="selected">Sucumb\xedos</option>
  31
+<option value="T">Tungurahua</option>
  32
+<option value="Z">Zamora Chinchipe</option>
  33
+</select>"""
  34
+        self.assertEqual(p.render('province', 'U'), out)
2  tests/regressiontests/forms/localflavortests.py
@@ -9,8 +9,10 @@
9 9
 from localflavor.cl import CLLocalFlavorTests
10 10
 from localflavor.cz import CZLocalFlavorTests
11 11
 from localflavor.cn import CNLocalFlavorTests
  12
+from localflavor.co import COLocalFlavorTests
12 13
 from localflavor.de import DELocalFlavorTests
13 14
 from localflavor.es import ESLocalFlavorTests
  15
+from localflavor.ec import ECLocalFlavorTests
14 16
 from localflavor.fi import FILocalFlavorTests
15 17
 from localflavor.fr import FRLocalFlavorTests
16 18
 from localflavor.gb import GBLocalFlavorTests
2  tests/regressiontests/forms/tests/__init__.py
@@ -21,8 +21,10 @@
21 21
     CHLocalFlavorTests,
22 22
     CLLocalFlavorTests,
23 23
     CNLocalFlavorTests,
  24
+    COLocalFlavorTests,
24 25
     CZLocalFlavorTests,
25 26
     DELocalFlavorTests,
  27
+    ECLocalFlavorTests,
26 28
     ESLocalFlavorTests,
27 29
     FILocalFlavorTests,
28 30
     FRLocalFlavorTests,

0 notes on commit 4a6e1b5

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