mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
unicode: Unicode audit pass through localflavor. Also fixed a few common
stylistic errors. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5271 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1ad97d0634
commit
4a7727e46e
@ -15,14 +15,14 @@ class AUPostCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AUPostCodeField, self).__init__(r'^\d{4}$',
|
super(AUPostCodeField, self).__init__(r'^\d{4}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a 4 digit post code.'),
|
error_message=ugettext('Enter a 4 digit post code.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class AUPhoneNumberField(Field):
|
class AUPhoneNumberField(Field):
|
||||||
"""Australian phone number field."""
|
"""Australian phone number field."""
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
"""Validate a phone number. Strips parentheses, whitespace and
|
"""
|
||||||
hyphens.
|
Validate a phone number. Strips parentheses, whitespace and hyphens.
|
||||||
"""
|
"""
|
||||||
super(AUPhoneNumberField, self).clean(value)
|
super(AUPhoneNumberField, self).clean(value)
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
@ -39,5 +39,5 @@ class AUStateSelect(Select):
|
|||||||
choices.
|
choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from au_states import STATE_CHOICES # relative import
|
from au_states import STATE_CHOICES
|
||||||
super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
||||||
|
@ -27,7 +27,7 @@ class BRPhoneNumberField(Field):
|
|||||||
m = phone_digits_re.search(value)
|
m = phone_digits_re.search(value)
|
||||||
if m:
|
if m:
|
||||||
return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
|
return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
|
||||||
raise ValidationError(ugettext(u'Phone numbers must be in XX-XXXX-XXXX format.'))
|
raise ValidationError(ugettext('Phone numbers must be in XX-XXXX-XXXX format.'))
|
||||||
|
|
||||||
class BRStateSelect(Select):
|
class BRStateSelect(Select):
|
||||||
"""
|
"""
|
||||||
@ -35,7 +35,7 @@ class BRStateSelect(Select):
|
|||||||
as its choices.
|
as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from br_states import STATE_CHOICES # relative import
|
from br_states import STATE_CHOICES
|
||||||
super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ Chile specific form helpers.
|
|||||||
from django.newforms import ValidationError
|
from django.newforms import ValidationError
|
||||||
from django.newforms.fields import RegexField, EMPTY_VALUES
|
from django.newforms.fields import RegexField, EMPTY_VALUES
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
class CLRutField(RegexField):
|
class CLRutField(RegexField):
|
||||||
"""
|
"""
|
||||||
@ -23,7 +24,7 @@ class CLRutField(RegexField):
|
|||||||
else:
|
else:
|
||||||
# In non-strict mode, accept RUTs that validate but do not exist in
|
# In non-strict mode, accept RUTs that validate but do not exist in
|
||||||
# the real world.
|
# the real world.
|
||||||
super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', error_message=ugettext(u'Enter valid a Chilean RUT'), *args, **kwargs)
|
super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', error_message=ugettext('Enter valid a Chilean RUT'), *args, **kwargs)
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
"""
|
"""
|
||||||
@ -49,14 +50,14 @@ class CLRutField(RegexField):
|
|||||||
multi += 1
|
multi += 1
|
||||||
if multi == 8:
|
if multi == 8:
|
||||||
multi = 2
|
multi = 2
|
||||||
return '0123456789K0'[11 - suma % 11]
|
return u'0123456789K0'[11 - suma % 11]
|
||||||
|
|
||||||
def _canonify(self, rut):
|
def _canonify(self, rut):
|
||||||
"""
|
"""
|
||||||
Turns the RUT into one normalized format. Returns a (rut, verifier)
|
Turns the RUT into one normalized format. Returns a (rut, verifier)
|
||||||
tuple.
|
tuple.
|
||||||
"""
|
"""
|
||||||
rut = str(rut).replace(' ', '').replace('.', '').replace('-', '')
|
rut = smart_unicode(rut).replace(' ', '').replace('.', '').replace('-', '')
|
||||||
return rut[:-1], rut[-1]
|
return rut[:-1], rut[-1]
|
||||||
|
|
||||||
def _format(self, code, verifier=None):
|
def _format(self, code, verifier=None):
|
||||||
@ -74,5 +75,5 @@ class CLRutField(RegexField):
|
|||||||
else:
|
else:
|
||||||
new_dot = pos - 3
|
new_dot = pos - 3
|
||||||
code = code[:new_dot] + '.' + code[new_dot:]
|
code = code[:new_dot] + '.' + code[new_dot:]
|
||||||
return '%s-%s' % (code, verifier)
|
return u'%s-%s' % (code, verifier)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class DEZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DEZipCodeField, self).__init__(r'^\d{5}$',
|
super(DEZipCodeField, self).__init__(r'^\d{5}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a zip code in the format XXXXX.'),
|
error_message=ugettext('Enter a zip code in the format XXXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class DEStateSelect(Select):
|
class DEStateSelect(Select):
|
||||||
@ -21,7 +21,7 @@ class DEStateSelect(Select):
|
|||||||
A Select widget that uses a list of DE states as its choices.
|
A Select widget that uses a list of DE states as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from de_states import STATE_CHOICES # relative import
|
from de_states import STATE_CHOICES
|
||||||
super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
||||||
|
|
||||||
class DEIdentityCardNumberField(Field):
|
class DEIdentityCardNumberField(Field):
|
||||||
@ -57,7 +57,7 @@ class DEIdentityCardNumberField(Field):
|
|||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
super(DEIdentityCardNumberField, self).clean(value)
|
super(DEIdentityCardNumberField, self).clean(value)
|
||||||
error_msg = ugettext(u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.')
|
error_msg = ugettext('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.')
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
return u''
|
return u''
|
||||||
match = re.match(id_re, value)
|
match = re.match(id_re, value)
|
||||||
@ -71,7 +71,7 @@ class DEIdentityCardNumberField(Field):
|
|||||||
if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
|
if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
|
||||||
raise ValidationError(error_msg)
|
raise ValidationError(error_msg)
|
||||||
|
|
||||||
all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum)
|
all_digits = u"%s%s%s%s" % (residence, birthday, validity, checksum)
|
||||||
if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \
|
if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \
|
||||||
not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits):
|
not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits):
|
||||||
raise ValidationError(error_msg)
|
raise ValidationError(error_msg)
|
||||||
|
@ -11,7 +11,7 @@ class FIZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(FIZipCodeField, self).__init__(r'^\d{5}$',
|
super(FIZipCodeField, self).__init__(r'^\d{5}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a zip code in the format XXXXX.'),
|
error_message=ugettext('Enter a zip code in the format XXXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class FIMunicipalitySelect(Select):
|
class FIMunicipalitySelect(Select):
|
||||||
@ -19,7 +19,7 @@ class FIMunicipalitySelect(Select):
|
|||||||
A Select widget that uses a list of Finnish municipalities as its choices.
|
A Select widget that uses a list of Finnish municipalities as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from fi_municipalities import MUNICIPALITY_CHOICES # relative import
|
from fi_municipalities import MUNICIPALITY_CHOICES
|
||||||
super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
|
super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
|
||||||
|
|
||||||
class FISocialSecurityNumber(Field):
|
class FISocialSecurityNumber(Field):
|
||||||
@ -37,9 +37,9 @@ class FISocialSecurityNumber(Field):
|
|||||||
(?P<serial>(\d{3}))
|
(?P<serial>(\d{3}))
|
||||||
(?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE)
|
(?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE)
|
||||||
if not result:
|
if not result:
|
||||||
raise ValidationError(ugettext(u'Enter a valid Finnish social security number.'))
|
raise ValidationError(ugettext('Enter a valid Finnish social security number.'))
|
||||||
gd = result.groupdict()
|
gd = result.groupdict()
|
||||||
checksum = int(gd['date'] + gd['serial'])
|
checksum = int(gd['date'] + gd['serial'])
|
||||||
if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper():
|
if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper():
|
||||||
return u'%s' % value.upper()
|
return u'%s' % value.upper()
|
||||||
raise ValidationError(ugettext(u'Enter a valid Finnish social security number.'))
|
raise ValidationError(ugettext('Enter a valid Finnish social security number.'))
|
||||||
|
@ -14,7 +14,7 @@ class FRZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(FRZipCodeField, self).__init__(r'^\d{5}$',
|
super(FRZipCodeField, self).__init__(r'^\d{5}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a zip code in the format XXXXX.'),
|
error_message=ugettext('Enter a zip code in the format XXXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class FRPhoneNumberField(Field):
|
class FRPhoneNumberField(Field):
|
||||||
@ -39,6 +39,6 @@ class FRDepartmentSelect(Select):
|
|||||||
A Select widget that uses a list of FR departments as its choices.
|
A Select widget that uses a list of FR departments as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from fr_department import DEPARTMENT_ASCII_CHOICES # relative import
|
from fr_department import DEPARTMENT_ASCII_CHOICES
|
||||||
super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ASCII_CHOICES)
|
super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ASCII_CHOICES)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from django.newforms import ValidationError
|
|||||||
from django.newforms.fields import RegexField, EMPTY_VALUES
|
from django.newforms.fields import RegexField, EMPTY_VALUES
|
||||||
from django.newforms.widgets import Select
|
from django.newforms.widgets import Select
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
class ISIdNumberField(RegexField):
|
class ISIdNumberField(RegexField):
|
||||||
"""
|
"""
|
||||||
@ -13,7 +14,7 @@ class ISIdNumberField(RegexField):
|
|||||||
of Iceland has.
|
of Iceland has.
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
error_msg = ugettext(u'Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.')
|
error_msg = ugettext('Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.')
|
||||||
kwargs['min_length'],kwargs['max_length'] = 10,11
|
kwargs['min_length'],kwargs['max_length'] = 10,11
|
||||||
super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', error_message=error_msg, *args, **kwargs)
|
super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', error_message=error_msg, *args, **kwargs)
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ class ISIdNumberField(RegexField):
|
|||||||
Takes in the value in canonical form and returns it in the common
|
Takes in the value in canonical form and returns it in the common
|
||||||
display format.
|
display format.
|
||||||
"""
|
"""
|
||||||
return value[:6]+'-'+value[6:]
|
return smart_unicode(value[:6]+'-'+value[6:])
|
||||||
|
|
||||||
class ISPhoneNumberField(RegexField):
|
class ISPhoneNumberField(RegexField):
|
||||||
"""
|
"""
|
||||||
|
@ -13,7 +13,7 @@ class ITZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ITZipCodeField, self).__init__(r'^\d{5}$',
|
super(ITZipCodeField, self).__init__(r'^\d{5}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a valid zip code.'),
|
error_message=ugettext('Enter a valid zip code.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class ITRegionSelect(Select):
|
class ITRegionSelect(Select):
|
||||||
@ -21,7 +21,7 @@ class ITRegionSelect(Select):
|
|||||||
A Select widget that uses a list of IT regions as its choices.
|
A Select widget that uses a list of IT regions as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from it_region import REGION_CHOICES # relative import
|
from it_region import REGION_CHOICES
|
||||||
super(ITRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
|
super(ITRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
|
||||||
|
|
||||||
class ITProvinceSelect(Select):
|
class ITProvinceSelect(Select):
|
||||||
@ -29,7 +29,7 @@ class ITProvinceSelect(Select):
|
|||||||
A Select widget that uses a list of IT regions as its choices.
|
A Select widget that uses a list of IT regions as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from it_province import PROVINCE_CHOICES # relative import
|
from it_province import PROVINCE_CHOICES
|
||||||
super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
|
super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
|
||||||
|
|
||||||
class ITSocialSecurityNumberField(RegexField):
|
class ITSocialSecurityNumberField(RegexField):
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
|
from django.utils.encoding import smart_str, smart_unicode
|
||||||
|
|
||||||
def ssn_check_digit(value):
|
def ssn_check_digit(value):
|
||||||
"Calculate Italian social security number check digit."
|
"Calculate Italian social security number check digit."
|
||||||
ssn_even_chars = {
|
ssn_even_chars = {
|
||||||
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
|
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8,
|
||||||
'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9,
|
'9': 9, 'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7,
|
||||||
'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18,
|
'I': 8, 'J': 9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15,
|
||||||
'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25
|
'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23,
|
||||||
|
'Y': 24, 'Z': 25
|
||||||
}
|
}
|
||||||
ssn_odd_chars = {
|
ssn_odd_chars = {
|
||||||
'0': 1, '1': 0, '2': 5, '3': 7, '4': 9, '5': 13, '6': 15, '7': 17, '8': 19, '9': 21,
|
'0': 1, '1': 0, '2': 5, '3': 7, '4': 9, '5': 13, '6': 15, '7': 17, '8':
|
||||||
'A': 1, 'B': 0, 'C': 5, 'D': 7, 'E': 9, 'F': 13, 'G': 15, 'H': 17, 'I': 19, 'J': 21,
|
19, '9': 21, 'A': 1, 'B': 0, 'C': 5, 'D': 7, 'E': 9, 'F': 13, 'G': 15,
|
||||||
'K': 2, 'L': 4, 'M': 18, 'N': 20, 'O': 11, 'P': 3, 'Q': 6, 'R': 8, 'S': 12,
|
'H': 17, 'I': 19, 'J': 21, 'K': 2, 'L': 4, 'M': 18, 'N': 20, 'O': 11,
|
||||||
'T': 14, 'U': 16, 'V': 10, 'W': 22, 'X': 25, 'Y': 24, 'Z': 23
|
'P': 3, 'Q': 6, 'R': 8, 'S': 12, 'T': 14, 'U': 16, 'V': 10, 'W': 22,
|
||||||
|
'X': 25, 'Y': 24, 'Z': 23
|
||||||
}
|
}
|
||||||
# Chars from 'A' to 'Z'
|
# Chars from 'A' to 'Z'
|
||||||
ssn_check_digits = [chr(x) for x in range(65, 91)]
|
ssn_check_digits = [chr(x) for x in range(65, 91)]
|
||||||
@ -30,11 +34,11 @@ def ssn_check_digit(value):
|
|||||||
|
|
||||||
def vat_number_check_digit(vat_number):
|
def vat_number_check_digit(vat_number):
|
||||||
"Calculate Italian VAT number check digit."
|
"Calculate Italian VAT number check digit."
|
||||||
normalized_vat_number = str(vat_number).zfill(10)
|
normalized_vat_number = smart_str(vat_number).zfill(10)
|
||||||
total = 0
|
total = 0
|
||||||
for i in range(0, 10, 2):
|
for i in range(0, 10, 2):
|
||||||
total += int(normalized_vat_number[i])
|
total += int(normalized_vat_number[i])
|
||||||
for i in range(1, 11, 2):
|
for i in range(1, 11, 2):
|
||||||
quotient , remainder = divmod(int(normalized_vat_number[i]) * 2, 10)
|
quotient , remainder = divmod(int(normalized_vat_number[i]) * 2, 10)
|
||||||
total += quotient + remainder
|
total += quotient + remainder
|
||||||
return str((10 - total % 10) % 10)
|
return smart_unicode((10 - total % 10) % 10)
|
||||||
|
@ -18,7 +18,7 @@ class JPPostalCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$',
|
super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
|
error_message=ugettext('Enter a postal code in the format XXXXXXX or XXX-XXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
|
@ -12,7 +12,7 @@ class NOZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(NOZipCodeField, self).__init__(r'^\d{4}$',
|
super(NOZipCodeField, self).__init__(r'^\d{4}$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a zip code in the format XXXX.'),
|
error_message=ugettext('Enter a zip code in the format XXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class NOMunicipalitySelect(Select):
|
class NOMunicipalitySelect(Select):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# -*- coding: iso-8859-1 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
An alphabetical list of Norwegian municipalities (fylker) fro use as `choices`
|
An alphabetical list of Norwegian municipalities (fylker) fro use as `choices`
|
||||||
in a formfield.
|
in a formfield.
|
||||||
@ -15,18 +15,18 @@ MUNICIPALITY_CHOICES = (
|
|||||||
('hedmark', u'Hedmark'),
|
('hedmark', u'Hedmark'),
|
||||||
('hordaland', u'Hordaland'),
|
('hordaland', u'Hordaland'),
|
||||||
('janmayen', u'Jan Mayen'),
|
('janmayen', u'Jan Mayen'),
|
||||||
('moreogromsdal', u'Møre og Romsdal'),
|
('moreogromsdal', u'Møre og Romsdal'),
|
||||||
('nordtrondelag', u'Nord-Trøndelag'),
|
('nordtrondelag', u'Nord-Trøndelag'),
|
||||||
('nordland', u'Nordland'),
|
('nordland', u'Nordland'),
|
||||||
('oppland', u'Oppland'),
|
('oppland', u'Oppland'),
|
||||||
('oslo', u'Oslo'),
|
('oslo', u'Oslo'),
|
||||||
('rogaland', u'Rogaland'),
|
('rogaland', u'Rogaland'),
|
||||||
('sognogfjordane', u'Sogn og Fjordane'),
|
('sognogfjordane', u'Sogn og Fjordane'),
|
||||||
('svalbard', u'Svalbard'),
|
('svalbard', u'Svalbard'),
|
||||||
('sortrondelag', u'Sør-Trøndelag'),
|
('sortrondelag', u'Sør-Trøndelag'),
|
||||||
('telemark', u'Telemark'),
|
('telemark', u'Telemark'),
|
||||||
('troms', u'Troms'),
|
('troms', u'Troms'),
|
||||||
('vestagder', u'Vest-Agder'),
|
('vestagder', u'Vest-Agder'),
|
||||||
('vestfold', u'Vestfold'),
|
('vestfold', u'Vestfold'),
|
||||||
('ostfold', u'Østfold')
|
('ostfold', u'Østfold')
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,7 @@ class USZipCodeField(RegexField):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
|
super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
|
||||||
max_length=None, min_length=None,
|
max_length=None, min_length=None,
|
||||||
error_message=ugettext(u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'),
|
error_message=ugettext('Enter a zip code in the format XXXXX or XXXXX-XXXX.'),
|
||||||
*args, **kwargs)
|
*args, **kwargs)
|
||||||
|
|
||||||
class USPhoneNumberField(Field):
|
class USPhoneNumberField(Field):
|
||||||
@ -38,17 +38,17 @@ class USSocialSecurityNumberField(Field):
|
|||||||
* Conforms to the XXX-XX-XXXX format.
|
* Conforms to the XXX-XX-XXXX format.
|
||||||
* No group consists entirely of zeroes.
|
* No group consists entirely of zeroes.
|
||||||
* The leading group is not "666" (block "666" will never be allocated).
|
* The leading group is not "666" (block "666" will never be allocated).
|
||||||
* The number is not in the promotional block 987-65-4320 through 987-65-4329,
|
* The number is not in the promotional block 987-65-4320 through
|
||||||
which are permanently invalid.
|
987-65-4329, which are permanently invalid.
|
||||||
* The number is not one known to be invalid due to otherwise widespread
|
* The number is not one known to be invalid due to otherwise widespread
|
||||||
promotional use or distribution (e.g., the Woolworth's number or the 1962
|
promotional use or distribution (e.g., the Woolworth's number or the
|
||||||
promotional number).
|
1962 promotional number).
|
||||||
"""
|
"""
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
super(USSocialSecurityNumberField, self).clean(value)
|
super(USSocialSecurityNumberField, self).clean(value)
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
return u''
|
return u''
|
||||||
msg = ugettext(u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.')
|
msg = ugettext('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.')
|
||||||
match = re.match(ssn_re, value)
|
match = re.match(ssn_re, value)
|
||||||
if not match:
|
if not match:
|
||||||
raise ValidationError(msg)
|
raise ValidationError(msg)
|
||||||
@ -75,7 +75,7 @@ class USStateField(Field):
|
|||||||
abbreviation for the given state.
|
abbreviation for the given state.
|
||||||
"""
|
"""
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
from us_states import STATES_NORMALIZED # relative import
|
from us_states import STATES_NORMALIZED
|
||||||
super(USStateField, self).clean(value)
|
super(USStateField, self).clean(value)
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
return u''
|
return u''
|
||||||
@ -95,5 +95,5 @@ class USStateSelect(Select):
|
|||||||
A Select widget that uses a list of U.S. states/territories as its choices.
|
A Select widget that uses a list of U.S. states/territories as its choices.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
from us_states import STATE_CHOICES # relative import
|
from us_states import STATE_CHOICES
|
||||||
super(USStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
super(USStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user