Ticket #15013: ru_localflavor.diff
File ru_localflavor.diff, 16.1 KB (added by , 14 years ago) |
---|
-
django/contrib/localflavor/ru/ru_regions.py
1 """ 2 Sources: 3 http://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D0%B4%D1%8B_%D1%81%D1%83%D0%B1%D1%8A%D0%B5%D0%BA%D1%82%D0%BE%D0%B2_%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%BE%D0%B9_%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D0%B8 4 http://ru.wikipedia.org/wiki/%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B5_%D0%BE%D0%BA%D1%80%D1%83%D0%B3%D0%B0_%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%BE%D0%B9_%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D0%B8 5 """ 6 from django.utils.translation import ugettext_lazy as _ 7 8 RU_COUNTY_CHOICES = ( 9 ("Central Federal County", _("Central Federal County")), 10 ("South Federal County", _("South Federal County")), 11 ("North-West Federal County", _("North-West Federal County")), 12 ("Far-East Federal County", _("Far-East Federal County")), 13 ("Siberian Federal County", _("Siberian Federal County")), 14 ("Ural Federal County", _("Ural Federal County")), 15 ("Privolzhsky Federal County", _("Privolzhsky Federal County")), 16 ("North-Caucasian Federal County", _("North-Caucasian Federal County")) 17 ) 18 19 RU_REGIONS_CHOICES = ( 20 ("77", _("Moskva")), 21 ("78", _("Saint-Peterburg")), 22 ("50", _("Moskovskaya oblast'")), 23 ("01", _("Adygeya, Respublika")), 24 ("02", _("Bashkortostan, Respublika")), 25 ("03", _("Buryatia, Respublika")), 26 ("04", _("Altay, Respublika")), 27 ("05", _("Dagestan, Respublika")), 28 ("06", _("Ingushskaya Respublika")), 29 ("07", _("Kabardino-Balkarskaya Respublika")), 30 ("08", _("Kalmykia, Respublika")), 31 ("09", _("Karachaevo-Cherkesskaya Respublika")), 32 ("10", _("Karelia, Respublika")), 33 ("11", _("Komi, Respublika")), 34 ("12", _("Mariy Ehl, Respublika")), 35 ("13", _("Mordovia, Respublika")), 36 ("14", _("Sakha, Respublika (Yakutiya)")), 37 ("15", _("Severnaya Osetia, Respublika (Alania)")), 38 ("16", _("Tatarstan, Respublika")), 39 ("17", _("Tyva, Respublika (Tuva)")), 40 ("18", _("Udmurtskaya Respublika")), 41 ("19", _("Khakassiya, Respublika")), 42 ("95", _("Chechenskaya Respublika")), 43 ("21", _("Chuvashskaya Respublika")), 44 ("22", _("Altayskiy Kray")), 45 ("80", _("Zabaykalskiy Kray")), 46 ("82", _("Kamchatskiy Kray")), 47 ("23", _("Krasnodarskiy Kray")), 48 ("24", _("Krasnoyarskiy Kray")), 49 ("81", _("Permskiy Kray")), 50 ("25", _("Primorskiy Kray")), 51 ("26", _("Stavropol'siyy Kray")), 52 ("27", _("Khabarovskiy Kray")), 53 ("28", _("Amurskaya oblast'")), 54 ("29", _("Arkhangel'skaya oblast'")), 55 ("30", _("Astrakhanskaya oblast'")), 56 ("31", _("Belgorodskaya oblast'")), 57 ("32", _("Bryanskaya oblast'")), 58 ("33", _("Vladimirskaya oblast'")), 59 ("34", _("Volgogradskaya oblast'")), 60 ("35", _("Vologodskaya oblast'")), 61 ("36", _("Voronezhskaya oblast'")), 62 ("37", _("Ivanovskaya oblast'")), 63 ("38", _("Irkutskaya oblast'")), 64 ("39", _("Kaliningradskaya oblast'")), 65 ("40", _("Kaluzhskaya oblast'")), 66 ("42", _("Kemerovskaya oblast'")), 67 ("43", _("Kirovskaya oblast'")), 68 ("44", _("Kostromskaya oblast'")), 69 ("45", _("Kurganskaya oblast'")), 70 ("46", _("Kurskaya oblast'")), 71 ("47", _("Leningradskaya oblast'")), 72 ("48", _("Lipeckaya oblast'")), 73 ("49", _("Magadanskaya oblast'")), 74 ("51", _("Murmanskaya oblast'")), 75 ("52", _("Nizhegorodskaja oblast'")), 76 ("53", _("Novgorodskaya oblast'")), 77 ("54", _("Novosibirskaya oblast'")), 78 ("55", _("Omskaya oblast'")), 79 ("56", _("Orenburgskaya oblast'")), 80 ("57", _("Orlovskaya oblast'")), 81 ("58", _("Penzenskaya oblast'")), 82 ("60", _("Pskovskaya oblast'")), 83 ("61", _("Rostovskaya oblast'")), 84 ("62", _("Rjazanskaya oblast'")), 85 ("63", _("Samarskaya oblast'")), 86 ("64", _("Saratovskaya oblast'")), 87 ("65", _("Sakhalinskaya oblast'")), 88 ("66", _("Sverdlovskaya oblast'")), 89 ("67", _("Smolenskaya oblast'")), 90 ("68", _("Tambovskaya oblast'")), 91 ("69", _("Tverskaya oblast'")), 92 ("70", _("Tomskaya oblast'")), 93 ("71", _("Tul'skaya oblast'")), 94 ("72", _("Tyumenskaya oblast'")), 95 ("73", _("Ul'ianovskaya oblast'")), 96 ("74", _("Chelyabinskaya oblast'")), 97 ("76", _("Yaroslavskaya oblast'")), 98 ("79", _("Evreyskaya avtonomnaja oblast'")), 99 ("83", _("Neneckiy autonomnyy okrug")), 100 ("86", _("Khanty-Mansiyskiy avtonomnyy okrug - Yugra")), 101 ("87", _("Chukotskiy avtonomnyy okrug")), 102 ("89", _("Yamalo-Neneckiy avtonomnyy okrug")) 103 ) 104 -
django/contrib/localflavor/ru/forms.py
1 """ 2 Russian-specific forms helpers 3 """ 4 from django.core.validators import EMPTY_VALUES 5 from django.forms import ValidationError 6 from django.forms.fields import CharField, Select, RegexField 7 from django.utils.translation import ugettext_lazy as _ 8 9 import re 10 11 phone_digits_re = re.compile(r'^(?:[78]-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$') 12 13 class RUCountySelect(Select): 14 """ 15 A Select widget that uses a list of Russian Counties as its choices. 16 """ 17 def __init__(self, attrs=None): 18 from ru_regions import RU_COUNTY_CHOICES 19 super(RUCountySelect, self).__init__(attrs, choices=RU_COUNTY_CHOICES) 20 21 class RURegionSelect(Select): 22 """ 23 A Select widget that uses a list of Russian Regions as its choices. 24 """ 25 def __init__(self, attrs=None): 26 from ru_regions import RU_REGIONS_CHOICES 27 super(RURegionSelect, self).__init__(attrs, choices=RU_REGIONS_CHOICES) 28 29 class RUPostalCodeField(RegexField): 30 """ 31 Russian Postal code field. 32 Format: XXXXXX, where X is any digit, and first digit is not zero. 33 """ 34 default_error_messages = { 35 'invalid': _(u'Enter a postal code in the format XXXXXX.'), 36 } 37 def __init__(self, *args, **kwargs): 38 super(RUPostalCodeField, self).__init__(r'^\d{6}$', 39 max_length=None, min_length=None, *args, **kwargs) 40 41 class RUPassportNumberField(RegexField): 42 """ 43 Russian internal passport number format: 44 XXXX XXXXXX where X - any digit. 45 """ 46 default_error_messages = { 47 'invalid': _(u'Enter a passport number in the format XXXX XXXXXX.'), 48 } 49 def __init__(self, *args, **kwargs): 50 super(RUPassportNumberField, self).__init__(r'^\d{4} \d{6}$', 51 max_length=None, min_length=None, *args, **kwargs) 52 53 class RUAlienPassportNumberField(RegexField): 54 """ 55 Russian alien's passport number format: 56 XX XXXXXXX where X - any digit. 57 """ 58 default_error_messages = { 59 'invalid': _(u'Enter a passport number in the format XX XXXXXXX.'), 60 } 61 def __init__(self, *args, **kwargs): 62 super(RUAlienPassportNumberField, self).__init__(r'^\d{2} \d{7}$', 63 max_length=None, min_length=None, *args, **kwargs) -
tests/regressiontests/forms/localflavor/ru.py
+
1 from django.contrib.localflavor.ru.forms import * 2 3 from utils import LocalFlavorTestCase 4 5 6 class RULocalFlavorTests(LocalFlavorTestCase): 7 8 def test_RUPassportNumberField(self): 9 error = [u'Enter a passport number in the format XXXX XXXXXX.'] 10 valid = { 11 '1981 211204': '1981 211204', 12 '0305 967876': '0305 967876', 13 } 14 invalid = { 15 '1981 2112044': error, 16 '1981 23220': error, 17 '9981211201': error, 18 } 19 self.assertFieldOutput(RUPassportNumberField, valid, invalid) 20 21 def test_RUAlienPassportNumberField(self): 22 error = [u'Enter a passport number in the format XX XXXXXXX.'] 23 valid = { 24 '19 8111204': '19 8111204', 25 '03 0567876': '03 0567876', 26 } 27 invalid = { 28 '198 1112044': error, 29 '19 81123220': error, 30 '99 812112': error, 31 } 32 self.assertFieldOutput(RUAlienPassportNumberField, valid, invalid) 33 34 def test_RUPostalCodeField(self): 35 error = [u'Enter a postal code in the format XXXXXX.'] 36 valid = { 37 '987654': '987654', 38 '123456': '123456' 39 } 40 invalid = { 41 '123 34': error, 42 '1234567': error, 43 '12345': error 44 } 45 self.assertFieldOutput(RUPostalCodeField, valid, invalid) 46 47 def test_RUCountySelect(self): 48 f = RUCountySelect() 49 out = u'''<select name="county"> 50 <option value="Central Federal County">Central Federal County</option> 51 <option value="South Federal County">South Federal County</option> 52 <option value="North-West Federal County">North-West Federal County</option> 53 <option value="Far-East Federal County">Far-East Federal County</option> 54 <option value="Siberian Federal County">Siberian Federal County</option> 55 <option value="Ural Federal County">Ural Federal County</option> 56 <option value="Privolzhsky Federal County">Privolzhsky Federal County</option> 57 <option value="North-Caucasian Federal County">North-Caucasian Federal County</option> 58 </select>''' 59 self.assertEqual(f.render('county', None), out) 60 61 def test_RURegionSelect(self): 62 f = RURegionSelect() 63 out = u'''<select name="region"> 64 <option value="77">Moskva</option> 65 <option value="78">Saint-Peterburg</option> 66 <option value="50">Moskovskaya oblast'</option> 67 <option value="01">Adygeya, Respublika</option> 68 <option value="02">Bashkortostan, Respublika</option> 69 <option value="03">Buryatia, Respublika</option> 70 <option value="04">Altay, Respublika</option> 71 <option value="05">Dagestan, Respublika</option> 72 <option value="06">Ingushskaya Respublika</option> 73 <option value="07">Kabardino-Balkarskaya Respublika</option> 74 <option value="08">Kalmykia, Respublika</option> 75 <option value="09">Karachaevo-Cherkesskaya Respublika</option> 76 <option value="10">Karelia, Respublika</option> 77 <option value="11">Komi, Respublika</option> 78 <option value="12">Mariy Ehl, Respublika</option> 79 <option value="13">Mordovia, Respublika</option> 80 <option value="14">Sakha, Respublika (Yakutiya)</option> 81 <option value="15">Severnaya Osetia, Respublika (Alania)</option> 82 <option value="16">Tatarstan, Respublika</option> 83 <option value="17">Tyva, Respublika (Tuva)</option> 84 <option value="18">Udmurtskaya Respublika</option> 85 <option value="19">Khakassiya, Respublika</option> 86 <option value="95">Chechenskaya Respublika</option> 87 <option value="21">Chuvashskaya Respublika</option> 88 <option value="22">Altayskiy Kray</option> 89 <option value="80">Zabaykalskiy Kray</option> 90 <option value="82">Kamchatskiy Kray</option> 91 <option value="23">Krasnodarskiy Kray</option> 92 <option value="24">Krasnoyarskiy Kray</option> 93 <option value="81">Permskiy Kray</option> 94 <option value="25">Primorskiy Kray</option> 95 <option value="26">Stavropol'siyy Kray</option> 96 <option value="27">Khabarovskiy Kray</option> 97 <option value="28">Amurskaya oblast'</option> 98 <option value="29">Arkhangel'skaya oblast'</option> 99 <option value="30">Astrakhanskaya oblast'</option> 100 <option value="31">Belgorodskaya oblast'</option> 101 <option value="32">Bryanskaya oblast'</option> 102 <option value="33">Vladimirskaya oblast'</option> 103 <option value="34">Volgogradskaya oblast'</option> 104 <option value="35">Vologodskaya oblast'</option> 105 <option value="36">Voronezhskaya oblast'</option> 106 <option value="37">Ivanovskaya oblast'</option> 107 <option value="38">Irkutskaya oblast'</option> 108 <option value="39">Kaliningradskaya oblast'</option> 109 <option value="40">Kaluzhskaya oblast'</option> 110 <option value="42">Kemerovskaya oblast'</option> 111 <option value="43">Kirovskaya oblast'</option> 112 <option value="44">Kostromskaya oblast'</option> 113 <option value="45">Kurganskaya oblast'</option> 114 <option value="46">Kurskaya oblast'</option> 115 <option value="47">Leningradskaya oblast'</option> 116 <option value="48">Lipeckaya oblast'</option> 117 <option value="49">Magadanskaya oblast'</option> 118 <option value="51">Murmanskaya oblast'</option> 119 <option value="52">Nizhegorodskaja oblast'</option> 120 <option value="53">Novgorodskaya oblast'</option> 121 <option value="54">Novosibirskaya oblast'</option> 122 <option value="55">Omskaya oblast'</option> 123 <option value="56">Orenburgskaya oblast'</option> 124 <option value="57">Orlovskaya oblast'</option> 125 <option value="58">Penzenskaya oblast'</option> 126 <option value="60">Pskovskaya oblast'</option> 127 <option value="61">Rostovskaya oblast'</option> 128 <option value="62">Rjazanskaya oblast'</option> 129 <option value="63">Samarskaya oblast'</option> 130 <option value="64">Saratovskaya oblast'</option> 131 <option value="65">Sakhalinskaya oblast'</option> 132 <option value="66">Sverdlovskaya oblast'</option> 133 <option value="67" selected="selected">Smolenskaya oblast'</option> 134 <option value="68">Tambovskaya oblast'</option> 135 <option value="69">Tverskaya oblast'</option> 136 <option value="70">Tomskaya oblast'</option> 137 <option value="71">Tul'skaya oblast'</option> 138 <option value="72">Tyumenskaya oblast'</option> 139 <option value="73">Ul'ianovskaya oblast'</option> 140 <option value="74">Chelyabinskaya oblast'</option> 141 <option value="76">Yaroslavskaya oblast'</option> 142 <option value="79">Evreyskaya avtonomnaja oblast'</option> 143 <option value="83">Neneckiy autonomnyy okrug</option> 144 <option value="86">Khanty-Mansiyskiy avtonomnyy okrug - Yugra</option> 145 <option value="87">Chukotskiy avtonomnyy okrug</option> 146 <option value="89">Yamalo-Neneckiy avtonomnyy okrug</option> 147 </select>''' 148 self.assertEqual(f.render('region', '67'), out) -
tests/regressiontests/forms/localflavortests.py
23 23 from localflavor.pl import PLLocalFlavorTests 24 24 from localflavor.pt import PTLocalFlavorTests 25 25 from localflavor.ro import ROLocalFlavorTests 26 from localflavor.ru import RULocalFlavorTests 26 27 from localflavor.se import SELocalFlavorTests 27 28 from localflavor.sk import SKLocalFlavorTests 28 29 from localflavor.tr import TRLocalFlavorTests -
docs/ref/contrib/localflavor.txt
62 62 * Poland_ 63 63 * Portugal_ 64 64 * Romania_ 65 * Russia_ 65 66 * Slovakia_ 66 67 * `South Africa`_ 67 68 * Spain_ … … 111 112 .. _Poland: `Poland (pl)`_ 112 113 .. _Portugal: `Portugal (pt)`_ 113 114 .. _Romania: `Romania (ro)`_ 115 .. _Russia: `Russia (ru)`_ 114 116 .. _Slovakia: `Slovakia (sk)`_ 115 117 .. _South Africa: `South Africa (za)`_ 116 118 .. _Spain: `Spain (es)`_ … … 710 712 711 713 A form field that validates Romanian postal codes. 712 714 715 Russia (``ru``) 716 =============== 717 718 .. class:: ru.forms.RUPostalCodeField 719 720 Russian Postal code field. 721 Format: XXXXXX, where X is any digit, and first digit is not zero. 722 723 .. class:: ru.forms.RUCountySelect 724 725 A ``Select`` widget that uses a list of Russian Counties as its choices. 726 727 .. class:: ru.forms.RURegionSelect 728 729 A ``Select`` widget that uses a list of Russian Regions as its choices. 730 731 .. class:: ru.forms.RUPassportNumberField 732 733 Russian internal passport number format: 734 XXXX XXXXXX where X - any digit. 735 736 .. class:: ru.forms.RUAlienPassportNumberField 737 738 Russian alien's passport number format: 739 XX XXXXXXX where X - any digit. 740 713 741 Slovakia (``sk``) 714 742 ================= 715 743