2011-04-22 20:03:30 +08:00
|
|
|
"""
|
|
|
|
Russian-specific forms helpers
|
|
|
|
"""
|
|
|
|
import re
|
|
|
|
|
|
|
|
from django.core.validators import EMPTY_VALUES
|
|
|
|
from django.forms import ValidationError
|
|
|
|
from django.forms.fields import CharField, Select, RegexField
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
phone_digits_re = re.compile(r'^(?:[78]-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
|
|
|
|
|
|
|
|
|
|
|
|
class RUCountySelect(Select):
|
|
|
|
"""
|
|
|
|
A Select widget that uses a list of Russian Counties as its choices.
|
|
|
|
"""
|
|
|
|
def __init__(self, attrs=None):
|
|
|
|
from ru_regions import RU_COUNTY_CHOICES
|
|
|
|
super(RUCountySelect, self).__init__(attrs, choices=RU_COUNTY_CHOICES)
|
|
|
|
|
|
|
|
|
|
|
|
class RURegionSelect(Select):
|
|
|
|
"""
|
|
|
|
A Select widget that uses a list of Russian Regions as its choices.
|
|
|
|
"""
|
|
|
|
def __init__(self, attrs=None):
|
|
|
|
from ru_regions import RU_REGIONS_CHOICES
|
|
|
|
super(RURegionSelect, self).__init__(attrs, choices=RU_REGIONS_CHOICES)
|
|
|
|
|
|
|
|
|
|
|
|
class RUPostalCodeField(RegexField):
|
|
|
|
"""
|
|
|
|
Russian Postal code field.
|
|
|
|
Format: XXXXXX, where X is any digit, and first digit is not zero.
|
|
|
|
"""
|
|
|
|
default_error_messages = {
|
|
|
|
'invalid': _(u'Enter a postal code in the format XXXXXX.'),
|
|
|
|
}
|
2011-05-03 19:52:04 +08:00
|
|
|
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
2011-04-22 20:03:30 +08:00
|
|
|
super(RUPostalCodeField, self).__init__(r'^\d{6}$',
|
2011-05-03 19:52:04 +08:00
|
|
|
max_length, min_length, *args, **kwargs)
|
2011-04-22 20:03:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
class RUPassportNumberField(RegexField):
|
|
|
|
"""
|
|
|
|
Russian internal passport number format:
|
|
|
|
XXXX XXXXXX where X - any digit.
|
|
|
|
"""
|
|
|
|
default_error_messages = {
|
|
|
|
'invalid': _(u'Enter a passport number in the format XXXX XXXXXX.'),
|
|
|
|
}
|
2011-05-03 19:52:04 +08:00
|
|
|
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
2011-04-22 20:03:30 +08:00
|
|
|
super(RUPassportNumberField, self).__init__(r'^\d{4} \d{6}$',
|
2011-05-03 19:52:04 +08:00
|
|
|
max_length, min_length, *args, **kwargs)
|
2011-04-22 20:03:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
class RUAlienPassportNumberField(RegexField):
|
|
|
|
"""
|
|
|
|
Russian alien's passport number format:
|
|
|
|
XX XXXXXXX where X - any digit.
|
|
|
|
"""
|
|
|
|
default_error_messages = {
|
|
|
|
'invalid': _(u'Enter a passport number in the format XX XXXXXXX.'),
|
|
|
|
}
|
2011-05-03 19:52:04 +08:00
|
|
|
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
|
2011-04-22 20:03:30 +08:00
|
|
|
super(RUAlienPassportNumberField, self).__init__(r'^\d{2} \d{7}$',
|
2011-05-03 19:52:04 +08:00
|
|
|
max_length, min_length, *args, **kwargs)
|