Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #4808 -- Added Chilean regions in localflavor. Thanks, Marijn V…

…riens <marijn@metronomo.cl>.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5663 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f3e71048c3e6b3c932586e3ec45a55986f90f63c 1 parent 1655103
@freakboy3742 freakboy3742 authored
View
2  AUTHORS
@@ -175,7 +175,7 @@ answer newbie questions, and generally made Django that much better:
Manuzhai
Petar Marić <http://www.petarmaric.com/>
Nuno Mariz <nmariz@gmail.com>
- marijn@metronomo.cl
+ Marijn Vriens <marijn@metronomo.cl>
mark@junklight.com
Yasushi Masuda <whosaysni@gmail.com>
mattycakes@gmail.com
View
25 django/contrib/localflavor/cl/cl_regions.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+"""
+A list of Chilean regions as `choices` in a formfield.
+
+This exists in this standalone file so that it's only imported into memory
+when explicitly needed.
+"""
+
+REGION_CHOICES = (
+ ('RM', u'Región Metropolitana de Santiago'),
+ ('I', u'Región de Tarapacá'),
+ ('II', u'Región de Antofagasta'),
+ ('III', u'Región de Atacama'),
+ ('IV', u'Región de Coquimbo'),
+ ('V', u'Región de Valparaíso'),
+ ('VI', u'Región del Libertador Bernardo O\'Higgins'),
+ ('VII', u'Región del Maule'),
+ ('VIII',u'Región del Bío Bío'),
+ ('IX', u'Región de la Araucanía'),
+ ('X', u'Región de los Lagos'),
+ ('XI', u'Región de Aysén del General Carlos Ibáñez del Campo'),
+ ('XII', u'Región de Magallanes y la Antártica Chilena'),
+ ('XIV', u'Región de Los Ríos'),
+ ('XV', u'Región de Arica-Parinacota'),
+)
View
12 django/contrib/localflavor/cl/forms.py
@@ -3,10 +3,20 @@
"""
from django.newforms import ValidationError
-from django.newforms.fields import RegexField, EMPTY_VALUES
+from django.newforms.fields import RegexField, Select, EMPTY_VALUES
from django.utils.translation import ugettext
from django.utils.encoding import smart_unicode
+
+class CLRegionSelect(Select):
+ """
+ A Select widget that uses a list of Chilean Regions (Regiones)
+ as its choices.
+ """
+ def __init__(self, attrs=None):
+ from cl_regions import REGION_CHOICES
+ super(CLRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
+
class CLRutField(RegexField):
"""
Chilean "Rol Unico Tributario" (RUT) field. This is the Chilean national
View
8 tests/regressiontests/forms/localflavor.py
@@ -1356,4 +1356,12 @@
...
ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.']
+## CLRegionSelect #########################################################
+>>> from django.contrib.localflavor.cl.forms import CLRegionSelect
+>>> f = CLRegionSelect()
+
+>>> f.render('foo', 'bar')
+u'<select name="foo">\n<option value="RM">Regi\xf3n Metropolitana de Santiago</option>\n<option value="I">Regi\xf3n de Tarapac\xe1</option>\n<option value="II">Regi\xf3n de Antofagasta</option>\n<option value="III">Regi\xf3n de Atacama</option>\n<option value="IV">Regi\xf3n de Coquimbo</option>\n<option value="V">Regi\xf3n de Valpara\xedso</option>\n<option value="VI">Regi\xf3n del Libertador Bernardo O&#39;Higgins</option>\n<option value="VII">Regi\xf3n del Maule</option>\n<option value="VIII">Regi\xf3n del B\xedo B\xedo</option>\n<option value="IX">Regi\xf3n de la Araucan\xeda</option>\n<option value="X">Regi\xf3n de los Lagos</option>\n<option value="XI">Regi\xf3n de Ays\xe9n del General Carlos Ib\xe1\xf1ez del Campo</option>\n<option value="XII">Regi\xf3n de Magallanes y la Ant\xe1rtica Chilena</option>\n<option value="XIV">Regi\xf3n de Los R\xedos</option>\n<option value="XV">Regi\xf3n de Arica-Parinacota</option>\n</select>'
+
"""
+
Please sign in to comment.
Something went wrong with that request. Please try again.