Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed django.contrib.localflavor.

Each localflavor lives on as a separate app.
  • Loading branch information...
commit f27a4ee3270bd57299ce02d622978ac4d839137e 1 parent b2d20e9
Aymeric Augustin authored December 24, 2012

Showing 117 changed files with 1 addition and 50,783 deletions. Show diff stats Hide diff stats

  1. 5  .tx/config
  2. 3  django/contrib/gis/tests/relatedapp/models.py
  3. 2  django/contrib/gis/utils/layermapping.py
  4. 2  django/contrib/localflavor/__init__.py
  5. 37  django/contrib/localflavor/ar/ar_provinces.py
  6. 128  django/contrib/localflavor/ar/forms.py
  7. 14  django/contrib/localflavor/at/at_states.py
  8. 69  django/contrib/localflavor/at/forms.py
  9. 17  django/contrib/localflavor/au/au_states.py
  10. 60  django/contrib/localflavor/au/forms.py
  11. 43  django/contrib/localflavor/au/models.py
  12. 16  django/contrib/localflavor/be/be_provinces.py
  13. 8  django/contrib/localflavor/be/be_regions.py
  14. 71  django/contrib/localflavor/be/forms.py
  15. 38  django/contrib/localflavor/br/br_states.py
  16. 166  django/contrib/localflavor/br/forms.py
  17. 63  django/contrib/localflavor/ca/ca_provinces.py
  18. 148  django/contrib/localflavor/ca/forms.py
  19. 31  django/contrib/localflavor/ch/ch_states.py
  20. 122  django/contrib/localflavor/ch/forms.py
  21. 26  django/contrib/localflavor/cl/cl_regions.py
  22. 97  django/contrib/localflavor/cl/forms.py
  23. 49  django/contrib/localflavor/cn/cn_provinces.py
  24. 214  django/contrib/localflavor/cn/forms.py
  25. 45  django/contrib/localflavor/co/co_departments.py
  26. 16  django/contrib/localflavor/co/forms.py
  27. 22  django/contrib/localflavor/cz/cz_regions.py
  28. 136  django/contrib/localflavor/cz/forms.py
  29. 21  django/contrib/localflavor/de/de_states.py
  30. 88  django/contrib/localflavor/de/forms.py
  31. 36  django/contrib/localflavor/ec/ec_provinces.py
  32. 15  django/contrib/localflavor/ec/forms.py
  33. 58  django/contrib/localflavor/es/es_provinces.py
  34. 23  django/contrib/localflavor/es/es_regions.py
  35. 189  django/contrib/localflavor/es/forms.py
  36. 355  django/contrib/localflavor/fi/fi_municipalities.py
  37. 55  django/contrib/localflavor/fi/forms.py
  38. 57  django/contrib/localflavor/fr/forms.py
  39. 118  django/contrib/localflavor/fr/fr_department.py
  40. 55  django/contrib/localflavor/gb/forms.py
  41. 97  django/contrib/localflavor/gb/gb_regions.py
  42. 48  django/contrib/localflavor/generic/forms.py
  43. 71  django/contrib/localflavor/hk/forms.py
  44. 282  django/contrib/localflavor/hr/forms.py
  45. 112  django/contrib/localflavor/hr/hr_choices.py
  46. 217  django/contrib/localflavor/id/forms.py
  47. 107  django/contrib/localflavor/id/id_choices.py
  48. 16  django/contrib/localflavor/ie/forms.py
  49. 40  django/contrib/localflavor/ie/ie_counties.py
  50. 67  django/contrib/localflavor/il/forms.py
  51. 115  django/contrib/localflavor/in_/forms.py
  52. 133  django/contrib/localflavor/in_/in_states.py
  53. 86  django/contrib/localflavor/is_/forms.py
  54. 152  django/contrib/localflavor/is_/is_postalcodes.py
  55. 88  django/contrib/localflavor/it/forms.py
  56. 115  django/contrib/localflavor/it/it_province.py
  57. 25  django/contrib/localflavor/it/it_region.py
  58. 44  django/contrib/localflavor/it/util.py
  59. 39  django/contrib/localflavor/jp/forms.py
  60. 51  django/contrib/localflavor/jp/jp_prefectures.py
  61. 65  django/contrib/localflavor/kw/forms.py
  62. BIN  django/contrib/localflavor/locale/ar/LC_MESSAGES/django.mo
  63. 3,534  django/contrib/localflavor/locale/ar/LC_MESSAGES/django.po
  64. BIN  django/contrib/localflavor/locale/az/LC_MESSAGES/django.mo
  65. 3,543  django/contrib/localflavor/locale/az/LC_MESSAGES/django.po
  66. BIN  django/contrib/localflavor/locale/bg/LC_MESSAGES/django.mo
  67. 3,548  django/contrib/localflavor/locale/bg/LC_MESSAGES/django.po
  68. BIN  django/contrib/localflavor/locale/bn/LC_MESSAGES/django.mo
  69. 3,527  django/contrib/localflavor/locale/bn/LC_MESSAGES/django.po
  70. BIN  django/contrib/localflavor/locale/bs/LC_MESSAGES/django.mo
  71. 3,542  django/contrib/localflavor/locale/bs/LC_MESSAGES/django.po
  72. BIN  django/contrib/localflavor/locale/ca/LC_MESSAGES/django.mo
  73. 3,566  django/contrib/localflavor/locale/ca/LC_MESSAGES/django.po
  74. BIN  django/contrib/localflavor/locale/cs/LC_MESSAGES/django.mo
  75. 3,545  django/contrib/localflavor/locale/cs/LC_MESSAGES/django.po
  76. BIN  django/contrib/localflavor/locale/cy/LC_MESSAGES/django.mo
  77. 3,527  django/contrib/localflavor/locale/cy/LC_MESSAGES/django.po
  78. BIN  django/contrib/localflavor/locale/da/LC_MESSAGES/django.mo
  79. 3,551  django/contrib/localflavor/locale/da/LC_MESSAGES/django.po
  80. BIN  django/contrib/localflavor/locale/de/LC_MESSAGES/django.mo
  81. 3,567  django/contrib/localflavor/locale/de/LC_MESSAGES/django.po
  82. BIN  django/contrib/localflavor/locale/el/LC_MESSAGES/django.mo
  83. 3,556  django/contrib/localflavor/locale/el/LC_MESSAGES/django.po
  84. BIN  django/contrib/localflavor/locale/en/LC_MESSAGES/django.mo
  85. 3,546  django/contrib/localflavor/locale/en/LC_MESSAGES/django.po
  86. BIN  django/contrib/localflavor/locale/en_GB/LC_MESSAGES/django.mo
  87. 3,544  django/contrib/localflavor/locale/en_GB/LC_MESSAGES/django.po
  88. BIN  django/contrib/localflavor/locale/eo/LC_MESSAGES/django.mo
  89. 0  localflavor/ar/__init__.py b/django/contrib/localflavor/ar/__init__.py
  90. 0  localflavor/at/__init__.py b/django/contrib/localflavor/at/__init__.py
  91. 0  localflavor/au/__init__.py b/django/contrib/localflavor/au/__init__.py
  92. 0  localflavor/be/__init__.py b/django/contrib/localflavor/be/__init__.py
  93. 0  localflavor/br/__init__.py b/django/contrib/localflavor/br/__init__.py
  94. 0  localflavor/ca/__init__.py b/django/contrib/localflavor/ca/__init__.py
  95. 0  localflavor/ch/__init__.py b/django/contrib/localflavor/ch/__init__.py
  96. 0  localflavor/cl/__init__.py b/django/contrib/localflavor/cl/__init__.py
  97. 0  localflavor/cn/__init__.py b/django/contrib/localflavor/cn/__init__.py
  98. 0  localflavor/co/__init__.py b/django/contrib/localflavor/co/__init__.py
  99. 0  localflavor/cz/__init__.py b/django/contrib/localflavor/cz/__init__.py
  100. 0  localflavor/de/__init__.py b/django/contrib/localflavor/de/__init__.py
  101. 0  localflavor/ec/__init__.py b/django/contrib/localflavor/ec/__init__.py
  102. 0  localflavor/es/__init__.py b/django/contrib/localflavor/es/__init__.py
  103. 0  localflavor/fi/__init__.py b/django/contrib/localflavor/fi/__init__.py
  104. 0  localflavor/fr/__init__.py b/django/contrib/localflavor/fr/__init__.py
  105. 0  localflavor/gb/__init__.py b/django/contrib/localflavor/gb/__init__.py
  106. 0  localflavor/generic/__init__.py b/django/contrib/localflavor/generic/__init__.py
  107. 0  localflavor/hk/__init__.py b/django/contrib/localflavor/hk/__init__.py
  108. 0  localflavor/hr/__init__.py b/django/contrib/localflavor/hr/__init__.py
  109. 0  localflavor/id/__init__.py b/django/contrib/localflavor/id/__init__.py
  110. 0  localflavor/ie/__init__.py b/django/contrib/localflavor/ie/__init__.py
  111. 0  localflavor/il/__init__.py b/django/contrib/localflavor/il/__init__.py
  112. 0  localflavor/in_/__init__.py b/django/contrib/localflavor/in_/__init__.py
  113. 0  localflavor/is_/__init__.py b/django/contrib/localflavor/is_/__init__.py
  114. 0  localflavor/it/__init__.py b/django/contrib/localflavor/it/__init__.py
  115. 0  localflavor/jp/__init__.py b/django/contrib/localflavor/jp/__init__.py
  116. 0  localflavor/kw/__init__.py b/django/contrib/localflavor/kw/__init__.py
5  .tx/config
@@ -57,11 +57,6 @@ file_filter = django/contrib/humanize/locale/<lang>/LC_MESSAGES/django.po
57 57
 source_file = django/contrib/humanize/locale/en/LC_MESSAGES/django.po
58 58
 source_lang = en
59 59
 
60  
-[django.contrib-localflavor]
61  
-file_filter = django/contrib/localflavor/locale/<lang>/LC_MESSAGES/django.po
62  
-source_file = django/contrib/localflavor/locale/en/LC_MESSAGES/django.po
63  
-source_lang = en
64  
-
65 60
 [django.contrib-messages]
66 61
 file_filter = django/contrib/messages/locale/<lang>/LC_MESSAGES/django.po
67 62
 source_file = django/contrib/messages/locale/en/LC_MESSAGES/django.po
3  django/contrib/gis/tests/relatedapp/models.py
... ...
@@ -1,5 +1,4 @@
1 1
 from django.contrib.gis.db import models
2  
-from django.contrib.localflavor.us.models import USStateField
3 2
 from django.utils.encoding import python_2_unicode_compatible
4 3
 
5 4
 @python_2_unicode_compatible
@@ -11,7 +10,7 @@ def __str__(self): return self.point.wkt
11 10
 @python_2_unicode_compatible
12 11
 class City(models.Model):
13 12
     name = models.CharField(max_length=50)
14  
-    state = USStateField()
  13
+    state = models.CharField(max_length=2)
15 14
     location = models.ForeignKey(Location)
16 15
     objects = models.GeoManager()
17 16
     def __str__(self): return self.name
2  django/contrib/gis/utils/layermapping.py
@@ -16,7 +16,6 @@
16 16
 from django.contrib.gis.gdal.field import (
17 17
     OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime)
18 18
 from django.db import models, transaction
19  
-from django.contrib.localflavor.us.models import USStateField
20 19
 from django.utils import six
21 20
 from django.utils.encoding import force_text
22 21
 
@@ -55,7 +54,6 @@ class LayerMapping(object):
55 54
         models.SlugField : OFTString,
56 55
         models.TextField : OFTString,
57 56
         models.URLField : OFTString,
58  
-        USStateField : OFTString,
59 57
         models.BigIntegerField : (OFTInteger, OFTReal, OFTString),
60 58
         models.SmallIntegerField : (OFTInteger, OFTReal, OFTString),
61 59
         models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
2  django/contrib/localflavor/__init__.py
... ...
@@ -1,2 +0,0 @@
1  
-import warnings
2  
-warnings.warn("django.contrib.localflavor is deprecated. Use the separate django-localflavor-* packages instead.", DeprecationWarning)
37  django/contrib/localflavor/ar/ar_provinces.py
... ...
@@ -1,37 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-A list of Argentinean provinces and autonomous cities as `choices` in a
4  
-formfield. From
5  
-http://www.argentina.gov.ar/argentina/portal/paginas.dhtml?pagina=425
6  
-
7  
-This exists in this standalone file so that it's only imported into memory
8  
-when explicitly needed.
9  
-"""
10  
-from __future__ import unicode_literals
11  
-
12  
-PROVINCE_CHOICES = (
13  
-    ('B', 'Buenos Aires'),
14  
-    ('K', 'Catamarca'),
15  
-    ('H', 'Chaco'),
16  
-    ('U', 'Chubut'),
17  
-    ('C', 'Ciudad Autónoma de Buenos Aires'),
18  
-    ('X', 'Córdoba'),
19  
-    ('W', 'Corrientes'),
20  
-    ('E', 'Entre Ríos'),
21  
-    ('P', 'Formosa'),
22  
-    ('Y', 'Jujuy'),
23  
-    ('L', 'La Pampa'),
24  
-    ('F', 'La Rioja'),
25  
-    ('M', 'Mendoza'),
26  
-    ('N', 'Misiones'),
27  
-    ('Q', 'Neuquén'),
28  
-    ('R', 'Río Negro'),
29  
-    ('A', 'Salta'),
30  
-    ('J', 'San Juan'),
31  
-    ('D', 'San Luis'),
32  
-    ('Z', 'Santa Cruz'),
33  
-    ('S', 'Santa Fe'),
34  
-    ('G', 'Santiago del Estero'),
35  
-    ('V', 'Tierra del Fuego, Antártida e Islas del Atlántico Sur'),
36  
-    ('T', 'Tucumán'),
37  
-)
128  django/contrib/localflavor/ar/forms.py
... ...
@@ -1,128 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-AR-specific Form helpers.
4  
-"""
5  
-
6  
-from __future__ import absolute_import, unicode_literals
7  
-
8  
-from django.contrib.localflavor.ar.ar_provinces import PROVINCE_CHOICES
9  
-from django.core.validators import EMPTY_VALUES
10  
-from django.forms import ValidationError
11  
-from django.forms.fields import RegexField, CharField, Select
12  
-from django.utils.translation import ugettext_lazy as _
13  
-
14  
-
15  
-class ARProvinceSelect(Select):
16  
-    """
17  
-    A Select widget that uses a list of Argentinean provinces/autonomous cities
18  
-    as its choices.
19  
-    """
20  
-    def __init__(self, attrs=None):
21  
-        super(ARProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
22  
-
23  
-class ARPostalCodeField(RegexField):
24  
-    """
25  
-    A field that accepts a 'classic' NNNN Postal Code or a CPA.
26  
-
27  
-    See:
28  
-        http://www.correoargentino.com.ar/cpa/que_es
29  
-        http://www.correoargentino.com.ar/cpa/como_escribirlo
30  
-    """
31  
-    default_error_messages = {
32  
-        'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."),
33  
-    }
34  
-
35  
-    def __init__(self, max_length=8, min_length=4, *args, **kwargs):
36  
-        super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$',
37  
-            max_length, min_length, *args, **kwargs)
38  
-
39  
-    def clean(self, value):
40  
-        value = super(ARPostalCodeField, self).clean(value)
41  
-        if value in EMPTY_VALUES:
42  
-            return ''
43  
-        if len(value) not in (4, 8):
44  
-            raise ValidationError(self.error_messages['invalid'])
45  
-        if len(value) == 8:
46  
-            return '%s%s%s' % (value[0].upper(), value[1:5], value[5:].upper())
47  
-        return value
48  
-
49  
-class ARDNIField(CharField):
50  
-    """
51  
-    A field that validates 'Documento Nacional de Identidad' (DNI) numbers.
52  
-    """
53  
-    default_error_messages = {
54  
-        'invalid': _("This field requires only numbers."),
55  
-        'max_digits': _("This field requires 7 or 8 digits."),
56  
-    }
57  
-
58  
-    def __init__(self, max_length=10, min_length=7, *args, **kwargs):
59  
-        super(ARDNIField, self).__init__(max_length, min_length, *args,
60  
-                **kwargs)
61  
-
62  
-    def clean(self, value):
63  
-        """
64  
-        Value can be a string either in the [X]X.XXX.XXX or [X]XXXXXXX formats.
65  
-        """
66  
-        value = super(ARDNIField, self).clean(value)
67  
-        if value in EMPTY_VALUES:
68  
-            return ''
69  
-        if not value.isdigit():
70  
-            value = value.replace('.', '')
71  
-        if not value.isdigit():
72  
-            raise ValidationError(self.error_messages['invalid'])
73  
-        if len(value) not in (7, 8):
74  
-            raise ValidationError(self.error_messages['max_digits'])
75  
-
76  
-        return value
77  
-
78  
-class ARCUITField(RegexField):
79  
-    """
80  
-    This field validates a CUIT (Código Único de Identificación Tributaria). A
81  
-    CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit.
82  
-    """
83  
-    default_error_messages = {
84  
-        'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
85  
-        'checksum': _("Invalid CUIT."),
86  
-        'legal_type': _('Invalid legal type. Type must be 27, 20, 23 or 30.'),
87  
-    }
88  
-
89  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
90  
-        super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$',
91  
-            max_length, min_length, *args, **kwargs)
92  
-
93  
-    def clean(self, value):
94  
-        """
95  
-        Value can be either a string in the format XX-XXXXXXXX-X or an
96  
-        11-digit number.
97  
-        """
98  
-        value = super(ARCUITField, self).clean(value)
99  
-        if value in EMPTY_VALUES:
100  
-            return ''
101  
-        value, cd = self._canon(value)
102  
-        if not value[:2] in ['27', '20', '23', '30']:
103  
-            raise ValidationError(self.error_messages['legal_type'])
104  
-        if self._calc_cd(value) != cd:
105  
-            raise ValidationError(self.error_messages['checksum'])
106  
-        return self._format(value, cd)
107  
-
108  
-    def _canon(self, cuit):
109  
-        cuit = cuit.replace('-', '')
110  
-        return cuit[:-1], cuit[-1]
111  
-
112  
-    def _calc_cd(self, cuit):
113  
-        # Calculation code based on:
114  
-        # http://es.wikipedia.org/wiki/C%C3%B3digo_%C3%9Anico_de_Identificaci%C3%B3n_Tributaria
115  
-        mults = (5, 4, 3, 2, 7, 6, 5, 4, 3, 2)
116  
-        tmp = sum([m * int(cuit[idx]) for idx, m in enumerate(mults)])
117  
-        result = 11 - (tmp % 11)
118  
-        if result == 11:
119  
-            result = 0
120  
-        elif result == 10:
121  
-            result = 9
122  
-        return str(result)
123  
-
124  
-    def _format(self, cuit, check_digit=None):
125  
-        if check_digit is None:
126  
-            check_digit = cuit[-1]
127  
-            cuit = cuit[:-1]
128  
-        return '%s-%s-%s' % (cuit[:2], cuit[2:], check_digit)
14  django/contrib/localflavor/at/at_states.py
... ...
@@ -1,14 +0,0 @@
1  
-# -*- coding: utf-8 -*
2  
-from django.utils.translation import ugettext_lazy as _
3  
-
4  
-STATE_CHOICES = (
5  
-    ('BL', _('Burgenland')),
6  
-    ('KA', _('Carinthia')),
7  
-    ('NO', _('Lower Austria')),
8  
-    ('OO', _('Upper Austria')),
9  
-    ('SA', _('Salzburg')),
10  
-    ('ST', _('Styria')),
11  
-    ('TI', _('Tyrol')),
12  
-    ('VO', _('Vorarlberg')),
13  
-    ('WI', _('Vienna')),
14  
-)
69  django/contrib/localflavor/at/forms.py
... ...
@@ -1,69 +0,0 @@
1  
-"""
2  
-AT-specific Form helpers
3  
-"""
4  
-from __future__ import unicode_literals
5  
-import re
6  
-
7  
-from django.core.validators import EMPTY_VALUES
8  
-from django.forms import ValidationError
9  
-from django.forms.fields import Field, RegexField, Select
10  
-from django.utils.translation import ugettext_lazy as _
11  
-
12  
-re_ssn = re.compile(r'^\d{4} \d{6}')
13  
-
14  
-
15  
-class ATZipCodeField(RegexField):
16  
-    """
17  
-    A form field that validates its input is an Austrian postcode.
18  
-
19  
-    Accepts 4 digits (first digit must be greater than 0).
20  
-    """
21  
-    default_error_messages = {
22  
-        'invalid': _('Enter a zip code in the format XXXX.'),
23  
-    }
24  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
25  
-        super(ATZipCodeField, self).__init__(r'^[1-9]{1}\d{3}$',
26  
-                max_length, min_length, *args, **kwargs)
27  
-
28  
-class ATStateSelect(Select):
29  
-    """
30  
-    A Select widget that uses a list of AT states as its choices.
31  
-    """
32  
-    def __init__(self, attrs=None):
33  
-        from django.contrib.localflavor.at.at_states import STATE_CHOICES
34  
-        super(ATStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
35  
-
36  
-class ATSocialSecurityNumberField(Field):
37  
-    """
38  
-    Austrian Social Security numbers are composed of a 4 digits and 6 digits
39  
-    field. The latter represents in most cases the person's birthdate while
40  
-    the first 4 digits represent a 3-digits counter and a one-digit checksum.
41  
-
42  
-    The 6-digits field can also differ from the person's birthdate if the
43  
-    3-digits counter suffered an overflow.
44  
-
45  
-    This code is based on information available on
46  
-    http://de.wikipedia.org/wiki/Sozialversicherungsnummer#.C3.96sterreich
47  
-    """
48  
-
49  
-    default_error_messages = {
50  
-        'invalid': _('Enter a valid Austrian Social Security Number in XXXX XXXXXX format.'),
51  
-    }
52  
-
53  
-    def clean(self, value):
54  
-        value = super(ATSocialSecurityNumberField, self).clean(value)
55  
-        if value in EMPTY_VALUES:
56  
-            return ""
57  
-        if not re_ssn.search(value):
58  
-            raise ValidationError(self.error_messages['invalid'])
59  
-        sqnr, date = value.split(" ")
60  
-        sqnr, check = (sqnr[:3], (sqnr[3]))
61  
-        if int(sqnr) < 100:
62  
-           raise ValidationError(self.error_messages['invalid'])
63  
-        res = int(sqnr[0])*3 + int(sqnr[1])*7 + int(sqnr[2])*9 \
64  
-           + int(date[0])*5 + int(date[1])*8 + int(date[2])*4 \
65  
-           + int(date[3])*2 + int(date[4])*1 + int(date[5])*6
66  
-        res = res % 11
67  
-        if res != int(check):
68  
-           raise ValidationError(self.error_messages['invalid'])
69  
-        return '%s%s %s'%(sqnr, check, date,)
17  django/contrib/localflavor/au/au_states.py
... ...
@@ -1,17 +0,0 @@
1  
-"""
2  
-An alphabetical list of states for use as `choices` in a formfield.
3  
-
4  
-This exists in this standalone file so that it's only imported into memory
5  
-when explicitly needed.
6  
-"""
7  
-
8  
-STATE_CHOICES = (
9  
-    ('ACT', 'Australian Capital Territory'),
10  
-    ('NSW', 'New South Wales'),
11  
-    ('NT', 'Northern Territory'),
12  
-    ('QLD', 'Queensland'),
13  
-    ('SA', 'South Australia'),
14  
-    ('TAS', 'Tasmania'),
15  
-    ('VIC', 'Victoria'),
16  
-    ('WA', 'Western Australia'),
17  
-)
60  django/contrib/localflavor/au/forms.py
... ...
@@ -1,60 +0,0 @@
1  
-"""
2  
-Australian-specific Form helpers
3  
-"""
4  
-
5  
-from __future__ import absolute_import, unicode_literals
6  
-
7  
-import re
8  
-
9  
-from django.contrib.localflavor.au.au_states import STATE_CHOICES
10  
-from django.core.validators import EMPTY_VALUES
11  
-from django.forms import ValidationError
12  
-from django.forms.fields import Field, RegexField, Select
13  
-from django.utils.encoding import smart_text
14  
-from django.utils.translation import ugettext_lazy as _
15  
-
16  
-
17  
-PHONE_DIGITS_RE = re.compile(r'^(\d{10})$')
18  
-
19  
-class AUPostCodeField(RegexField):
20  
-    """ Australian post code field.
21  
-
22  
-    Assumed to be 4 digits.
23  
-    Northern Territory 3-digit postcodes should have leading zero.
24  
-    """
25  
-    default_error_messages = {
26  
-        'invalid': _('Enter a 4 digit postcode.'),
27  
-    }
28  
-
29  
-    def __init__(self, max_length=4, min_length=None, *args, **kwargs):
30  
-        super(AUPostCodeField, self).__init__(r'^\d{4}$',
31  
-            max_length, min_length, *args, **kwargs)
32  
-
33  
-
34  
-class AUPhoneNumberField(Field):
35  
-    """Australian phone number field."""
36  
-    default_error_messages = {
37  
-        'invalid': 'Phone numbers must contain 10 digits.',
38  
-    }
39  
-
40  
-    def clean(self, value):
41  
-        """
42  
-        Validate a phone number. Strips parentheses, whitespace and hyphens.
43  
-        """
44  
-        super(AUPhoneNumberField, self).clean(value)
45  
-        if value in EMPTY_VALUES:
46  
-            return ''
47  
-        value = re.sub('(\(|\)|\s+|-)', '', smart_text(value))
48  
-        phone_match = PHONE_DIGITS_RE.search(value)
49  
-        if phone_match:
50  
-            return '%s' % phone_match.group(1)
51  
-        raise ValidationError(self.error_messages['invalid'])
52  
-
53  
-
54  
-class AUStateSelect(Select):
55  
-    """
56  
-    A Select widget that uses a list of Australian states/territories as its
57  
-    choices.
58  
-    """
59  
-    def __init__(self, attrs=None):
60  
-        super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
43  django/contrib/localflavor/au/models.py
... ...
@@ -1,43 +0,0 @@
1  
-from django.utils.translation import ugettext_lazy as _
2  
-from django.db.models.fields import CharField
3  
-
4  
-from django.contrib.localflavor.au.au_states import STATE_CHOICES
5  
-from django.contrib.localflavor.au import forms
6  
-
7  
-class AUStateField(CharField):
8  
-
9  
-    description = _("Australian State")
10  
-
11  
-    def __init__(self, *args, **kwargs):
12  
-        kwargs['choices'] = STATE_CHOICES
13  
-        kwargs['max_length'] = 3
14  
-        super(AUStateField, self).__init__(*args, **kwargs)
15  
-
16  
-
17  
-class AUPostCodeField(CharField):
18  
-
19  
-    description = _("Australian Postcode")
20  
-
21  
-    def __init__(self, *args, **kwargs):
22  
-        kwargs['max_length'] = 4
23  
-        super(AUPostCodeField, self).__init__(*args, **kwargs)
24  
-
25  
-    def formfield(self, **kwargs):
26  
-        defaults = {'form_class': forms.AUPostCodeField}
27  
-        defaults.update(kwargs)
28  
-        return super(AUPostCodeField, self).formfield(**defaults)
29  
-
30  
-
31  
-class AUPhoneNumberField(CharField):
32  
-
33  
-    description = _("Australian Phone number")
34  
-
35  
-    def __init__(self, *args, **kwargs):
36  
-        kwargs['max_length'] = 20
37  
-        super(AUPhoneNumberField, self).__init__(*args, **kwargs)
38  
-
39  
-    def formfield(self, **kwargs):
40  
-        defaults = {'form_class': forms.AUPhoneNumberField}
41  
-        defaults.update(kwargs)
42  
-        return super(AUPhoneNumberField, self).formfield(**defaults)
43  
-
16  django/contrib/localflavor/be/be_provinces.py
... ...
@@ -1,16 +0,0 @@
1  
-from django.utils.translation import ugettext_lazy as _
2  
-
3  
-# ISO codes
4  
-PROVINCE_CHOICES = (
5  
-    ('VAN', _('Antwerp')),
6  
-    ('BRU', _('Brussels')),
7  
-    ('VOV', _('East Flanders')),
8  
-    ('VBR', _('Flemish Brabant')),
9  
-    ('WHT', _('Hainaut')),
10  
-    ('WLG', _('Liege')),
11  
-    ('VLI', _('Limburg')),
12  
-    ('WLX', _('Luxembourg')),
13  
-    ('WNA', _('Namur')),
14  
-    ('WBR', _('Walloon Brabant')),
15  
-    ('VWV', _('West Flanders'))
16  
-)
8  django/contrib/localflavor/be/be_regions.py
... ...
@@ -1,8 +0,0 @@
1  
-from django.utils.translation import ugettext_lazy as _
2  
-
3  
-# ISO codes
4  
-REGION_CHOICES = (
5  
-    ('BRU', _('Brussels Capital Region')),
6  
-    ('VLG', _('Flemish Region')),
7  
-    ('WAL', _('Wallonia'))
8  
-)
71  django/contrib/localflavor/be/forms.py
... ...
@@ -1,71 +0,0 @@
1  
-"""
2  
-Belgium-specific Form helpers
3  
-"""
4  
-
5  
-from __future__ import absolute_import
6  
-
7  
-from django.contrib.localflavor.be.be_provinces import PROVINCE_CHOICES
8  
-from django.contrib.localflavor.be.be_regions import REGION_CHOICES
9  
-from django.forms.fields import RegexField, Select
10  
-from django.utils.translation import ugettext_lazy as _
11  
-
12  
-
13  
-class BEPostalCodeField(RegexField):
14  
-    """
15  
-    A form field that validates its input as a belgium postal code.
16  
-
17  
-    Belgium postal code is a 4 digits string. The first digit indicates
18  
-    the province (except for the 3ddd numbers that are shared by the
19  
-    eastern part of Flemish Brabant and Limburg and the and 1ddd that
20  
-    are shared by the Brussels Capital Region, the western part of
21  
-    Flemish Brabant and Walloon Brabant)
22  
-    """
23  
-    default_error_messages = {
24  
-        'invalid': _(
25  
-            'Enter a valid postal code in the range and format 1XXX - 9XXX.'),
26  
-    }
27  
-
28  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
29  
-        super(BEPostalCodeField, self).__init__(r'^[1-9]\d{3}$',
30  
-                max_length, min_length, *args, **kwargs)
31  
-
32  
-class BEPhoneNumberField(RegexField):
33  
-    """
34  
-    A form field that validates its input as a belgium phone number.
35  
-
36  
-    Landlines have a seven-digit subscriber number and a one-digit area code,
37  
-    while smaller cities have a six-digit subscriber number and a two-digit
38  
-    area code. Cell phones have a six-digit subscriber number and a two-digit
39  
-    area code preceeded by the number 4.
40  
-    0d ddd dd dd, 0d/ddd.dd.dd, 0d.ddd.dd.dd,
41  
-    0dddddddd - dialling a bigger city
42  
-    0dd dd dd dd, 0dd/dd.dd.dd, 0dd.dd.dd.dd,
43  
-    0dddddddd - dialling a smaller city
44  
-    04dd ddd dd dd, 04dd/ddd.dd.dd,
45  
-    04dd.ddd.dd.dd, 04ddddddddd - dialling a mobile number
46  
-    """
47  
-    default_error_messages = {
48  
-        'invalid': _('Enter a valid phone number in one of the formats '
49  
-                     '0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, '
50  
-                     '0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, '
51  
-                     '0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, '
52  
-                     '0xxxxxxxx or 04xxxxxxxx.'),
53  
-    }
54  
-
55  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
56  
-        super(BEPhoneNumberField, self).__init__(r'^[0]\d{1}[/. ]?\d{3}[. ]\d{2}[. ]?\d{2}$|^[0]\d{2}[/. ]?\d{2}[. ]?\d{2}[. ]?\d{2}$|^[0][4]\d{2}[/. ]?\d{2}[. ]?\d{2}[. ]?\d{2}$',
57  
-            max_length, min_length, *args, **kwargs)
58  
-
59  
-class BERegionSelect(Select):
60  
-    """
61  
-    A Select widget that uses a list of belgium regions as its choices.
62  
-    """
63  
-    def __init__(self, attrs=None):
64  
-        super(BERegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
65  
-
66  
-class BEProvinceSelect(Select):
67  
-    """
68  
-    A Select widget that uses a list of belgium provinces as its choices.
69  
-    """
70  
-    def __init__(self, attrs=None):
71  
-        super(BEProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
38  django/contrib/localflavor/br/br_states.py
... ...
@@ -1,38 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-An alphabetical list of Brazilian states for use as `choices` in a formfield.
4  
-
5  
-This exists in this standalone file so that it's only imported into memory
6  
-when explicitly needed.
7  
-"""
8  
-from __future__ import unicode_literals
9  
-
10  
-STATE_CHOICES = (
11  
-    ('AC', 'Acre'),
12  
-    ('AL', 'Alagoas'),
13  
-    ('AP', 'Amapá'),
14  
-    ('AM', 'Amazonas'),
15  
-    ('BA', 'Bahia'),
16  
-    ('CE', 'Ceará'),
17  
-    ('DF', 'Distrito Federal'),
18  
-    ('ES', 'Espírito Santo'),
19  
-    ('GO', 'Goiás'),
20  
-    ('MA', 'Maranhão'),
21  
-    ('MT', 'Mato Grosso'),
22  
-    ('MS', 'Mato Grosso do Sul'),
23  
-    ('MG', 'Minas Gerais'),
24  
-    ('PA', 'Pará'),
25  
-    ('PB', 'Paraíba'),
26  
-    ('PR', 'Paraná'),
27  
-    ('PE', 'Pernambuco'),
28  
-    ('PI', 'Piauí'),
29  
-    ('RJ', 'Rio de Janeiro'),
30  
-    ('RN', 'Rio Grande do Norte'),
31  
-    ('RS', 'Rio Grande do Sul'),
32  
-    ('RO', 'Rondônia'),
33  
-    ('RR', 'Roraima'),
34  
-    ('SC', 'Santa Catarina'),
35  
-    ('SP', 'São Paulo'),
36  
-    ('SE', 'Sergipe'),
37  
-    ('TO', 'Tocantins'),
38  
-)
166  django/contrib/localflavor/br/forms.py
... ...
@@ -1,166 +0,0 @@
1  
-# -*- coding: utf-8 -*-
2  
-"""
3  
-BR-specific Form helpers
4  
-"""
5  
-
6  
-from __future__ import absolute_import, unicode_literals
7  
-
8  
-import re
9  
-
10  
-from django.contrib.localflavor.br.br_states import STATE_CHOICES
11  
-from django.core.validators import EMPTY_VALUES
12  
-from django.forms import ValidationError
13  
-from django.forms.fields import Field, RegexField, CharField, Select
14  
-from django.utils.encoding import smart_text
15  
-from django.utils.translation import ugettext_lazy as _
16  
-
17  
-
18  
-phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$')
19  
-
20  
-class BRZipCodeField(RegexField):
21  
-    default_error_messages = {
22  
-        'invalid': _('Enter a zip code in the format XXXXX-XXX.'),
23  
-    }
24  
-
25  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
26  
-        super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$',
27  
-            max_length, min_length, *args, **kwargs)
28  
-
29  
-class BRPhoneNumberField(Field):
30  
-    default_error_messages = {
31  
-        'invalid': _('Phone numbers must be in XX-XXXX-XXXX format.'),
32  
-    }
33  
-
34  
-    def clean(self, value):
35  
-        super(BRPhoneNumberField, self).clean(value)
36  
-        if value in EMPTY_VALUES:
37  
-            return ''
38  
-        value = re.sub('(\(|\)|\s+)', '', smart_text(value))
39  
-        m = phone_digits_re.search(value)
40  
-        if m:
41  
-            return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
42  
-        raise ValidationError(self.error_messages['invalid'])
43  
-
44  
-class BRStateSelect(Select):
45  
-    """
46  
-    A Select widget that uses a list of Brazilian states/territories
47  
-    as its choices.
48  
-    """
49  
-    def __init__(self, attrs=None):
50  
-        super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
51  
-
52  
-class BRStateChoiceField(Field):
53  
-    """
54  
-    A choice field that uses a list of Brazilian states as its choices.
55  
-    """
56  
-    widget = Select
57  
-    default_error_messages = {
58  
-        'invalid': _('Select a valid brazilian state. That state is not one of the available states.'),
59  
-    }
60  
-
61  
-    def __init__(self, required=True, widget=None, label=None,
62  
-                 initial=None, help_text=None):
63  
-        super(BRStateChoiceField, self).__init__(required, widget, label,
64  
-                                                 initial, help_text)
65  
-        self.widget.choices = STATE_CHOICES
66  
-
67  
-    def clean(self, value):
68  
-        value = super(BRStateChoiceField, self).clean(value)
69  
-        if value in EMPTY_VALUES:
70  
-            value = ''
71  
-        value = smart_text(value)
72  
-        if value == '':
73  
-            return value
74  
-        valid_values = set([smart_text(k) for k, v in self.widget.choices])
75  
-        if value not in valid_values:
76  
-            raise ValidationError(self.error_messages['invalid'])
77  
-        return value
78  
-
79  
-def DV_maker(v):
80  
-    if v >= 2:
81  
-        return 11 - v
82  
-    return 0
83  
-
84  
-class BRCPFField(CharField):
85  
-    """
86  
-    This field validate a CPF number or a CPF string. A CPF number is
87  
-    compounded by XXX.XXX.XXX-VD. The two last digits are check digits.
88  
-
89  
-    More information:
90  
-    http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
91  
-    """
92  
-    default_error_messages = {
93  
-        'invalid': _("Invalid CPF number."),
94  
-        'max_digits': _("This field requires at most 11 digits or 14 characters."),
95  
-        'digits_only': _("This field requires only numbers."),
96  
-    }
97  
-
98  
-    def __init__(self, max_length=14, min_length=11, *args, **kwargs):
99  
-        super(BRCPFField, self).__init__(max_length, min_length, *args, **kwargs)
100  
-
101  
-    def clean(self, value):
102  
-        """
103  
-        Value can be either a string in the format XXX.XXX.XXX-XX or an
104  
-        11-digit number.
105  
-        """
106  
-        value = super(BRCPFField, self).clean(value)
107  
-        if value in EMPTY_VALUES:
108  
-            return ''
109  
-        orig_value = value[:]
110  
-        if not value.isdigit():
111  
-            value = re.sub("[-\.]", "", value)
112  
-        try:
113  
-            int(value)
114  
-        except ValueError:
115  
-            raise ValidationError(self.error_messages['digits_only'])
116  
-        if len(value) != 11:
117  
-            raise ValidationError(self.error_messages['max_digits'])
118  
-        orig_dv = value[-2:]
119  
-
120  
-        new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(range(10, 1, -1))])
121  
-        new_1dv = DV_maker(new_1dv % 11)
122  
-        value = value[:-2] + str(new_1dv) + value[-1]
123  
-        new_2dv = sum([i * int(value[idx]) for idx, i in enumerate(range(11, 1, -1))])
124  
-        new_2dv = DV_maker(new_2dv % 11)
125  
-        value = value[:-1] + str(new_2dv)
126  
-        if value[-2:] != orig_dv:
127  
-            raise ValidationError(self.error_messages['invalid'])
128  
-
129  
-        return orig_value
130  
-
131  
-class BRCNPJField(Field):
132  
-    default_error_messages = {
133  
-        'invalid': _("Invalid CNPJ number."),
134  
-        'digits_only': _("This field requires only numbers."),
135  
-        'max_digits': _("This field requires at least 14 digits"),
136  
-    }
137  
-
138  
-    def clean(self, value):
139  
-        """
140  
-        Value can be either a string in the format XX.XXX.XXX/XXXX-XX or a
141  
-        group of 14 characters.
142  
-        """
143  
-        value = super(BRCNPJField, self).clean(value)
144  
-        if value in EMPTY_VALUES:
145  
-            return ''
146  
-        orig_value = value[:]
147  
-        if not value.isdigit():
148  
-            value = re.sub("[-/\.]", "", value)
149  
-        try:
150  
-            int(value)
151  
-        except ValueError:
152  
-            raise ValidationError(self.error_messages['digits_only'])
153  
-        if len(value) != 14:
154  
-            raise ValidationError(self.error_messages['max_digits'])
155  
-        orig_dv = value[-2:]
156  
-
157  
-        new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(list(range(5, 1, -1)) + list(range(9, 1, -1)))])
158  
-        new_1dv = DV_maker(new_1dv % 11)
159  
-        value = value[:-2] + str(new_1dv) + value[-1]
160  
-        new_2dv = sum([i * int(value[idx]) for idx, i in enumerate(list(range(6, 1, -1)) + list(range(9, 1, -1)))])
161  
-        new_2dv = DV_maker(new_2dv % 11)
162  
-        value = value[:-1] + str(new_2dv)
163  
-        if value[-2:] != orig_dv:
164  
-            raise ValidationError(self.error_messages['invalid'])
165  
-
166  
-        return orig_value
63  django/contrib/localflavor/ca/ca_provinces.py
... ...
@@ -1,63 +0,0 @@
1  
-""" 
2  
-An alphabetical list of provinces and territories for use as `choices` 
3  
-in a formfield., and a mapping of province misspellings/abbreviations to 
4  
-normalized abbreviations
5  
-
6  
-Source: http://www.canada.gc.ca/othergov/prov_e.html 
7  
-
8  
-This exists in this standalone file so that it's only imported into memory 
9  
-when explicitly needed. 
10  
-""" 
11  
-
12  
-PROVINCE_CHOICES = ( 
13  
-    ('AB', 'Alberta'), 
14  
-    ('BC', 'British Columbia'), 
15  
-    ('MB', 'Manitoba'), 
16  
-    ('NB', 'New Brunswick'), 
17  
-    ('NL', 'Newfoundland and Labrador'),
18  
-    ('NT', 'Northwest Territories'), 
19  
-    ('NS', 'Nova Scotia'), 
20  
-    ('NU', 'Nunavut'), 
21  
-    ('ON', 'Ontario'), 
22  
-    ('PE', 'Prince Edward Island'), 
23  
-    ('QC', 'Quebec'), 
24  
-    ('SK', 'Saskatchewan'), 
25  
-    ('YT', 'Yukon')
26  
-)
27  
-
28  
-PROVINCES_NORMALIZED = {
29  
-    'ab': 'AB',
30  
-    'alberta': 'AB',
31  
-    'bc': 'BC',
32  
-    'b.c.': 'BC',
33  
-    'british columbia': 'BC',
34  
-    'mb': 'MB',
35  
-    'manitoba': 'MB',
36  
-    'nb': 'NB',
37  
-    'new brunswick': 'NB',
38  
-    'nf': 'NL',
39  
-    'nl': 'NL',
40  
-    'newfoundland': 'NL',
41  
-    'newfoundland and labrador': 'NL',
42  
-    'nt': 'NT',
43  
-    'northwest territories': 'NT',
44  
-    'ns': 'NS',
45  
-    'nova scotia': 'NS',
46  
-    'nu': 'NU',
47  
-    'nunavut': 'NU',
48  
-    'on': 'ON',
49  
-    'ontario': 'ON',
50  
-    'pe': 'PE',
51  
-    'pei': 'PE',
52  
-    'p.e.i.': 'PE',
53  
-    'prince edward island': 'PE',
54  
-    'pq' : 'QC',
55  
-    'qc': 'QC',
56  
-    'quebec': 'QC',
57  
-    'sk': 'SK',
58  
-    'saskatchewan': 'SK',
59  
-    'yk': 'YT',
60  
-    'yt': 'YT',
61  
-    'yukon': 'YT',
62  
-    'yukon territory': 'YT',
63  
-}
148  django/contrib/localflavor/ca/forms.py
... ...
@@ -1,148 +0,0 @@
1  
-"""
2  
-Canada-specific Form helpers
3  
-"""
4  
-
5  
-from __future__ import absolute_import, unicode_literals
6  
-
7  
-import re
8  
-
9  
-from django.core.validators import EMPTY_VALUES
10  
-from django.forms import ValidationError
11  
-from django.forms.fields import Field, CharField, Select
12  
-from django.utils.encoding import smart_text
13  
-from django.utils.translation import ugettext_lazy as _
14  
-
15  
-
16  
-phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
17  
-sin_re = re.compile(r"^(\d{3})-(\d{3})-(\d{3})$")
18  
-
19  
-class CAPostalCodeField(CharField):
20  
-    """
21  
-    Canadian postal code field.
22  
-
23  
-    Validates against known invalid characters: D, F, I, O, Q, U
24  
-    Additionally the first character cannot be Z or W.
25  
-    For more info see:
26  
-    http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1402170
27  
-    """
28  
-    default_error_messages = {
29  
-        'invalid': _('Enter a postal code in the format XXX XXX.'),
30  
-    }
31  
-
32  
-    postcode_regex = re.compile(r'^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]) *(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$')
33  
-
34  
-    def clean(self, value):
35  
-        value = super(CAPostalCodeField, self).clean(value)
36  
-        if value in EMPTY_VALUES:
37  
-            return ''
38  
-        postcode = value.upper().strip()
39  
-        m = self.postcode_regex.match(postcode)
40  
-        if not m:
41  
-            raise ValidationError(self.default_error_messages['invalid'])
42  
-        return "%s %s" % (m.group(1), m.group(2))
43  
-
44  
-class CAPhoneNumberField(Field):
45  
-    """Canadian phone number field."""
46  
-    default_error_messages = {
47  
-        'invalid': _('Phone numbers must be in XXX-XXX-XXXX format.'),
48  
-    }
49  
-
50  
-    def clean(self, value):
51  
-        """Validate a phone number.
52  
-        """
53  
-        super(CAPhoneNumberField, self).clean(value)
54  
-        if value in EMPTY_VALUES:
55  
-            return ''
56  
-        value = re.sub('(\(|\)|\s+)', '', smart_text(value))
57  
-        m = phone_digits_re.search(value)
58  
-        if m:
59  
-            return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
60  
-        raise ValidationError(self.error_messages['invalid'])
61  
-
62  
-class CAProvinceField(Field):
63  
-    """
64  
-    A form field that validates its input is a Canadian province name or abbreviation.
65  
-    It normalizes the input to the standard two-leter postal service
66  
-    abbreviation for the given province.
67  
-    """
68  
-    default_error_messages = {
69  
-        'invalid': _('Enter a Canadian province or territory.'),
70  
-    }
71  
-
72  
-    def clean(self, value):
73  
-        super(CAProvinceField, self).clean(value)
74  
-        if value in EMPTY_VALUES:
75  
-            return ''
76  
-        try:
77  
-            value = value.strip().lower()
78  
-        except AttributeError:
79  
-            pass
80  
-        else:
81  
-            # Load data in memory only when it is required, see also #17275
82  
-            from .ca_provinces import PROVINCES_NORMALIZED
83  
-            try:
84  
-                return PROVINCES_NORMALIZED[value.strip().lower()]
85  
-            except KeyError:
86  
-                pass
87  
-        raise ValidationError(self.error_messages['invalid'])
88  
-
89  
-class CAProvinceSelect(Select):
90  
-    """
91  
-    A Select widget that uses a list of Canadian provinces and
92  
-    territories as its choices.
93  
-    """
94  
-    def __init__(self, attrs=None):
95  
-        # Load data in memory only when it is required, see also #17275
96  
-        from .ca_provinces import PROVINCE_CHOICES
97  
-        super(CAProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
98  
-
99  
-class CASocialInsuranceNumberField(Field):
100  
-    """
101  
-    A Canadian Social Insurance Number (SIN).
102  
-
103  
-    Checks the following rules to determine whether the number is valid:
104  
-
105  
-        * Conforms to the XXX-XXX-XXX format.
106  
-        * Passes the check digit process "Luhn Algorithm"
107  
-             See: http://en.wikipedia.org/wiki/Social_Insurance_Number
108  
-    """
109  
-    default_error_messages = {
110  
-        'invalid': _('Enter a valid Canadian Social Insurance number in XXX-XXX-XXX format.'),
111  
-    }
112  
-
113  
-    def clean(self, value):
114  
-        super(CASocialInsuranceNumberField, self).clean(value)
115  
-        if value in EMPTY_VALUES:
116  
-            return ''
117  
-
118  
-        match = re.match(sin_re, value)
119  
-        if not match:
120  
-            raise ValidationError(self.error_messages['invalid'])
121  
-
122  
-        number = '%s-%s-%s' % (match.group(1), match.group(2), match.group(3))
123  
-        check_number = '%s%s%s' % (match.group(1), match.group(2), match.group(3))
124  
-        if not self.luhn_checksum_is_valid(check_number):
125  
-            raise ValidationError(self.error_messages['invalid'])
126  
-        return number
127  
-
128  
-    def luhn_checksum_is_valid(self, number):
129  
-        """
130  
-        Checks to make sure that the SIN passes a luhn mod-10 checksum
131  
-        See: http://en.wikipedia.org/wiki/Luhn_algorithm
132  
-        """
133  
-
134  
-        sum = 0
135  
-        num_digits = len(number)
136  
-        oddeven = num_digits & 1
137  
-
138  
-        for count in range(0, num_digits):
139  
-            digit = int(number[count])
140  
-
141  
-            if not (( count & 1 ) ^ oddeven ):
142  
-                digit = digit * 2
143  
-            if digit > 9:
144  
-                digit = digit - 9
145  
-
146  
-            sum = sum + digit
147  
-
148  
-        return ( (sum % 10) == 0 )
31  django/contrib/localflavor/ch/ch_states.py
... ...
@@ -1,31 +0,0 @@
1  
-# -*- coding: utf-8 -*
2  
-from django.utils.translation import ugettext_lazy as _
3  
-
4  
-STATE_CHOICES = (
5  
-    ('AG', _('Aargau')),
6  
-    ('AI', _('Appenzell Innerrhoden')),
7  
-    ('AR', _('Appenzell Ausserrhoden')),
8  
-    ('BS', _('Basel-Stadt')),
9  
-    ('BL', _('Basel-Land')),
10  
-    ('BE', _('Berne')),
11  
-    ('FR', _('Fribourg')),
12  
-    ('GE', _('Geneva')),
13  
-    ('GL', _('Glarus')),
14  
-    ('GR', _('Graubuenden')),
15  
-    ('JU', _('Jura')),
16  
-    ('LU', _('Lucerne')),
17  
-    ('NE', _('Neuchatel')),
18  
-    ('NW', _('Nidwalden')),
19  
-    ('OW', _('Obwalden')),
20  
-    ('SH', _('Schaffhausen')),
21  
-    ('SZ', _('Schwyz')),
22  
-    ('SO', _('Solothurn')),
23  
-    ('SG', _('St. Gallen')),
24  
-    ('TG', _('Thurgau')),
25  
-    ('TI', _('Ticino')),
26  
-    ('UR', _('Uri')),
27  
-    ('VS', _('Valais')),
28  
-    ('VD', _('Vaud')),
29  
-    ('ZG', _('Zug')),
30  
-    ('ZH', _('Zurich'))
31  
-)
122  django/contrib/localflavor/ch/forms.py
... ...
@@ -1,122 +0,0 @@
1  
-"""
2  
-Swiss-specific Form helpers
3  
-"""
4  
-
5  
-from __future__ import absolute_import, unicode_literals
6  
-
7  
-import re
8  
-
9  
-from django.contrib.localflavor.ch.ch_states import STATE_CHOICES
10  
-from django.core.validators import EMPTY_VALUES
11  
-from django.forms import ValidationError
12  
-from django.forms.fields import Field, RegexField, Select
13  
-from django.utils.encoding import smart_text
14  
-from django.utils.translation import ugettext_lazy as _
15  
-
16  
-
17  
-id_re = re.compile(r"^(?P<idnumber>\w{8})(?P<pos9>(\d{1}|<))(?P<checksum>\d{1})$")
18  
-phone_digits_re = re.compile(r'^0([1-9]{1})\d{8}$')
19  
-
20  
-class CHZipCodeField(RegexField):
21  
-    default_error_messages = {
22  
-        'invalid': _('Enter a zip code in the format XXXX.'),
23  
-    }
24  
-
25  
-    def __init__(self, max_length=None, min_length=None, *args, **kwargs):
26  
-        super(CHZipCodeField, self).__init__(r'^\d{4}$',
27  
-        max_length, min_length, *args, **kwargs)
28  
-
29  
-class CHPhoneNumberField(Field):
30  
-    """
31  
-    Validate local Swiss phone number (not international ones)
32  
-    The correct format is '0XX XXX XX XX'.
33  
-    '0XX.XXX.XX.XX' and '0XXXXXXXXX' validate but are corrected to
34  
-    '0XX XXX XX XX'.
35  
-    """
36  
-    default_error_messages = {
37  
-        'invalid': _('Phone numbers must be in 0XX XXX XX XX format.'),
38  
-    }
39  
-
40  
-    def clean(self, value):
41  
-        super(CHPhoneNumberField, self).clean(value)
42  
-        if value in EMPTY_VALUES:
43  
-            return ''
44  
-        value = re.sub('(\.|\s|/|-)', '', smart_text(value))
45  
-        m = phone_digits_re.search(value)
46  
-        if m:
47  
-            return '%s %s %s %s' % (value[0:3], value[3:6], value[6:8], value[8:10])
48  
-        raise ValidationError(self.error_messages['invalid'])
49  
-
50  
-class CHStateSelect(Select):
51  
-    """
52  
-    A Select widget that uses a list of CH states as its choices.
53  
-    """
54  
-    def __init__(self, attrs=None):
55  
-        super(CHStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
56  
-
57  
-class CHIdentityCardNumberField(Field):
58  
-    """
59  
-    A Swiss identity card number.
60  
-
61  
-    Checks the following rules to determine whether the number is valid:
62  
-
63  
-        * Conforms to the X1234567<0 or 1234567890 format.
64  
-        * Included checksums match calculated checksums
65  
-
66  
-    """
67  
-    default_error_messages = {
68  
-        'invalid': _('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'),
69  
-    }
70  
-
71  
-    def has_valid_checksum(self, number):
72  
-        given_number, given_checksum = number[:-1], number[-1]
73  
-        new_number = given_number
74  
-        calculated_checksum = 0