Skip to content

Commit

Permalink
Add Hungarian Counties select widget
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaszlo committed Apr 3, 2016
1 parent b0c3873 commit b88be8c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Authors
* Julien Phalip
* Justin Bronn
* Karen Tracey
* László Ratskó
* Luke Benstead
* Malcolm Tredinnick
* Marti Raudsepp
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ New flavors:
(`gh-191 <https://github.com/django/django-localflavor/pull/191>`_)
- Added local flavor for Tunisia
(`gh-141 <https://github.com/django/django-localflavor/pull/141>`_)
- Added local flavor for Hungary
(`gh-213 <https://github.com/django/django-localflavor/pull/213>`_)

New fields for existing flavors:

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ validate Finnish social security numbers.
* :doc:`localflavor/gr`
* :doc:`localflavor/hk`
* :doc:`localflavor/hr`
* :doc:`localflavor/hu`
* :doc:`localflavor/id_`
* :doc:`localflavor/ie_`
* :doc:`localflavor/il`
Expand Down
13 changes: 13 additions & 0 deletions docs/localflavor/hu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hungary (``hu``)
================

Forms
-----

.. automodule:: localflavor.hu.forms
:members:

Data
----

.. autodata:: localflavor.hu.hu_counties.HU_COUNTY_CHOICES
Empty file added localflavor/hu/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions localflavor/hu/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""HU-specific Form helpers"""

from django.forms.fields import Select

from .hu_counties import HU_COUNTY_CHOICES


class HUCountySelect(Select):
"""
A Select widget that uses a list of Hungarian Counties as its choices.
.. versionadded:: 1.3
"""

def __init__(self, attrs=None):
super(HUCountySelect, self).__init__(attrs, choices=HU_COUNTY_CHOICES)
27 changes: 27 additions & 0 deletions localflavor/hu/hu_counties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _

#: Hungarian counties: https://en.wikipedia.org/wiki/Counties_of_Hungary
HU_COUNTY_CHOICES = (
('bacs_kiskun', _('Bács-Kiskun')),
('baranya', _('Baranya')),
('bekes', _('Békés')),
('borsod_abauj_zemplen', _('Borsod-Abaúj-Zemplén')),
('csongrad', _('Csongrád')),
('fejer', _('Fejér')),
('gyor_moson_sopron', _('Győr-Moson-Sopron')),
('hajdu_bihar', _('Hajdú-Bihar')),
('heves', _('Heves')),
('jasz_nagykun_szolnok', _('Jász-Nagykun-Szolnok')),
('komarom_esztergom', _('Komárom-Esztergom')),
('nograd', _('Nógrád')),
('pest', _('Pest')),
('somogy', _('Somogy')),
('szabolcs_szatmar_bereg', _('Szabolcs-Szatmár-Bereg')),
('tolna', _('Tolna')),
('vas', _('Vas')),
('veszprem', _('Veszprém')),
('zala', _('Zala')),
)
33 changes: 33 additions & 0 deletions tests/test_hu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import SimpleTestCase

from localflavor.hu.forms import HUCountySelect


class HULocalFlavorTests(SimpleTestCase):
def test_HUCountySelect(self):
f = HUCountySelect()
out = '''<select name="counties">
<option value="bacs_kiskun">Bács-Kiskun</option>
<option value="baranya">Baranya</option>
<option value="bekes">Békés</option>
<option value="borsod_abauj_zemplen">Borsod-Abaúj-Zemplén</option>
<option value="csongrad">Csongrád</option>
<option value="fejer">Fejér</option>
<option value="gyor_moson_sopron">Győr-Moson-Sopron</option>
<option value="hajdu_bihar">Hajdú-Bihar</option>
<option value="heves">Heves</option>
<option value="jasz_nagykun_szolnok">Jász-Nagykun-Szolnok</option>
<option value="komarom_esztergom">Komárom-Esztergom</option>
<option value="nograd">Nógrád</option>
<option value="pest">Pest</option>
<option value="somogy">Somogy</option>
<option value="szabolcs_szatmar_bereg">Szabolcs-Szatmár-Bereg</option>
<option value="tolna">Tolna</option>
<option value="vas" selected="selected">Vas</option>
<option value="veszprem">Veszprém</option>
<option value="zala">Zala</option>
</select>'''
self.assertHTMLEqual(f.render('counties', 'vas'), out)

0 comments on commit b88be8c

Please sign in to comment.