Fixed #7686 -- Added an Austrian localflavor. Thanks, bernd.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8087 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
319a31464d
commit
a26ba33111
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
STATE_CHOICES = (
|
||||
('BL', _('Burgenland')),
|
||||
('KA', _('Carinthia')),
|
||||
('NO', _('Lower Austria')),
|
||||
('OO', _('Upper Austria')),
|
||||
('SA', _('Salzburg')),
|
||||
('ST', _('Styria')),
|
||||
('TI', _('Tyrol')),
|
||||
('VO', _('Vorarlberg')),
|
||||
('WI', _('Vienna')),
|
||||
)
|
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
AT-specific Form helpers
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.forms.fields import Field, RegexField, Select
|
||||
|
||||
class ATZipCodeField(RegexField):
|
||||
"""
|
||||
A form field that validates its input is an Austrian postcode.
|
||||
|
||||
Accepts 4 digits.
|
||||
"""
|
||||
default_error_messages = {
|
||||
'invalid': _('Enter a zip code in the format XXXX.'),
|
||||
}
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ATZipCodeField, self).__init__(r'^\d{4}$',
|
||||
max_length=None, min_length=None, *args, **kwargs)
|
||||
|
||||
class ATStateSelect(Select):
|
||||
"""
|
||||
A Select widget that uses a list of AT states as its choices.
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
from at_states import STATE_CHOICES
|
||||
super(ATStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
|
@ -32,6 +32,7 @@ Countries currently supported by ``localflavor`` are:
|
|||
|
||||
* Argentina_
|
||||
* Australia_
|
||||
* Austria_
|
||||
* Brazil_
|
||||
* Canada_
|
||||
* Chile_
|
||||
|
@ -70,6 +71,7 @@ them::
|
|||
.. _ISO 3166 country codes: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
|
||||
.. _Argentina: `Argentina (django.contrib.localflavor.ar)`_
|
||||
.. _Australia: `Australia (django.contrib.localflavor.au)`_
|
||||
.. _Austria: `Austria (django.contrib.localflavor.at)`_
|
||||
.. _Brazil: `Brazil (django.contrib.localflavor.br)`_
|
||||
.. _Canada: `Canada (django.contrib.localflavor.ca)`_
|
||||
.. _Chile: `Chile (django.contrib.localflavor.cl)`_
|
||||
|
@ -153,6 +155,19 @@ AUStateSelect
|
|||
A ``Select`` widget that uses a list of Australian states/territories as its
|
||||
choices.
|
||||
|
||||
Austria (``django.contrib.localflavor.at``)
|
||||
=============================================
|
||||
|
||||
ATZipCodeField
|
||||
---------------
|
||||
|
||||
A form field that validates its input is an Austrian postcode.
|
||||
|
||||
ATStateSelect
|
||||
-------------
|
||||
|
||||
A ``Select`` widget that uses a list of Austrian states as its choices.
|
||||
|
||||
Brazil (``django.contrib.localflavor.br``)
|
||||
==========================================
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Tests for the contrib/localflavor/ AT form fields.
|
||||
|
||||
tests = r"""
|
||||
# ATZipCodeField ###########################################################
|
||||
|
||||
>>> from django.contrib.localflavor.at.forms import ATZipCodeField
|
||||
>>> f = ATZipCodeField()
|
||||
>>> f.clean('1150')
|
||||
u'1150'
|
||||
>>> f.clean('4020')
|
||||
u'4020'
|
||||
>>> f.clean('8020')
|
||||
u'8020'
|
||||
>>> f.clean('111222')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a zip code in the format XXXX.']
|
||||
>>> f.clean('eeffee')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a zip code in the format XXXX.']
|
||||
>>> f.clean(u'')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
>>> f.clean(None)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
|
||||
|
||||
>>> f = ATZipCodeField(required=False)
|
||||
>>> f.clean('1150')
|
||||
u'1150'
|
||||
>>> f.clean('4020')
|
||||
u'4020'
|
||||
>>> f.clean('8020')
|
||||
u'8020'
|
||||
>>> f.clean('111222')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a zip code in the format XXXX.']
|
||||
>>> f.clean('eeffee')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a zip code in the format XXXX.']
|
||||
>>> f.clean(None)
|
||||
u''
|
||||
>>> f.clean('')
|
||||
u''
|
||||
>>> f.clean(u'')
|
||||
u''
|
||||
|
||||
# ATStateSelect ##################################################################
|
||||
|
||||
>>> from django.contrib.localflavor.at.forms import ATStateSelect
|
||||
>>> f = ATStateSelect()
|
||||
>>> f.render('bundesland', 'WI')
|
||||
u'<select name="bundesland">\n<option value="BL">Burgenland</option>\n<option value="KA">Carinthia</option>\n<option value="NO">Lower Austria</option>\n<option value="OO">Upper Austria</option>\n<option value="SA">Salzburg</option>\n<option value="ST">Styria</option>\n<option value="TI">Tyrol</option>\n<option value="VO">Vorarlberg</option>\n<option value="WI" selected="selected">Vienna</option>\n</select>'
|
||||
|
||||
"""
|
|
@ -4,6 +4,7 @@ from fields import tests as fields_tests
|
|||
from forms import tests as form_tests
|
||||
from error_messages import tests as custom_error_message_tests
|
||||
from localflavor.ar import tests as localflavor_ar_tests
|
||||
from localflavor.at import tests as localflavor_at_tests
|
||||
from localflavor.au import tests as localflavor_au_tests
|
||||
from localflavor.br import tests as localflavor_br_tests
|
||||
from localflavor.ca import tests as localflavor_ca_tests
|
||||
|
@ -36,6 +37,7 @@ __test__ = {
|
|||
'form_tests': form_tests,
|
||||
'custom_error_message_tests': custom_error_message_tests,
|
||||
'localflavor_ar_tests': localflavor_ar_tests,
|
||||
'localflavor_at_tests': localflavor_at_tests,
|
||||
'localflavor_au_tests': localflavor_au_tests,
|
||||
'localflavor_br_tests': localflavor_br_tests,
|
||||
'localflavor_ca_tests': localflavor_ca_tests,
|
||||
|
|
Loading…
Reference in New Issue