Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #3715 -- Added Japanese package to django.contrib.localflavor. …
…Thanks, Makoto Tsuyuki git-svn-id: http://code.djangoproject.com/svn/django/trunk@4822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
1 parent
e2c04e8
commit f2861da
Showing
4 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
JP-specific Form helpers | ||
""" | ||
|
||
from django.core import validators | ||
from django.newforms import ValidationError | ||
from django.utils.translation import gettext | ||
from django.newforms.fields import RegexField, Select | ||
|
||
import re | ||
|
||
class JPPostalCodeField(RegexField): | ||
""" | ||
A form field that validates its input is a Japanese postcode. | ||
Accepts 7 digits, with or without a hyphen. | ||
""" | ||
def __init__(self, *args, **kwargs): | ||
super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$', | ||
max_length=None, min_length=None, | ||
error_message=gettext(u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'), | ||
*args, **kwargs) | ||
|
||
def clean(self, value): | ||
""" | ||
Validates the input and returns a string that contains only numbers. | ||
Returns an empty string for empty values. | ||
""" | ||
v = super(JPPostalCodeField, self).clean(value) | ||
return v.replace('-', '') | ||
|
||
class JPPrefectureSelect(Select): | ||
""" | ||
A Select widget that uses a list of Japanese prefectures as its choices. | ||
""" | ||
def __init__(self, attrs=None): | ||
from jp_prefectures import JP_PREFECTURES | ||
super(JPPrefectureSelect, self).__init__(attrs, choices=JP_PREFECTURES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.utils.translation import gettext_lazy as gettext_lazy | ||
|
||
JP_PREFECTURES = ( | ||
('hokkaido', gettext_lazy('Hokkaido'),), | ||
('aomori', gettext_lazy('Aomori'),), | ||
('iwate', gettext_lazy('Iwate'),), | ||
('miyagi', gettext_lazy('Miyagi'),), | ||
('akita', gettext_lazy('Akita'),), | ||
('yamagata', gettext_lazy('Yamagata'),), | ||
('fukushima', gettext_lazy('Fukushima'),), | ||
('ibaraki', gettext_lazy('Ibaraki'),), | ||
('tochigi', gettext_lazy('Tochigi'),), | ||
('gunma', gettext_lazy('Gunma'),), | ||
('saitama', gettext_lazy('Saitama'),), | ||
('chiba', gettext_lazy('Chiba'),), | ||
('tokyo', gettext_lazy('Tokyo'),), | ||
('kanagawa', gettext_lazy('Kanagawa'),), | ||
('yamanashi', gettext_lazy('Yamanashi'),), | ||
('nagano', gettext_lazy('Nagano'),), | ||
('niigata', gettext_lazy('Niigata'),), | ||
('toyama', gettext_lazy('Toyama'),), | ||
('ishikawa', gettext_lazy('Ishikawa'),), | ||
('fukui', gettext_lazy('Fukui'),), | ||
('gifu', gettext_lazy('Gifu'),), | ||
('shizuoka', gettext_lazy('Shizuoka'),), | ||
('aichi', gettext_lazy('Aichi'),), | ||
('mie', gettext_lazy('Mie'),), | ||
('shiga', gettext_lazy('Shiga'),), | ||
('kyoto', gettext_lazy('Kyoto'),), | ||
('osaka', gettext_lazy('Osaka'),), | ||
('hyogo', gettext_lazy('Hyogo'),), | ||
('nara', gettext_lazy('Nara'),), | ||
('wakayama', gettext_lazy('Wakayama'),), | ||
('tottori', gettext_lazy('Tottori'),), | ||
('shimane', gettext_lazy('Shimane'),), | ||
('okayama', gettext_lazy('Okayama'),), | ||
('hiroshima', gettext_lazy('Hiroshima'),), | ||
('yamaguchi', gettext_lazy('Yamaguchi'),), | ||
('tokushima', gettext_lazy('Tokushima'),), | ||
('kagawa', gettext_lazy('Kagawa'),), | ||
('ehime', gettext_lazy('Ehime'),), | ||
('kochi', gettext_lazy('Kochi'),), | ||
('fukuoka', gettext_lazy('Fukuoka'),), | ||
('saga', gettext_lazy('Saga'),), | ||
('nagasaki', gettext_lazy('Nagasaki'),), | ||
('kumamoto', gettext_lazy('Kumamoto'),), | ||
('oita', gettext_lazy('Oita'),), | ||
('miyazaki', gettext_lazy('Miyazaki'),), | ||
('kagoshima', gettext_lazy('Kagoshima'),), | ||
('okinawa', gettext_lazy('Okinawa'),), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters