Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the Tunisian Local Flavor to Django. #141

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Authors
* Florian Apolloner
* Gary Wilson Jr
* Gerardo Orozco
* Ghassen Telmoudi
* Grzes Furga
* Honza Král
* Horst Gutmann
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 7 additions & 0 deletions docs/localflavor/tn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Tunisia (``tn``)
================

.. automodule:: localflavor.tn.forms
:members:

.. autodata:: localflavor.tn.tn_governorates.GOVERNORATE_CHOICES
Empty file added localflavor/tn/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions localflavor/tn/forms.py
Original file line number Diff line number Diff line change
@@ -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
)
32 changes: 32 additions & 0 deletions localflavor/tn/tn_governorates.py
Original file line number Diff line number Diff line change
@@ -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')),
)
49 changes: 49 additions & 0 deletions tests/test_tn.py
Original file line number Diff line number Diff line change
@@ -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 = '''<select name="governorate">
<option value="ariana">Ariana</option>
<option value="beja">Beja</option>
<option value="ben arous">Ben Arous</option>
<option value="bizert">Bizert</option>
<option value="gabes" selected="selected">Gabes</option>
<option value="gafsa">Gafsa</option>
<option value="jendouba">Jendouba</option>
<option value="kairouan">Kairouan</option>
<option value="kasserine">Kasserine</option>
<option value="kebili">Kebili</option>
<option value="kef">Kef</option>
<option value="mahdia">Mahdia</option>
<option value="manouba">Manouba</option>
<option value="medenine">Medenine</option>
<option value="monastir">Monastir</option>
<option value="nabeul">Nabeul</option>
<option value="sfax">Sfax</option>
<option value="sidi bouzid">Sidi Bouzid</option>
<option value="siliana">Siliana</option>
<option value="sousse">Sousse</option>
<option value="tataouine">Tataouine</option>
<option value="tozeur">Tozeur</option>
<option value="tunis">Tunis</option>
<option value="zaghouan">Zaghouan</option>
</select>'''

self.assertHTMLEqual(
form.render('governorate', 'gabes'),
select_governorate_html
)