2011-04-22 20:03:30 +08:00
|
|
|
"""
|
|
|
|
Russian-specific forms helpers
|
|
|
|
"""
|
2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2011-10-18 08:47:49 +08:00
|
|
|
|
2011-04-22 20:03:30 +08:00
|
|
|
import re
|
|
|
|
|
2011-10-18 08:47:49 +08:00
|
|
|
from django.contrib.localflavor.ru.ru_regions import RU_COUNTY_CHOICES, RU_REGIONS_CHOICES
|
2011-07-13 17:35:51 +08:00
|
|
|
from django.forms.fields import RegexField, Select
|
2011-04-22 20:03:30 +08:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
2011-10-18 08:47:49 +08:00
|
|
|
phone_digits_re = re.compile(r'^(?:[78]-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
|
2011-04-22 20:03:30 +08:00
|
|
|
|
|
|
|
class RUCountySelect(Select):
|
|
|
|
"""
|
|
|
|
A Select widget that uses a list of Russian Counties as its choices.
|
|
|
|
"""
|
|
|
|
def __init__(self, attrs=None):
|
|
|
|
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):
|
|
|
|
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 = {
|
2012-06-08 00:08:47 +08:00
|
|
|
'invalid': _('Enter a postal code in the format XXXXXX.'),
|
2011-04-22 20:03:30 +08:00
|
|
|
}
|
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 = {
|
2012-06-08 00:08:47 +08:00
|
|
|
'invalid': _('Enter a passport number in the format XXXX XXXXXX.'),
|
2011-04-22 20:03:30 +08:00
|
|
|
}
|
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 = {
|
2012-06-08 00:08:47 +08:00
|
|
|
'invalid': _('Enter a passport number in the format XX XXXXXXX.'),
|
2011-04-22 20:03:30 +08:00
|
|
|
}
|
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)
|