From f3e71048c3e6b3c932586e3ec45a55986f90f63c Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 12 Jul 2007 12:44:05 +0000 Subject: [PATCH] Fixed #4808 -- Added Chilean regions in localflavor. Thanks, Marijn Vriens . git-svn-id: http://code.djangoproject.com/svn/django/trunk@5663 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 2 +- django/contrib/localflavor/cl/cl_regions.py | 25 +++++++++++++++++++++ django/contrib/localflavor/cl/forms.py | 12 +++++++++- tests/regressiontests/forms/localflavor.py | 8 +++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 django/contrib/localflavor/cl/cl_regions.py diff --git a/AUTHORS b/AUTHORS index fd8c87e387..b32fe163bc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -175,7 +175,7 @@ answer newbie questions, and generally made Django that much better: Manuzhai Petar Marić Nuno Mariz - marijn@metronomo.cl + Marijn Vriens mark@junklight.com Yasushi Masuda mattycakes@gmail.com diff --git a/django/contrib/localflavor/cl/cl_regions.py b/django/contrib/localflavor/cl/cl_regions.py new file mode 100644 index 0000000000..47db6d3912 --- /dev/null +++ b/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'), +) diff --git a/django/contrib/localflavor/cl/forms.py b/django/contrib/localflavor/cl/forms.py index a737bcb5a7..d2d37a3712 100644 --- a/django/contrib/localflavor/cl/forms.py +++ b/django/contrib/localflavor/cl/forms.py @@ -3,10 +3,20 @@ Chile specific form helpers. """ 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 diff --git a/tests/regressiontests/forms/localflavor.py b/tests/regressiontests/forms/localflavor.py index 252aa10b34..b52759a6e1 100644 --- a/tests/regressiontests/forms/localflavor.py +++ b/tests/regressiontests/forms/localflavor.py @@ -1356,4 +1356,12 @@ Traceback (most recent call last): ... 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'' + """ +