diff --git a/django/contrib/localflavor/py/__init__.py b/django/contrib/localflavor/py/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/django/contrib/localflavor/py/forms.py b/django/contrib/localflavor/py/forms.py new file mode 100644 index 00000000000..85ddffd82f9 --- /dev/null +++ b/django/contrib/localflavor/py/forms.py @@ -0,0 +1,21 @@ +""" +PY-specific Form helpers. +""" +from django.forms.fields import Select + +class PyDepartmentSelect(Select): + """ + A Select widget with a list of Paraguayan departments as choices. + """ + def __init__(self, attrs=None): + from py_department import DEPARTMENT_CHOICES + super(PyDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES) + + +class PyNumberedDepartmentSelect(Select): + """ + A Select widget with a roman numbered list of Paraguayan departments as choices. + """ + def __init__(self, attrs=None): + from py_department import DEPARTMENT_ROMAN_CHOICES + super(PyNumberedDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ROMAN_CHOICES) diff --git a/django/contrib/localflavor/py/py_department.py b/django/contrib/localflavor/py/py_department.py new file mode 100644 index 00000000000..28c613b9a06 --- /dev/null +++ b/django/contrib/localflavor/py/py_department.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# http://www.statoids.com/upy.html + +DEPARTMENT_CHOICES = ( + ('AG', u'Alto Paraguay'), + ('AA', u'Alto Paraná'), + ('AM', u'Amambay'), + ('AS', u'Asunción'), + ('BQ', u'Boquerón'), + ('CG', u'Caaguazú'), + ('CZ', u'Caazapá'), + ('CY', u'Canindeyú'), + ('CE', u'Central'), + ('CN', u'Concepción'), + ('CR', u'Cordillera'), + ('GU', u'Guairá'), + ('IT', u'Itapúa'), + ('MI', u'Misiones'), + ('NE', u'Ñeembucú'), + ('PG', u'Paraguarí'), + ('PH', u'Pdte. Hayes'), + ('SP', u'San Pedro'), +) + +DEPARTMENT_ROMAN_CHOICES = ( + ('CN', u'I Concepción'), + ('SP', u'II San Pedro'), + ('CR', u'III Cordillera'), + ('GU', u'IV Guairá'), + ('CG', u'V Caaguazú'), + ('CZ', u'VI Caazapá'), + ('IT', u'VII Itapúa'), + ('MI', u'VIII Misiones'), + ('PG', u'IX Paraguarí'), + ('AA', u'X Alto Paraná'), + ('CE', u'XI Central'), + ('NE', u'XII Ñeembucú'), + ('AM', u'XIII Amambay'), + ('CY', u'XIV Canindeyú'), + ('PH', u'XV Pdte. Hayes'), + ('AG', u'XVI Alto Paraguay'), + ('BQ', u'XVII Boquerón'), + ('AS', u'XVIII Asunción'), +) diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt index 1e565a58b1a..3ad5899239b 100644 --- a/docs/ref/contrib/localflavor.txt +++ b/docs/ref/contrib/localflavor.txt @@ -64,6 +64,7 @@ Countries currently supported by :mod:`~django.contrib.localflavor` are: * Peru_ * Poland_ * Portugal_ + * Paraguay_ * Romania_ * Russia_ * Slovakia_ @@ -114,6 +115,7 @@ Here's an example of how to use them:: .. _Macedonia: `Macedonia (mk)`_ .. _Mexico: `Mexico (mx)`_ .. _Norway: `Norway (no)`_ +.. _Paraguay: `Paraguay (py)`_ .. _Peru: `Peru (pe)`_ .. _Poland: `Poland (pl)`_ .. _Portugal: `Portugal (pt)`_ @@ -784,6 +786,19 @@ Norway (``no``) A ``Select`` widget that uses a list of Norwegian municipalities (fylker) as its choices. +Paraguay (``py``) +================= + +.. versionadded:: 1.4 + +.. class:: py.forms.PyDepartmentSelect + + A ``Select`` widget with a list of Paraguayan departments as choices. + +.. class:: py.forms.PyNumberedDepartmentSelect + + A ``Select`` widget with a roman numbered list of Paraguayan departments as choices. + Peru (``pe``) ============= diff --git a/tests/regressiontests/forms/localflavor/py.py b/tests/regressiontests/forms/localflavor/py.py new file mode 100644 index 00000000000..4c2acf88873 --- /dev/null +++ b/tests/regressiontests/forms/localflavor/py.py @@ -0,0 +1,53 @@ +from django.contrib.localflavor.py.forms import (PyDepartmentSelect, + PyNumberedDepartmentSelect) + +from utils import LocalFlavorTestCase + +class PYLocalFlavorTests(LocalFlavorTestCase): + def test_PyDepartmentSelect(self): + py = PyDepartmentSelect() + out = u'''''' + self.assertEqual(py.render('department', 'M'), out) + + def test_PyNumberedDepartmentSelect(self): + py = PyNumberedDepartmentSelect() + out = u'''''' + self.assertEqual(py.render('department', 'AM'), out) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 5a28a2b1379..4bd934199e9 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/tests/regressiontests/forms/localflavortests.py @@ -27,6 +27,7 @@ from localflavor.mk import MKLocalFlavorTests from localflavor.nl import NLLocalFlavorTests from localflavor.pl import PLLocalFlavorTests from localflavor.pt import PTLocalFlavorTests +from localflavor.py import PYLocalFlavorTests from localflavor.ro import ROLocalFlavorTests from localflavor.ru import RULocalFlavorTests from localflavor.se import SELocalFlavorTests diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index cb5f83cdaca..46cc5faf47a 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -40,6 +40,7 @@ from regressiontests.forms.localflavortests import ( NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests, + PYLocalFlavorTests, ROLocalFlavorTests, RULocalFlavorTests, SELocalFlavorTests,