diff --git a/.travis.yml b/.travis.yml index d9c539acb..d03f94192 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,7 @@ cache: - $HOME/.wheels install: - mkdir -p $PIP_WHEEL_DIR + - pip install virtualenv==13.1.2 - pip wheel -r tests/requirements.txt codecov - pip install codecov tox script: diff --git a/docs/authors.rst b/docs/authors.rst index 2ec7ef2a0..d87d0805b 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -23,6 +23,7 @@ Authors * Florian Apolloner * Gary Wilson Jr * Gerardo Orozco +* Ghassen Telmoudi * Grzes Furga * Honza Král * Horst Gutmann diff --git a/docs/index.rst b/docs/index.rst index 6a9a84133..ad8617d8c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -72,6 +72,7 @@ validate Finnish social security numbers. * :doc:`localflavor/se` * :doc:`localflavor/si` * :doc:`localflavor/sk` + * :doc:`localflavor/tn` * :doc:`localflavor/tr` * :doc:`localflavor/us` * :doc:`localflavor/uy` diff --git a/docs/localflavor/tn.rst b/docs/localflavor/tn.rst new file mode 100644 index 000000000..93b1b07a3 --- /dev/null +++ b/docs/localflavor/tn.rst @@ -0,0 +1,7 @@ +Tunisia (``tn``) +================ + +.. automodule:: localflavor.tn.forms + :members: + +.. autodata:: localflavor.tn.tn_governorates.GOVERNORATE_CHOICES diff --git a/localflavor/tn/__init__.py b/localflavor/tn/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/localflavor/tn/forms.py b/localflavor/tn/forms.py new file mode 100644 index 000000000..d1bdfc97f --- /dev/null +++ b/localflavor/tn/forms.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +""" +Tunisia-specific Form helpers. +""" +from __future__ import absolute_import, unicode_literals + +from django.forms.fields import Select + +from .tn_governorates import GOVERNORATE_CHOICES + + +class TNGovernorateSelect(Select): + """ + A Select widget that uses a list of the Tunisian governorates as its + choices. + """ + def __init__(self, attrs=None): + super(TNGovernorateSelect, self).__init__( + attrs, choices=GOVERNORATE_CHOICES + ) diff --git a/localflavor/tn/tn_governorates.py b/localflavor/tn/tn_governorates.py new file mode 100644 index 000000000..24b1de961 --- /dev/null +++ b/localflavor/tn/tn_governorates.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from django.utils.translation import ugettext_lazy as _ + + +#: All the 24 Tunisian Governorates +#: http://en.wikipedia.org/wiki/Governorates_of_Tunisia +GOVERNORATE_CHOICES = ( + ('ariana', _('Ariana')), + ('beja', _('Beja')), + ('ben arous', _('Ben Arous')), + ('bizert', _('Bizert')), + ('gabes', _('Gabes')), + ('gafsa', _('Gafsa')), + ('jendouba', _('Jendouba')), + ('kairouan', _('Kairouan')), + ('kasserine', _('Kasserine')), + ('kebili', _('Kebili')), + ('kef', _('Kef')), + ('mahdia', _('Mahdia')), + ('manouba', _('Manouba')), + ('medenine', _('Medenine')), + ('monastir', _('Monastir')), + ('nabeul', _('Nabeul')), + ('sfax', _('Sfax')), + ('sidi bouzid', _('Sidi Bouzid')), + ('siliana', _('Siliana')), + ('sousse', _('Sousse')), + ('tataouine', _('Tataouine')), + ('tozeur', _('Tozeur')), + ('tunis', _('Tunis')), + ('zaghouan', _('Zaghouan')), +) diff --git a/tests/test_tn.py b/tests/test_tn.py new file mode 100644 index 000000000..5c85c7ebc --- /dev/null +++ b/tests/test_tn.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import SimpleTestCase + +from localflavor.tn.forms import TNGovernorateSelect + + +class TNLocalFlavorTests(SimpleTestCase): + """ + Tunisia Local Flavor Tests class. + """ + def test_tn_governorate_select(self): + """ + Tests Select Governorate. + """ + form = TNGovernorateSelect() + + select_governorate_html = '''''' + + self.assertHTMLEqual( + form.render('governorate', 'gabes'), + select_governorate_html + )