Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed django.contrib.localflavor.

Each localflavor lives on as a separate app.
  • Loading branch information...
commit f27a4ee3270bd57299ce02d622978ac4d839137e 1 parent b2d20e9
Aymeric Augustin aaugustin authored
Showing with 1 addition and 50,783 deletions.
  1. +0 −5 .tx/config
  2. +1 −2  django/contrib/gis/tests/relatedapp/models.py
  3. +0 −2  django/contrib/gis/utils/layermapping.py
  4. +0 −2  django/contrib/localflavor/__init__.py
  5. 0  django/contrib/localflavor/ar/__init__.py
  6. +0 −37 django/contrib/localflavor/ar/ar_provinces.py
  7. +0 −128 django/contrib/localflavor/ar/forms.py
  8. 0  django/contrib/localflavor/at/__init__.py
  9. +0 −14 django/contrib/localflavor/at/at_states.py
  10. +0 −69 django/contrib/localflavor/at/forms.py
  11. 0  django/contrib/localflavor/au/__init__.py
  12. +0 −17 django/contrib/localflavor/au/au_states.py
  13. +0 −60 django/contrib/localflavor/au/forms.py
  14. +0 −43 django/contrib/localflavor/au/models.py
  15. 0  django/contrib/localflavor/be/__init__.py
  16. +0 −16 django/contrib/localflavor/be/be_provinces.py
  17. +0 −8 django/contrib/localflavor/be/be_regions.py
  18. +0 −71 django/contrib/localflavor/be/forms.py
  19. 0  django/contrib/localflavor/br/__init__.py
  20. +0 −38 django/contrib/localflavor/br/br_states.py
  21. +0 −166 django/contrib/localflavor/br/forms.py
  22. 0  django/contrib/localflavor/ca/__init__.py
  23. +0 −63 django/contrib/localflavor/ca/ca_provinces.py
  24. +0 −148 django/contrib/localflavor/ca/forms.py
  25. 0  django/contrib/localflavor/ch/__init__.py
  26. +0 −31 django/contrib/localflavor/ch/ch_states.py
  27. +0 −122 django/contrib/localflavor/ch/forms.py
  28. 0  django/contrib/localflavor/cl/__init__.py
  29. +0 −26 django/contrib/localflavor/cl/cl_regions.py
  30. +0 −97 django/contrib/localflavor/cl/forms.py
  31. 0  django/contrib/localflavor/cn/__init__.py
  32. +0 −49 django/contrib/localflavor/cn/cn_provinces.py
  33. +0 −214 django/contrib/localflavor/cn/forms.py
  34. 0  django/contrib/localflavor/co/__init__.py
  35. +0 −45 django/contrib/localflavor/co/co_departments.py
  36. +0 −16 django/contrib/localflavor/co/forms.py
  37. 0  django/contrib/localflavor/cz/__init__.py
  38. +0 −22 django/contrib/localflavor/cz/cz_regions.py
  39. +0 −136 django/contrib/localflavor/cz/forms.py
  40. 0  django/contrib/localflavor/de/__init__.py
  41. +0 −21 django/contrib/localflavor/de/de_states.py
  42. +0 −88 django/contrib/localflavor/de/forms.py
  43. 0  django/contrib/localflavor/ec/__init__.py
  44. +0 −36 django/contrib/localflavor/ec/ec_provinces.py
  45. +0 −15 django/contrib/localflavor/ec/forms.py
  46. 0  django/contrib/localflavor/es/__init__.py
  47. +0 −58 django/contrib/localflavor/es/es_provinces.py
  48. +0 −23 django/contrib/localflavor/es/es_regions.py
  49. +0 −189 django/contrib/localflavor/es/forms.py
  50. 0  django/contrib/localflavor/fi/__init__.py
  51. +0 −355 django/contrib/localflavor/fi/fi_municipalities.py
  52. +0 −55 django/contrib/localflavor/fi/forms.py
  53. 0  django/contrib/localflavor/fr/__init__.py
  54. +0 −57 django/contrib/localflavor/fr/forms.py
  55. +0 −118 django/contrib/localflavor/fr/fr_department.py
  56. 0  django/contrib/localflavor/gb/__init__.py
  57. +0 −55 django/contrib/localflavor/gb/forms.py
  58. +0 −97 django/contrib/localflavor/gb/gb_regions.py
  59. 0  django/contrib/localflavor/generic/__init__.py
  60. +0 −48 django/contrib/localflavor/generic/forms.py
  61. 0  django/contrib/localflavor/hk/__init__.py
  62. +0 −71 django/contrib/localflavor/hk/forms.py
  63. 0  django/contrib/localflavor/hr/__init__.py
  64. +0 −282 django/contrib/localflavor/hr/forms.py
  65. +0 −112 django/contrib/localflavor/hr/hr_choices.py
  66. 0  django/contrib/localflavor/id/__init__.py
  67. +0 −217 django/contrib/localflavor/id/forms.py
  68. +0 −107 django/contrib/localflavor/id/id_choices.py
  69. 0  django/contrib/localflavor/ie/__init__.py
  70. +0 −16 django/contrib/localflavor/ie/forms.py
  71. +0 −40 django/contrib/localflavor/ie/ie_counties.py
  72. 0  django/contrib/localflavor/il/__init__.py
  73. +0 −67 django/contrib/localflavor/il/forms.py
  74. 0  django/contrib/localflavor/in_/__init__.py
  75. +0 −115 django/contrib/localflavor/in_/forms.py
  76. +0 −133 django/contrib/localflavor/in_/in_states.py
  77. 0  django/contrib/localflavor/is_/__init__.py
  78. +0 −86 django/contrib/localflavor/is_/forms.py
  79. +0 −152 django/contrib/localflavor/is_/is_postalcodes.py
  80. 0  django/contrib/localflavor/it/__init__.py
  81. +0 −88 django/contrib/localflavor/it/forms.py
  82. +0 −115 django/contrib/localflavor/it/it_province.py
  83. +0 −25 django/contrib/localflavor/it/it_region.py
  84. +0 −44 django/contrib/localflavor/it/util.py
  85. 0  django/contrib/localflavor/jp/__init__.py
  86. +0 −39 django/contrib/localflavor/jp/forms.py
  87. +0 −51 django/contrib/localflavor/jp/jp_prefectures.py
  88. 0  django/contrib/localflavor/kw/__init__.py
  89. +0 −65 django/contrib/localflavor/kw/forms.py
  90. BIN  django/contrib/localflavor/locale/ar/LC_MESSAGES/django.mo
  91. +0 −3,534 django/contrib/localflavor/locale/ar/LC_MESSAGES/django.po
  92. BIN  django/contrib/localflavor/locale/az/LC_MESSAGES/django.mo
  93. +0 −3,543 django/contrib/localflavor/locale/az/LC_MESSAGES/django.po
  94. BIN  django/contrib/localflavor/locale/bg/LC_MESSAGES/django.mo
  95. +0 −3,548 django/contrib/localflavor/locale/bg/LC_MESSAGES/django.po
  96. BIN  django/contrib/localflavor/locale/bn/LC_MESSAGES/django.mo
  97. +0 −3,527 django/contrib/localflavor/locale/bn/LC_MESSAGES/django.po
  98. BIN  django/contrib/localflavor/locale/bs/LC_MESSAGES/django.mo
  99. +0 −3,542 django/contrib/localflavor/locale/bs/LC_MESSAGES/django.po
  100. BIN  django/contrib/localflavor/locale/ca/LC_MESSAGES/django.mo
  101. +0 −3,566 django/contrib/localflavor/locale/ca/LC_MESSAGES/django.po
  102. BIN  django/contrib/localflavor/locale/cs/LC_MESSAGES/django.mo
  103. +0 −3,545 django/contrib/localflavor/locale/cs/LC_MESSAGES/django.po
  104. BIN  django/contrib/localflavor/locale/cy/LC_MESSAGES/django.mo
  105. +0 −3,527 django/contrib/localflavor/locale/cy/LC_MESSAGES/django.po
  106. BIN  django/contrib/localflavor/locale/da/LC_MESSAGES/django.mo
  107. +0 −3,551 django/contrib/localflavor/locale/da/LC_MESSAGES/django.po
  108. BIN  django/contrib/localflavor/locale/de/LC_MESSAGES/django.mo
  109. +0 −3,567 django/contrib/localflavor/locale/de/LC_MESSAGES/django.po
  110. BIN  django/contrib/localflavor/locale/el/LC_MESSAGES/django.mo
  111. +0 −3,556 django/contrib/localflavor/locale/el/LC_MESSAGES/django.po
  112. BIN  django/contrib/localflavor/locale/en/LC_MESSAGES/django.mo
  113. +0 −3,546 django/contrib/localflavor/locale/en/LC_MESSAGES/django.po
  114. BIN  django/contrib/localflavor/locale/en_GB/LC_MESSAGES/django.mo
  115. +0 −3,544 django/contrib/localflavor/locale/en_GB/LC_MESSAGES/django.po
  116. BIN  django/contrib/localflavor/locale/eo/LC_MESSAGES/django.mo
Sorry, we could not display the entire diff because too many files (304) changed.
5 .tx/config
View
@@ -57,11 +57,6 @@ file_filter = django/contrib/humanize/locale/<lang>/LC_MESSAGES/django.po
source_file = django/contrib/humanize/locale/en/LC_MESSAGES/django.po
source_lang = en
-[django.contrib-localflavor]
-file_filter = django/contrib/localflavor/locale/<lang>/LC_MESSAGES/django.po
-source_file = django/contrib/localflavor/locale/en/LC_MESSAGES/django.po
-source_lang = en
-
[django.contrib-messages]
file_filter = django/contrib/messages/locale/<lang>/LC_MESSAGES/django.po
source_file = django/contrib/messages/locale/en/LC_MESSAGES/django.po
3  django/contrib/gis/tests/relatedapp/models.py
View
@@ -1,5 +1,4 @@
from django.contrib.gis.db import models
-from django.contrib.localflavor.us.models import USStateField
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
@@ -11,7 +10,7 @@ def __str__(self): return self.point.wkt
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=50)
- state = USStateField()
+ state = models.CharField(max_length=2)
location = models.ForeignKey(Location)
objects = models.GeoManager()
def __str__(self): return self.name
2  django/contrib/gis/utils/layermapping.py
View
@@ -16,7 +16,6 @@
from django.contrib.gis.gdal.field import (
OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime)
from django.db import models, transaction
-from django.contrib.localflavor.us.models import USStateField
from django.utils import six
from django.utils.encoding import force_text
@@ -55,7 +54,6 @@ class LayerMapping(object):
models.SlugField : OFTString,
models.TextField : OFTString,
models.URLField : OFTString,
- USStateField : OFTString,
models.BigIntegerField : (OFTInteger, OFTReal, OFTString),
models.SmallIntegerField : (OFTInteger, OFTReal, OFTString),
models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
2  django/contrib/localflavor/__init__.py
View
@@ -1,2 +0,0 @@
-import warnings
-warnings.warn("django.contrib.localflavor is deprecated. Use the separate django-localflavor-* packages instead.", DeprecationWarning)
0  django/contrib/localflavor/ar/__init__.py
View
No changes.
37 django/contrib/localflavor/ar/ar_provinces.py
View
@@ -1,37 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-A list of Argentinean provinces and autonomous cities as `choices` in a
-formfield. From
-http://www.argentina.gov.ar/argentina/portal/paginas.dhtml?pagina=425
-
-This exists in this standalone file so that it's only imported into memory
-when explicitly needed.
-"""
-from __future__ import unicode_literals
-
-PROVINCE_CHOICES = (
- ('B', 'Buenos Aires'),
- ('K', 'Catamarca'),
- ('H', 'Chaco'),
- ('U', 'Chubut'),
- ('C', 'Ciudad Autónoma de Buenos Aires'),
- ('X', 'Córdoba'),
- ('W', 'Corrientes'),
- ('E', 'Entre Ríos'),
- ('P', 'Formosa'),
- ('Y', 'Jujuy'),
- ('L', 'La Pampa'),
- ('F', 'La Rioja'),
- ('M', 'Mendoza'),
- ('N', 'Misiones'),
- ('Q', 'Neuquén'),
- ('R', 'Río Negro'),
- ('A', 'Salta'),
- ('J', 'San Juan'),
- ('D', 'San Luis'),
- ('Z', 'Santa Cruz'),
- ('S', 'Santa Fe'),
- ('G', 'Santiago del Estero'),
- ('V', 'Tierra del Fuego, Antártida e Islas del Atlántico Sur'),
- ('T', 'Tucumán'),
-)
128 django/contrib/localflavor/ar/forms.py
View
@@ -1,128 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-AR-specific Form helpers.
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-from django.contrib.localflavor.ar.ar_provinces import PROVINCE_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import RegexField, CharField, Select
-from django.utils.translation import ugettext_lazy as _
-
-
-class ARProvinceSelect(Select):
- """
- A Select widget that uses a list of Argentinean provinces/autonomous cities
- as its choices.
- """
- def __init__(self, attrs=None):
- super(ARProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
-
-class ARPostalCodeField(RegexField):
- """
- A field that accepts a 'classic' NNNN Postal Code or a CPA.
-
- See:
- http://www.correoargentino.com.ar/cpa/que_es
- http://www.correoargentino.com.ar/cpa/como_escribirlo
- """
- default_error_messages = {
- 'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."),
- }
-
- def __init__(self, max_length=8, min_length=4, *args, **kwargs):
- super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$',
- max_length, min_length, *args, **kwargs)
-
- def clean(self, value):
- value = super(ARPostalCodeField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- if len(value) not in (4, 8):
- raise ValidationError(self.error_messages['invalid'])
- if len(value) == 8:
- return '%s%s%s' % (value[0].upper(), value[1:5], value[5:].upper())
- return value
-
-class ARDNIField(CharField):
- """
- A field that validates 'Documento Nacional de Identidad' (DNI) numbers.
- """
- default_error_messages = {
- 'invalid': _("This field requires only numbers."),
- 'max_digits': _("This field requires 7 or 8 digits."),
- }
-
- def __init__(self, max_length=10, min_length=7, *args, **kwargs):
- super(ARDNIField, self).__init__(max_length, min_length, *args,
- **kwargs)
-
- def clean(self, value):
- """
- Value can be a string either in the [X]X.XXX.XXX or [X]XXXXXXX formats.
- """
- value = super(ARDNIField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- if not value.isdigit():
- value = value.replace('.', '')
- if not value.isdigit():
- raise ValidationError(self.error_messages['invalid'])
- if len(value) not in (7, 8):
- raise ValidationError(self.error_messages['max_digits'])
-
- return value
-
-class ARCUITField(RegexField):
- """
- This field validates a CUIT (Código Único de Identificación Tributaria). A
- CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit.
- """
- default_error_messages = {
- 'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
- 'checksum': _("Invalid CUIT."),
- 'legal_type': _('Invalid legal type. Type must be 27, 20, 23 or 30.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$',
- max_length, min_length, *args, **kwargs)
-
- def clean(self, value):
- """
- Value can be either a string in the format XX-XXXXXXXX-X or an
- 11-digit number.
- """
- value = super(ARCUITField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- value, cd = self._canon(value)
- if not value[:2] in ['27', '20', '23', '30']:
- raise ValidationError(self.error_messages['legal_type'])
- if self._calc_cd(value) != cd:
- raise ValidationError(self.error_messages['checksum'])
- return self._format(value, cd)
-
- def _canon(self, cuit):
- cuit = cuit.replace('-', '')
- return cuit[:-1], cuit[-1]
-
- def _calc_cd(self, cuit):
- # Calculation code based on:
- # http://es.wikipedia.org/wiki/C%C3%B3digo_%C3%9Anico_de_Identificaci%C3%B3n_Tributaria
- mults = (5, 4, 3, 2, 7, 6, 5, 4, 3, 2)
- tmp = sum([m * int(cuit[idx]) for idx, m in enumerate(mults)])
- result = 11 - (tmp % 11)
- if result == 11:
- result = 0
- elif result == 10:
- result = 9
- return str(result)
-
- def _format(self, cuit, check_digit=None):
- if check_digit is None:
- check_digit = cuit[-1]
- cuit = cuit[:-1]
- return '%s-%s-%s' % (cuit[:2], cuit[2:], check_digit)
0  django/contrib/localflavor/at/__init__.py
View
No changes.
14 django/contrib/localflavor/at/at_states.py
View
@@ -1,14 +0,0 @@
-# -*- coding: utf-8 -*
-from django.utils.translation import ugettext_lazy as _
-
-STATE_CHOICES = (
- ('BL', _('Burgenland')),
- ('KA', _('Carinthia')),
- ('NO', _('Lower Austria')),
- ('OO', _('Upper Austria')),
- ('SA', _('Salzburg')),
- ('ST', _('Styria')),
- ('TI', _('Tyrol')),
- ('VO', _('Vorarlberg')),
- ('WI', _('Vienna')),
-)
69 django/contrib/localflavor/at/forms.py
View
@@ -1,69 +0,0 @@
-"""
-AT-specific Form helpers
-"""
-from __future__ import unicode_literals
-import re
-
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-
-re_ssn = re.compile(r'^\d{4} \d{6}')
-
-
-class ATZipCodeField(RegexField):
- """
- A form field that validates its input is an Austrian postcode.
-
- Accepts 4 digits (first digit must be greater than 0).
- """
- default_error_messages = {
- 'invalid': _('Enter a zip code in the format XXXX.'),
- }
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(ATZipCodeField, self).__init__(r'^[1-9]{1}\d{3}$',
- max_length, min_length, *args, **kwargs)
-
-class ATStateSelect(Select):
- """
- A Select widget that uses a list of AT states as its choices.
- """
- def __init__(self, attrs=None):
- from django.contrib.localflavor.at.at_states import STATE_CHOICES
- super(ATStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
-
-class ATSocialSecurityNumberField(Field):
- """
- Austrian Social Security numbers are composed of a 4 digits and 6 digits
- field. The latter represents in most cases the person's birthdate while
- the first 4 digits represent a 3-digits counter and a one-digit checksum.
-
- The 6-digits field can also differ from the person's birthdate if the
- 3-digits counter suffered an overflow.
-
- This code is based on information available on
- http://de.wikipedia.org/wiki/Sozialversicherungsnummer#.C3.96sterreich
- """
-
- default_error_messages = {
- 'invalid': _('Enter a valid Austrian Social Security Number in XXXX XXXXXX format.'),
- }
-
- def clean(self, value):
- value = super(ATSocialSecurityNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ""
- if not re_ssn.search(value):
- raise ValidationError(self.error_messages['invalid'])
- sqnr, date = value.split(" ")
- sqnr, check = (sqnr[:3], (sqnr[3]))
- if int(sqnr) < 100:
- raise ValidationError(self.error_messages['invalid'])
- res = int(sqnr[0])*3 + int(sqnr[1])*7 + int(sqnr[2])*9 \
- + int(date[0])*5 + int(date[1])*8 + int(date[2])*4 \
- + int(date[3])*2 + int(date[4])*1 + int(date[5])*6
- res = res % 11
- if res != int(check):
- raise ValidationError(self.error_messages['invalid'])
- return '%s%s %s'%(sqnr, check, date,)
0  django/contrib/localflavor/au/__init__.py
View
No changes.
17 django/contrib/localflavor/au/au_states.py
View
@@ -1,17 +0,0 @@
-"""
-An alphabetical list of states for use as `choices` in a formfield.
-
-This exists in this standalone file so that it's only imported into memory
-when explicitly needed.
-"""
-
-STATE_CHOICES = (
- ('ACT', 'Australian Capital Territory'),
- ('NSW', 'New South Wales'),
- ('NT', 'Northern Territory'),
- ('QLD', 'Queensland'),
- ('SA', 'South Australia'),
- ('TAS', 'Tasmania'),
- ('VIC', 'Victoria'),
- ('WA', 'Western Australia'),
-)
60 django/contrib/localflavor/au/forms.py
View
@@ -1,60 +0,0 @@
-"""
-Australian-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.au.au_states import STATE_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select
-from django.utils.encoding import smart_text
-from django.utils.translation import ugettext_lazy as _
-
-
-PHONE_DIGITS_RE = re.compile(r'^(\d{10})$')
-
-class AUPostCodeField(RegexField):
- """ Australian post code field.
-
- Assumed to be 4 digits.
- Northern Territory 3-digit postcodes should have leading zero.
- """
- default_error_messages = {
- 'invalid': _('Enter a 4 digit postcode.'),
- }
-
- def __init__(self, max_length=4, min_length=None, *args, **kwargs):
- super(AUPostCodeField, self).__init__(r'^\d{4}$',
- max_length, min_length, *args, **kwargs)
-
-
-class AUPhoneNumberField(Field):
- """Australian phone number field."""
- default_error_messages = {
- 'invalid': 'Phone numbers must contain 10 digits.',
- }
-
- def clean(self, value):
- """
- Validate a phone number. Strips parentheses, whitespace and hyphens.
- """
- super(AUPhoneNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- value = re.sub('(\(|\)|\s+|-)', '', smart_text(value))
- phone_match = PHONE_DIGITS_RE.search(value)
- if phone_match:
- return '%s' % phone_match.group(1)
- raise ValidationError(self.error_messages['invalid'])
-
-
-class AUStateSelect(Select):
- """
- A Select widget that uses a list of Australian states/territories as its
- choices.
- """
- def __init__(self, attrs=None):
- super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
43 django/contrib/localflavor/au/models.py
View
@@ -1,43 +0,0 @@
-from django.utils.translation import ugettext_lazy as _
-from django.db.models.fields import CharField
-
-from django.contrib.localflavor.au.au_states import STATE_CHOICES
-from django.contrib.localflavor.au import forms
-
-class AUStateField(CharField):
-
- description = _("Australian State")
-
- def __init__(self, *args, **kwargs):
- kwargs['choices'] = STATE_CHOICES
- kwargs['max_length'] = 3
- super(AUStateField, self).__init__(*args, **kwargs)
-
-
-class AUPostCodeField(CharField):
-
- description = _("Australian Postcode")
-
- def __init__(self, *args, **kwargs):
- kwargs['max_length'] = 4
- super(AUPostCodeField, self).__init__(*args, **kwargs)
-
- def formfield(self, **kwargs):
- defaults = {'form_class': forms.AUPostCodeField}
- defaults.update(kwargs)
- return super(AUPostCodeField, self).formfield(**defaults)
-
-
-class AUPhoneNumberField(CharField):
-
- description = _("Australian Phone number")
-
- def __init__(self, *args, **kwargs):
- kwargs['max_length'] = 20
- super(AUPhoneNumberField, self).__init__(*args, **kwargs)
-
- def formfield(self, **kwargs):
- defaults = {'form_class': forms.AUPhoneNumberField}
- defaults.update(kwargs)
- return super(AUPhoneNumberField, self).formfield(**defaults)
-
0  django/contrib/localflavor/be/__init__.py
View
No changes.
16 django/contrib/localflavor/be/be_provinces.py
View
@@ -1,16 +0,0 @@
-from django.utils.translation import ugettext_lazy as _
-
-# ISO codes
-PROVINCE_CHOICES = (
- ('VAN', _('Antwerp')),
- ('BRU', _('Brussels')),
- ('VOV', _('East Flanders')),
- ('VBR', _('Flemish Brabant')),
- ('WHT', _('Hainaut')),
- ('WLG', _('Liege')),
- ('VLI', _('Limburg')),
- ('WLX', _('Luxembourg')),
- ('WNA', _('Namur')),
- ('WBR', _('Walloon Brabant')),
- ('VWV', _('West Flanders'))
-)
8 django/contrib/localflavor/be/be_regions.py
View
@@ -1,8 +0,0 @@
-from django.utils.translation import ugettext_lazy as _
-
-# ISO codes
-REGION_CHOICES = (
- ('BRU', _('Brussels Capital Region')),
- ('VLG', _('Flemish Region')),
- ('WAL', _('Wallonia'))
-)
71 django/contrib/localflavor/be/forms.py
View
@@ -1,71 +0,0 @@
-"""
-Belgium-specific Form helpers
-"""
-
-from __future__ import absolute_import
-
-from django.contrib.localflavor.be.be_provinces import PROVINCE_CHOICES
-from django.contrib.localflavor.be.be_regions import REGION_CHOICES
-from django.forms.fields import RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-
-
-class BEPostalCodeField(RegexField):
- """
- A form field that validates its input as a belgium postal code.
-
- Belgium postal code is a 4 digits string. The first digit indicates
- the province (except for the 3ddd numbers that are shared by the
- eastern part of Flemish Brabant and Limburg and the and 1ddd that
- are shared by the Brussels Capital Region, the western part of
- Flemish Brabant and Walloon Brabant)
- """
- default_error_messages = {
- 'invalid': _(
- 'Enter a valid postal code in the range and format 1XXX - 9XXX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(BEPostalCodeField, self).__init__(r'^[1-9]\d{3}$',
- max_length, min_length, *args, **kwargs)
-
-class BEPhoneNumberField(RegexField):
- """
- A form field that validates its input as a belgium phone number.
-
- Landlines have a seven-digit subscriber number and a one-digit area code,
- while smaller cities have a six-digit subscriber number and a two-digit
- area code. Cell phones have a six-digit subscriber number and a two-digit
- area code preceeded by the number 4.
- 0d ddd dd dd, 0d/ddd.dd.dd, 0d.ddd.dd.dd,
- 0dddddddd - dialling a bigger city
- 0dd dd dd dd, 0dd/dd.dd.dd, 0dd.dd.dd.dd,
- 0dddddddd - dialling a smaller city
- 04dd ddd dd dd, 04dd/ddd.dd.dd,
- 04dd.ddd.dd.dd, 04ddddddddd - dialling a mobile number
- """
- default_error_messages = {
- 'invalid': _('Enter a valid phone number in one of the formats '
- '0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, '
- '0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, '
- '0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, '
- '0xxxxxxxx or 04xxxxxxxx.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- 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}$',
- max_length, min_length, *args, **kwargs)
-
-class BERegionSelect(Select):
- """
- A Select widget that uses a list of belgium regions as its choices.
- """
- def __init__(self, attrs=None):
- super(BERegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
-
-class BEProvinceSelect(Select):
- """
- A Select widget that uses a list of belgium provinces as its choices.
- """
- def __init__(self, attrs=None):
- super(BEProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
0  django/contrib/localflavor/br/__init__.py
View
No changes.
38 django/contrib/localflavor/br/br_states.py
View
@@ -1,38 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-An alphabetical list of Brazilian states for use as `choices` in a formfield.
-
-This exists in this standalone file so that it's only imported into memory
-when explicitly needed.
-"""
-from __future__ import unicode_literals
-
-STATE_CHOICES = (
- ('AC', 'Acre'),
- ('AL', 'Alagoas'),
- ('AP', 'Amapá'),
- ('AM', 'Amazonas'),
- ('BA', 'Bahia'),
- ('CE', 'Ceará'),
- ('DF', 'Distrito Federal'),
- ('ES', 'Espírito Santo'),
- ('GO', 'Goiás'),
- ('MA', 'Maranhão'),
- ('MT', 'Mato Grosso'),
- ('MS', 'Mato Grosso do Sul'),
- ('MG', 'Minas Gerais'),
- ('PA', 'Pará'),
- ('PB', 'Paraíba'),
- ('PR', 'Paraná'),
- ('PE', 'Pernambuco'),
- ('PI', 'Piauí'),
- ('RJ', 'Rio de Janeiro'),
- ('RN', 'Rio Grande do Norte'),
- ('RS', 'Rio Grande do Sul'),
- ('RO', 'Rondônia'),
- ('RR', 'Roraima'),
- ('SC', 'Santa Catarina'),
- ('SP', 'São Paulo'),
- ('SE', 'Sergipe'),
- ('TO', 'Tocantins'),
-)
166 django/contrib/localflavor/br/forms.py
View
@@ -1,166 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-BR-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.br.br_states import STATE_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, CharField, Select
-from django.utils.encoding import smart_text
-from django.utils.translation import ugettext_lazy as _
-
-
-phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$')
-
-class BRZipCodeField(RegexField):
- default_error_messages = {
- 'invalid': _('Enter a zip code in the format XXXXX-XXX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$',
- max_length, min_length, *args, **kwargs)
-
-class BRPhoneNumberField(Field):
- default_error_messages = {
- 'invalid': _('Phone numbers must be in XX-XXXX-XXXX format.'),
- }
-
- def clean(self, value):
- super(BRPhoneNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- value = re.sub('(\(|\)|\s+)', '', smart_text(value))
- m = phone_digits_re.search(value)
- if m:
- return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
- raise ValidationError(self.error_messages['invalid'])
-
-class BRStateSelect(Select):
- """
- A Select widget that uses a list of Brazilian states/territories
- as its choices.
- """
- def __init__(self, attrs=None):
- super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
-
-class BRStateChoiceField(Field):
- """
- A choice field that uses a list of Brazilian states as its choices.
- """
- widget = Select
- default_error_messages = {
- 'invalid': _('Select a valid brazilian state. That state is not one of the available states.'),
- }
-
- def __init__(self, required=True, widget=None, label=None,
- initial=None, help_text=None):
- super(BRStateChoiceField, self).__init__(required, widget, label,
- initial, help_text)
- self.widget.choices = STATE_CHOICES
-
- def clean(self, value):
- value = super(BRStateChoiceField, self).clean(value)
- if value in EMPTY_VALUES:
- value = ''
- value = smart_text(value)
- if value == '':
- return value
- valid_values = set([smart_text(k) for k, v in self.widget.choices])
- if value not in valid_values:
- raise ValidationError(self.error_messages['invalid'])
- return value
-
-def DV_maker(v):
- if v >= 2:
- return 11 - v
- return 0
-
-class BRCPFField(CharField):
- """
- This field validate a CPF number or a CPF string. A CPF number is
- compounded by XXX.XXX.XXX-VD. The two last digits are check digits.
-
- More information:
- http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
- """
- default_error_messages = {
- 'invalid': _("Invalid CPF number."),
- 'max_digits': _("This field requires at most 11 digits or 14 characters."),
- 'digits_only': _("This field requires only numbers."),
- }
-
- def __init__(self, max_length=14, min_length=11, *args, **kwargs):
- super(BRCPFField, self).__init__(max_length, min_length, *args, **kwargs)
-
- def clean(self, value):
- """
- Value can be either a string in the format XXX.XXX.XXX-XX or an
- 11-digit number.
- """
- value = super(BRCPFField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- orig_value = value[:]
- if not value.isdigit():
- value = re.sub("[-\.]", "", value)
- try:
- int(value)
- except ValueError:
- raise ValidationError(self.error_messages['digits_only'])
- if len(value) != 11:
- raise ValidationError(self.error_messages['max_digits'])
- orig_dv = value[-2:]
-
- new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(range(10, 1, -1))])
- new_1dv = DV_maker(new_1dv % 11)
- value = value[:-2] + str(new_1dv) + value[-1]
- new_2dv = sum([i * int(value[idx]) for idx, i in enumerate(range(11, 1, -1))])
- new_2dv = DV_maker(new_2dv % 11)
- value = value[:-1] + str(new_2dv)
- if value[-2:] != orig_dv:
- raise ValidationError(self.error_messages['invalid'])
-
- return orig_value
-
-class BRCNPJField(Field):
- default_error_messages = {
- 'invalid': _("Invalid CNPJ number."),
- 'digits_only': _("This field requires only numbers."),
- 'max_digits': _("This field requires at least 14 digits"),
- }
-
- def clean(self, value):
- """
- Value can be either a string in the format XX.XXX.XXX/XXXX-XX or a
- group of 14 characters.
- """
- value = super(BRCNPJField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- orig_value = value[:]
- if not value.isdigit():
- value = re.sub("[-/\.]", "", value)
- try:
- int(value)
- except ValueError:
- raise ValidationError(self.error_messages['digits_only'])
- if len(value) != 14:
- raise ValidationError(self.error_messages['max_digits'])
- orig_dv = value[-2:]
-
- new_1dv = sum([i * int(value[idx]) for idx, i in enumerate(list(range(5, 1, -1)) + list(range(9, 1, -1)))])
- new_1dv = DV_maker(new_1dv % 11)
- value = value[:-2] + str(new_1dv) + value[-1]
- new_2dv = sum([i * int(value[idx]) for idx, i in enumerate(list(range(6, 1, -1)) + list(range(9, 1, -1)))])
- new_2dv = DV_maker(new_2dv % 11)
- value = value[:-1] + str(new_2dv)
- if value[-2:] != orig_dv:
- raise ValidationError(self.error_messages['invalid'])
-
- return orig_value
0  django/contrib/localflavor/ca/__init__.py
View
No changes.
63 django/contrib/localflavor/ca/ca_provinces.py
View
@@ -1,63 +0,0 @@
-"""
-An alphabetical list of provinces and territories for use as `choices`
-in a formfield., and a mapping of province misspellings/abbreviations to
-normalized abbreviations
-
-Source: http://www.canada.gc.ca/othergov/prov_e.html
-
-This exists in this standalone file so that it's only imported into memory
-when explicitly needed.
-"""
-
-PROVINCE_CHOICES = (
- ('AB', 'Alberta'),
- ('BC', 'British Columbia'),
- ('MB', 'Manitoba'),
- ('NB', 'New Brunswick'),
- ('NL', 'Newfoundland and Labrador'),
- ('NT', 'Northwest Territories'),
- ('NS', 'Nova Scotia'),
- ('NU', 'Nunavut'),
- ('ON', 'Ontario'),
- ('PE', 'Prince Edward Island'),
- ('QC', 'Quebec'),
- ('SK', 'Saskatchewan'),
- ('YT', 'Yukon')
-)
-
-PROVINCES_NORMALIZED = {
- 'ab': 'AB',
- 'alberta': 'AB',
- 'bc': 'BC',
- 'b.c.': 'BC',
- 'british columbia': 'BC',
- 'mb': 'MB',
- 'manitoba': 'MB',
- 'nb': 'NB',
- 'new brunswick': 'NB',
- 'nf': 'NL',
- 'nl': 'NL',
- 'newfoundland': 'NL',
- 'newfoundland and labrador': 'NL',
- 'nt': 'NT',
- 'northwest territories': 'NT',
- 'ns': 'NS',
- 'nova scotia': 'NS',
- 'nu': 'NU',
- 'nunavut': 'NU',
- 'on': 'ON',
- 'ontario': 'ON',
- 'pe': 'PE',
- 'pei': 'PE',
- 'p.e.i.': 'PE',
- 'prince edward island': 'PE',
- 'pq' : 'QC',
- 'qc': 'QC',
- 'quebec': 'QC',
- 'sk': 'SK',
- 'saskatchewan': 'SK',
- 'yk': 'YT',
- 'yt': 'YT',
- 'yukon': 'YT',
- 'yukon territory': 'YT',
-}
148 django/contrib/localflavor/ca/forms.py
View
@@ -1,148 +0,0 @@
-"""
-Canada-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, CharField, Select
-from django.utils.encoding import smart_text
-from django.utils.translation import ugettext_lazy as _
-
-
-phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
-sin_re = re.compile(r"^(\d{3})-(\d{3})-(\d{3})$")
-
-class CAPostalCodeField(CharField):
- """
- Canadian postal code field.
-
- Validates against known invalid characters: D, F, I, O, Q, U
- Additionally the first character cannot be Z or W.
- For more info see:
- http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1402170
- """
- default_error_messages = {
- 'invalid': _('Enter a postal code in the format XXX XXX.'),
- }
-
- postcode_regex = re.compile(r'^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]) *(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$')
-
- def clean(self, value):
- value = super(CAPostalCodeField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- postcode = value.upper().strip()
- m = self.postcode_regex.match(postcode)
- if not m:
- raise ValidationError(self.default_error_messages['invalid'])
- return "%s %s" % (m.group(1), m.group(2))
-
-class CAPhoneNumberField(Field):
- """Canadian phone number field."""
- default_error_messages = {
- 'invalid': _('Phone numbers must be in XXX-XXX-XXXX format.'),
- }
-
- def clean(self, value):
- """Validate a phone number.
- """
- super(CAPhoneNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- value = re.sub('(\(|\)|\s+)', '', smart_text(value))
- m = phone_digits_re.search(value)
- if m:
- return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
- raise ValidationError(self.error_messages['invalid'])
-
-class CAProvinceField(Field):
- """
- A form field that validates its input is a Canadian province name or abbreviation.
- It normalizes the input to the standard two-leter postal service
- abbreviation for the given province.
- """
- default_error_messages = {
- 'invalid': _('Enter a Canadian province or territory.'),
- }
-
- def clean(self, value):
- super(CAProvinceField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- try:
- value = value.strip().lower()
- except AttributeError:
- pass
- else:
- # Load data in memory only when it is required, see also #17275
- from .ca_provinces import PROVINCES_NORMALIZED
- try:
- return PROVINCES_NORMALIZED[value.strip().lower()]
- except KeyError:
- pass
- raise ValidationError(self.error_messages['invalid'])
-
-class CAProvinceSelect(Select):
- """
- A Select widget that uses a list of Canadian provinces and
- territories as its choices.
- """
- def __init__(self, attrs=None):
- # Load data in memory only when it is required, see also #17275
- from .ca_provinces import PROVINCE_CHOICES
- super(CAProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
-
-class CASocialInsuranceNumberField(Field):
- """
- A Canadian Social Insurance Number (SIN).
-
- Checks the following rules to determine whether the number is valid:
-
- * Conforms to the XXX-XXX-XXX format.
- * Passes the check digit process "Luhn Algorithm"
- See: http://en.wikipedia.org/wiki/Social_Insurance_Number
- """
- default_error_messages = {
- 'invalid': _('Enter a valid Canadian Social Insurance number in XXX-XXX-XXX format.'),
- }
-
- def clean(self, value):
- super(CASocialInsuranceNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
-
- match = re.match(sin_re, value)
- if not match:
- raise ValidationError(self.error_messages['invalid'])
-
- number = '%s-%s-%s' % (match.group(1), match.group(2), match.group(3))
- check_number = '%s%s%s' % (match.group(1), match.group(2), match.group(3))
- if not self.luhn_checksum_is_valid(check_number):
- raise ValidationError(self.error_messages['invalid'])
- return number
-
- def luhn_checksum_is_valid(self, number):
- """
- Checks to make sure that the SIN passes a luhn mod-10 checksum
- See: http://en.wikipedia.org/wiki/Luhn_algorithm
- """
-
- sum = 0
- num_digits = len(number)
- oddeven = num_digits & 1
-
- for count in range(0, num_digits):
- digit = int(number[count])
-
- if not (( count & 1 ) ^ oddeven ):
- digit = digit * 2
- if digit > 9:
- digit = digit - 9
-
- sum = sum + digit
-
- return ( (sum % 10) == 0 )
0  django/contrib/localflavor/ch/__init__.py
View
No changes.
31 django/contrib/localflavor/ch/ch_states.py
View
@@ -1,31 +0,0 @@
-# -*- coding: utf-8 -*
-from django.utils.translation import ugettext_lazy as _
-
-STATE_CHOICES = (
- ('AG', _('Aargau')),
- ('AI', _('Appenzell Innerrhoden')),
- ('AR', _('Appenzell Ausserrhoden')),
- ('BS', _('Basel-Stadt')),
- ('BL', _('Basel-Land')),
- ('BE', _('Berne')),
- ('FR', _('Fribourg')),
- ('GE', _('Geneva')),
- ('GL', _('Glarus')),
- ('GR', _('Graubuenden')),
- ('JU', _('Jura')),
- ('LU', _('Lucerne')),
- ('NE', _('Neuchatel')),
- ('NW', _('Nidwalden')),
- ('OW', _('Obwalden')),
- ('SH', _('Schaffhausen')),
- ('SZ', _('Schwyz')),
- ('SO', _('Solothurn')),
- ('SG', _('St. Gallen')),
- ('TG', _('Thurgau')),
- ('TI', _('Ticino')),
- ('UR', _('Uri')),
- ('VS', _('Valais')),
- ('VD', _('Vaud')),
- ('ZG', _('Zug')),
- ('ZH', _('Zurich'))
-)
122 django/contrib/localflavor/ch/forms.py
View
@@ -1,122 +0,0 @@
-"""
-Swiss-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.ch.ch_states import STATE_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select
-from django.utils.encoding import smart_text
-from django.utils.translation import ugettext_lazy as _
-
-
-id_re = re.compile(r"^(?P<idnumber>\w{8})(?P<pos9>(\d{1}|<))(?P<checksum>\d{1})$")
-phone_digits_re = re.compile(r'^0([1-9]{1})\d{8}$')
-
-class CHZipCodeField(RegexField):
- default_error_messages = {
- 'invalid': _('Enter a zip code in the format XXXX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(CHZipCodeField, self).__init__(r'^\d{4}$',
- max_length, min_length, *args, **kwargs)
-
-class CHPhoneNumberField(Field):
- """
- Validate local Swiss phone number (not international ones)
- The correct format is '0XX XXX XX XX'.
- '0XX.XXX.XX.XX' and '0XXXXXXXXX' validate but are corrected to
- '0XX XXX XX XX'.
- """
- default_error_messages = {
- 'invalid': _('Phone numbers must be in 0XX XXX XX XX format.'),
- }
-
- def clean(self, value):
- super(CHPhoneNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- value = re.sub('(\.|\s|/|-)', '', smart_text(value))
- m = phone_digits_re.search(value)
- if m:
- return '%s %s %s %s' % (value[0:3], value[3:6], value[6:8], value[8:10])
- raise ValidationError(self.error_messages['invalid'])
-
-class CHStateSelect(Select):
- """
- A Select widget that uses a list of CH states as its choices.
- """
- def __init__(self, attrs=None):
- super(CHStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
-
-class CHIdentityCardNumberField(Field):
- """
- A Swiss identity card number.
-
- Checks the following rules to determine whether the number is valid:
-
- * Conforms to the X1234567<0 or 1234567890 format.
- * Included checksums match calculated checksums
-
- """
- default_error_messages = {
- 'invalid': _('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'),
- }
-
- def has_valid_checksum(self, number):
- given_number, given_checksum = number[:-1], number[-1]
- new_number = given_number
- calculated_checksum = 0
- fragment = ""
- parameter = 7
-
- first = str(number[:1])
- if first.isalpha():
- num = ord(first.upper()) - 65
- if num < 0 or num > 8:
- return False
- new_number = str(num) + new_number[1:]
- new_number = new_number[:8] + '0'
-
- if not new_number.isdigit():
- return False
-
- for i in range(len(new_number)):
- fragment = int(new_number[i])*parameter
- calculated_checksum += fragment
-
- if parameter == 1:
- parameter = 7
- elif parameter == 3:
- parameter = 1
- elif parameter ==7:
- parameter = 3
-
- return str(calculated_checksum)[-1] == given_checksum
-
- def clean(self, value):
- super(CHIdentityCardNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
-
- match = re.match(id_re, value)
- if not match:
- raise ValidationError(self.error_messages['invalid'])
-
- idnumber, pos9, checksum = match.groupdict()['idnumber'], match.groupdict()['pos9'], match.groupdict()['checksum']
-
- if idnumber == '00000000' or \
- idnumber == 'A0000000':
- raise ValidationError(self.error_messages['invalid'])
-
- all_digits = "%s%s%s" % (idnumber, pos9, checksum)
- if not self.has_valid_checksum(all_digits):
- raise ValidationError(self.error_messages['invalid'])
-
- return '%s%s%s' % (idnumber, pos9, checksum)
-
0  django/contrib/localflavor/cl/__init__.py
View
No changes.
26 django/contrib/localflavor/cl/cl_regions.py
View
@@ -1,26 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-A list of Chilean regions as `choices` in a formfield.
-
-This exists in this standalone file so that it's only imported into memory
-when explicitly needed.
-"""
-from __future__ import unicode_literals
-
-REGION_CHOICES = (
- ('RM', 'Región Metropolitana de Santiago'),
- ('I', 'Región de Tarapacá'),
- ('II', 'Región de Antofagasta'),
- ('III', 'Región de Atacama'),
- ('IV', 'Región de Coquimbo'),
- ('V', 'Región de Valparaíso'),
- ('VI', 'Región del Libertador Bernardo O\'Higgins'),
- ('VII', 'Región del Maule'),
- ('VIII','Región del Bío Bío'),
- ('IX', 'Región de la Araucanía'),
- ('X', 'Región de los Lagos'),
- ('XI', 'Región de Aysén del General Carlos Ibáñez del Campo'),
- ('XII', 'Región de Magallanes y la Antártica Chilena'),
- ('XIV', 'Región de Los Ríos'),
- ('XV', 'Región de Arica-Parinacota'),
-)
97 django/contrib/localflavor/cl/forms.py
View
@@ -1,97 +0,0 @@
-"""
-Chile specific form helpers.
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import smart_text
-
-from .cl_regions import REGION_CHOICES
-
-class CLRegionSelect(Select):
- """
- A Select widget that uses a list of Chilean Regions (Regiones)
- as its choices.
- """
- def __init__(self, attrs=None):
- super(CLRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
-
-class CLRutField(RegexField):
- """
- Chilean "Rol Unico Tributario" (RUT) field. This is the Chilean national
- identification number.
-
- Samples for testing are available from
- https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html
- """
- default_error_messages = {
- 'invalid': _('Enter a valid Chilean RUT.'),
- 'strict': _('Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.'),
- 'checksum': _('The Chilean RUT is not valid.'),
- }
-
- def __init__(self, *args, **kwargs):
- if 'strict' in kwargs:
- del kwargs['strict']
- super(CLRutField, self).__init__(r'^(\d{1,2}\.)?\d{3}\.\d{3}-[\dkK]$',
- error_message=self.default_error_messages['strict'], *args, **kwargs)
- else:
- # In non-strict mode, accept RUTs that validate but do not exist in
- # the real world.
- super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', *args, **kwargs)
-
- def clean(self, value):
- """
- Check and clean the Chilean RUT.
- """
- super(CLRutField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- rut, verificador = self._canonify(value)
- if self._algorithm(rut) == verificador:
- return self._format(rut, verificador)
- else:
- raise ValidationError(self.error_messages['checksum'])
-
- def _algorithm(self, rut):
- """
- Takes RUT in pure canonical form, calculates the verifier digit.
- """
- suma = 0
- multi = 2
- for r in rut[::-1]:
- suma += int(r) * multi
- multi += 1
- if multi == 8:
- multi = 2
- return '0123456789K0'[11 - suma % 11]
-
- def _canonify(self, rut):
- """
- Turns the RUT into one normalized format. Returns a (rut, verifier)
- tuple.
- """
- rut = smart_text(rut).replace(' ', '').replace('.', '').replace('-', '')
- return rut[:-1], rut[-1].upper()
-
- def _format(self, code, verifier=None):
- """
- Formats the RUT from canonical form to the common string representation.
- If verifier=None, then the last digit in 'code' is the verifier.
- """
- if verifier is None:
- verifier = code[-1]
- code = code[:-1]
- while len(code) > 3 and '.' not in code[:3]:
- pos = code.find('.')
- if pos == -1:
- new_dot = -3
- else:
- new_dot = pos - 3
- code = code[:new_dot] + '.' + code[new_dot:]
- return '%s-%s' % (code, verifier)
-
0  django/contrib/localflavor/cn/__init__.py
View
No changes.
49 django/contrib/localflavor/cn/cn_provinces.py
View
@@ -1,49 +0,0 @@
-# -*- coding: utf-8 -*-
-
-"""
-An alphabetical list of provinces for use as `choices` in a formfield.
-
-Reference:
-http://en.wikipedia.org/wiki/ISO_3166-2:CN
-http://en.wikipedia.org/wiki/Province_%28China%29
-http://en.wikipedia.org/wiki/Direct-controlled_municipality
-http://en.wikipedia.org/wiki/Autonomous_regions_of_China
-"""
-from __future__ import unicode_literals
-
-CN_PROVINCE_CHOICES = (
- ("anhui", "安徽"),
- ("beijing", "北京"),
- ("chongqing", "重庆"),
- ("fujian", "福建"),
- ("gansu", "甘肃"),
- ("guangdong", "广东"),
- ("guangxi", "广西壮族自治区"),
- ("guizhou", "贵州"),
- ("hainan", "海南"),
- ("hebei", "河北"),
- ("heilongjiang", "黑龙江"),
- ("henan", "河南"),
- ("hongkong", "香港"),
- ("hubei", "湖北"),
- ("hunan", "湖南"),
- ("jiangsu", "江苏"),
- ("jiangxi", "江西"),
- ("jilin", "吉林"),
- ("liaoning", "辽宁"),
- ("macao", "澳门"),
- ("neimongol", "内蒙古自治区"),
- ("ningxia", "宁夏回族自治区"),
- ("qinghai", "青海"),
- ("shaanxi", "陕西"),
- ("shandong", "山东"),
- ("shanghai", "上海"),
- ("shanxi", "山西"),
- ("sichuan", "四川"),
- ("taiwan", "台湾"),
- ("tianjin", "天津"),
- ("xinjiang", "新疆维吾尔自治区"),
- ("xizang", "西藏自治区"),
- ("yunnan", "云南"),
- ("zhejiang", "浙江"),
-)
214 django/contrib/localflavor/cn/forms.py
View
@@ -1,214 +0,0 @@
-# -*- coding: utf-8 -*-
-
-"""
-Chinese-specific form helpers
-"""
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.cn.cn_provinces import CN_PROVINCE_CHOICES
-from django.forms import ValidationError
-from django.forms.fields import CharField, RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-
-
-__all__ = (
- 'CNProvinceSelect',
- 'CNPostCodeField',
- 'CNIDCardField',
- 'CNPhoneNumberField',
- 'CNCellNumberField',
-)
-
-
-ID_CARD_RE = r'^\d{15}(\d{2}[0-9xX])?$'
-POST_CODE_RE = r'^\d{6}$'
-PHONE_RE = r'^\d{3,4}-\d{7,8}(-\d+)?$'
-CELL_RE = r'^1[358]\d{9}$'
-
-# Valid location code used in id card checking algorithm
-CN_LOCATION_CODES = (
- 11, # Beijing
- 12, # Tianjin
- 13, # Hebei
- 14, # Shanxi
- 15, # Nei Mongol
- 21, # Liaoning
- 22, # Jilin
- 23, # Heilongjiang
- 31, # Shanghai
- 32, # Jiangsu
- 33, # Zhejiang
- 34, # Anhui
- 35, # Fujian
- 36, # Jiangxi
- 37, # Shandong
- 41, # Henan
- 42, # Hubei
- 43, # Hunan
- 44, # Guangdong
- 45, # Guangxi
- 46, # Hainan
- 50, # Chongqing
- 51, # Sichuan
- 52, # Guizhou
- 53, # Yunnan
- 54, # Xizang
- 61, # Shaanxi
- 62, # Gansu
- 63, # Qinghai
- 64, # Ningxia
- 65, # Xinjiang
- 71, # Taiwan
- 81, # Hong Kong
- 91, # Macao
-)
-
-class CNProvinceSelect(Select):
- """
- A select widget with list of Chinese provinces as choices.
- """
- def __init__(self, attrs=None):
- super(CNProvinceSelect, self).__init__(
- attrs, choices=CN_PROVINCE_CHOICES,
- )
-
-
-class CNPostCodeField(RegexField):
- """
- A form field that validates as Chinese post code.
- Valid code is XXXXXX where X is digit.
- """
- default_error_messages = {
- 'invalid': _('Enter a post code in the format XXXXXX.'),
- }
-
- def __init__(self, *args, **kwargs):
- super(CNPostCodeField, self).__init__(POST_CODE_RE, *args, **kwargs)
-
-
-class CNIDCardField(CharField):
- """
- A form field that validates as Chinese Identification Card Number.
-
- This field would check the following restrictions:
- * the length could only be 15 or 18.
- * if the length is 18, the last digit could be x or X.
- * has a valid checksum.(length 18 only)
- * has a valid birthdate.
- * has a valid location.
-
- The checksum algorithm is described in GB11643-1999.
- """
- default_error_messages = {
- 'invalid': _('ID Card Number consists of 15 or 18 digits.'),
- 'checksum': _('Invalid ID Card Number: Wrong checksum'),
- 'birthday': _('Invalid ID Card Number: Wrong birthdate'),
- 'location': _('Invalid ID Card Number: Wrong location code'),
- }
-
- def __init__(self, max_length=18, min_length=15, *args, **kwargs):
- super(CNIDCardField, self).__init__(max_length, min_length, *args,
- **kwargs)
-
- def clean(self, value):
- """
- Check whether the input is a valid ID Card Number.
- """
- # Check the length of the ID card number.
- super(CNIDCardField, self).clean(value)
- if not value:
- return ""
- # Check whether this ID card number has valid format
- if not re.match(ID_CARD_RE, value):
- raise ValidationError(self.error_messages['invalid'])
- # Check the birthday of the ID card number.
- if not self.has_valid_birthday(value):
- raise ValidationError(self.error_messages['birthday'])
- # Check the location of the ID card number.
- if not self.has_valid_location(value):
- raise ValidationError(self.error_messages['location'])
- # Check the checksum of the ID card number.
- value = value.upper()
- if not self.has_valid_checksum(value):
- raise ValidationError(self.error_messages['checksum'])
- return '%s' % value
-
- def has_valid_birthday(self, value):
- """
- This function would grab the birthdate from the ID card number and test
- whether it is a valid date.
- """
- from datetime import datetime
- if len(value) == 15:
- # 1st generation ID card
- time_string = value[6:12]
- format_string = "%y%m%d"
- else:
- # 2nd generation ID card
- time_string = value[6:14]
- format_string = "%Y%m%d"
- try:
- datetime.strptime(time_string, format_string)
- return True
- except ValueError:
- # invalid date
- return False
-
- def has_valid_location(self, value):
- """
- This method checks if the first two digits in the ID Card are valid.
- """
- return int(value[:2]) in CN_LOCATION_CODES
-
- def has_valid_checksum(self, value):
- """
- This method checks if the last letter/digit in value is valid
- according to the algorithm the ID Card follows.
- """
- # If the length of the number is not 18, then the number is a 1st
- # generation ID card number, and there is no checksum to be checked.
- if len(value) != 18:
- return True
- checksum_index = sum(
- map(
- lambda a,b:a*(ord(b)-ord('0')),
- (7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2),
- value[:17],
- ),
- ) % 11
- return '10X98765432'[checksum_index] == value[-1]
-
-
-class CNPhoneNumberField(RegexField):
- """
- A form field that validates as Chinese phone number
- A valid phone number could be like:
- 010-55555555
- Considering there might be extension phone numbers, so this could also be:
- 010-55555555-35
- """
- default_error_messages = {
- 'invalid': _('Enter a valid phone number.'),
- }
-
- def __init__(self, *args, **kwargs):
- super(CNPhoneNumberField, self).__init__(PHONE_RE, *args, **kwargs)
-
-
-class CNCellNumberField(RegexField):
- """
- A form field that validates as Chinese cell number
- A valid cell number could be like:
- 13012345678
- We used a rough rule here, the first digit should be 1, the second could be
- 3, 5 and 8, the rest could be what so ever.
- The length of the cell number should be 11.
- """
- default_error_messages = {
- 'invalid': _('Enter a valid cell number.'),
- }
-
- def __init__(self, *args, **kwargs):
- super(CNCellNumberField, self).__init__(CELL_RE, *args, **kwargs)
0  django/contrib/localflavor/co/__init__.py
View
No changes.
45 django/contrib/localflavor/co/co_departments.py
View
@@ -1,45 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-A list of Colombian departaments as `choices` in a
-formfield.
-
-This exists in this standalone file so that it's only
-imported into memory when explicitly needed.
-"""
-from __future__ import unicode_literals
-
-DEPARTMENT_CHOICES = (
- ('AMA', 'Amazonas'),
- ('ANT', 'Antioquia'),
- ('ARA', 'Arauca'),
- ('ATL', 'Atlántico'),
- ('DC', 'Bogotá'),
- ('BOL', 'Bolívar'),
- ('BOY', 'Boyacá'),
- ('CAL', 'Caldas'),
- ('CAQ', 'Caquetá'),
- ('CAS', 'Casanare'),
- ('CAU', 'Cauca'),
- ('CES', 'Cesar'),
- ('CHO', 'Chocó'),
- ('COR', 'Córdoba'),
- ('CUN', 'Cundinamarca'),
- ('GUA', 'Guainía'),
- ('GUV', 'Guaviare'),
- ('HUI', 'Huila'),
- ('LAG', 'La Guajira'),
- ('MAG', 'Magdalena'),
- ('MET', 'Meta'),
- ('NAR', 'Nariño'),
- ('NSA', 'Norte de Santander'),
- ('PUT', 'Putumayo'),
- ('QUI', 'Quindío'),
- ('RIS', 'Risaralda'),
- ('SAP', 'San Andrés and Providencia'),
- ('SAN', 'Santander'),
- ('SUC', 'Sucre'),
- ('TOL', 'Tolima'),
- ('VAC', 'Valle del Cauca'),
- ('VAU', 'Vaupés'),
- ('VID', 'Vichada'),
-)
16 django/contrib/localflavor/co/forms.py
View
@@ -1,16 +0,0 @@
-"""
-Colombian-specific form helpers.
-"""
-
-from __future__ import absolute_import
-
-from django.contrib.localflavor.co.co_departments import DEPARTMENT_CHOICES
-from django.forms.fields import Select
-
-
-class CODepartmentSelect(Select):
- """
- A Select widget that uses a list of Colombian states as its choices.
- """
- def __init__(self, attrs=None):
- super(CODepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_CHOICES)
0  django/contrib/localflavor/cz/__init__.py
View
No changes.
22 django/contrib/localflavor/cz/cz_regions.py
View
@@ -1,22 +0,0 @@
-"""
-Czech regions, translations get from http://www.crwflags.com/fotw/Flags/cz-re.html
-"""
-
-from django.utils.translation import ugettext_lazy as _
-
-REGION_CHOICES = (
- ('PR', _('Prague')),
- ('CE', _('Central Bohemian Region')),
- ('SO', _('South Bohemian Region')),
- ('PI', _('Pilsen Region')),
- ('CA', _('Carlsbad Region')),
- ('US', _('Usti Region')),
- ('LB', _('Liberec Region')),
- ('HK', _('Hradec Region')),
- ('PA', _('Pardubice Region')),
- ('VY', _('Vysocina Region')),
- ('SM', _('South Moravian Region')),
- ('OL', _('Olomouc Region')),
- ('ZL', _('Zlin Region')),
- ('MS', _('Moravian-Silesian Region')),
-)
136 django/contrib/localflavor/cz/forms.py
View
@@ -1,136 +0,0 @@
-"""
-Czech-specific form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.cz.cz_regions import REGION_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Select, RegexField, Field
-from django.utils.translation import ugettext_lazy as _
-
-
-birth_number = re.compile(r'^(?P<birth>\d{6})/?(?P<id>\d{3,4})$')
-ic_number = re.compile(r'^(?P<number>\d{7})(?P<check>\d)$')
-
-class CZRegionSelect(Select):
- """
- A select widget widget with list of Czech regions as choices.
- """
- def __init__(self, attrs=None):
- super(CZRegionSelect, self).__init__(attrs, choices=REGION_CHOICES)
-
-class CZPostalCodeField(RegexField):
- """
- A form field that validates its input as Czech postal code.
- Valid form is XXXXX or XXX XX, where X represents integer.
- """
- default_error_messages = {
- 'invalid': _('Enter a postal code in the format XXXXX or XXX XX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(CZPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$',
- max_length, min_length, *args, **kwargs)
-
- def clean(self, value):
- """
- Validates the input and returns a string that contains only numbers.
- Returns an empty string for empty values.
- """
- v = super(CZPostalCodeField, self).clean(value)
- return v.replace(' ', '')
-
-class CZBirthNumberField(Field):
- """
- Czech birth number field.
- """
- default_error_messages = {
- 'invalid_format': _('Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.'),
- 'invalid': _('Enter a valid birth number.'),
- }
-
- def clean(self, value, gender=None):
- super(CZBirthNumberField, self).clean(value)
-
- if value in EMPTY_VALUES:
- return ''
-
- match = re.match(birth_number, value)
- if not match:
- raise ValidationError(self.error_messages['invalid_format'])
-
- birth, id = match.groupdict()['birth'], match.groupdict()['id']
-
- # Three digits for verification number were used until 1. january 1954
- if len(id) == 3:
- return '%s' % value
-
- # Birth number is in format YYMMDD. Females have month value raised by 50.
- # In case that all possible number are already used (for given date),
- # the month field is raised by 20.
- month = int(birth[2:4])
- if (not 1 <= month <= 12) and (not 21 <= month <= 32) and \
- (not 51 <= month <= 62) and (not 71 <= month <= 82):
- raise ValidationError(self.error_messages['invalid'])
-
- day = int(birth[4:6])
- if not (1 <= day <= 31):
- raise ValidationError(self.error_messages['invalid'])
-
- # Fourth digit has been added since 1. January 1954.
- # It is modulo of dividing birth number and verification number by 11.
- # If the modulo were 10, the last number was 0 (and therefore, the whole
- # birth number wasn't divisable by 11. These number are no longer used (since 1985)
- # and the condition 'modulo == 10' can be removed in 2085.
-
- modulo = int(birth + id[:3]) % 11
-
- if (modulo == int(id[-1])) or (modulo == 10 and id[-1] == '0'):
- return '%s' % value
- else:
- raise ValidationError(self.error_messages['invalid'])
-
-class CZICNumberField(Field):
- """
- Czech IC number field.
- """
- default_error_messages = {
- 'invalid': _('Enter a valid IC number.'),
- }
-
- def clean(self, value):
- super(CZICNumberField, self).clean(value)
-
- if value in EMPTY_VALUES:
- return ''
-
- match = re.match(ic_number, value)
- if not match:
- raise ValidationError(self.error_messages['invalid'])
-
- number, check = match.groupdict()['number'], int(match.groupdict()['check'])
-
- sum = 0
- weight = 8
- for digit in number:
- sum += int(digit)*weight
- weight -= 1
-
- remainder = sum % 11
-
- # remainder is equal:
- # 0 or 10: last digit is 1
- # 1: last digit is 0
- # in other case, last digit is 11 - remainder
-
- if (not remainder % 10 and check == 1) or \
- (remainder == 1 and check == 0) or \
- (check == (11 - remainder)):
- return '%s' % value
-
- raise ValidationError(self.error_messages['invalid'])
-
0  django/contrib/localflavor/de/__init__.py
View
No changes.
21 django/contrib/localflavor/de/de_states.py
View
@@ -1,21 +0,0 @@
-# -*- coding: utf-8 -*
-from django.utils.translation import ugettext_lazy as _
-
-STATE_CHOICES = (
- ('BW', _('Baden-Wuerttemberg')),
- ('BY', _('Bavaria')),
- ('BE', _('Berlin')),
- ('BB', _('Brandenburg')),
- ('HB', _('Bremen')),
- ('HH', _('Hamburg')),
- ('HE', _('Hessen')),
- ('MV', _('Mecklenburg-Western Pomerania')),
- ('NI', _('Lower Saxony')),
- ('NW', _('North Rhine-Westphalia')),
- ('RP', _('Rhineland-Palatinate')),
- ('SL', _('Saarland')),
- ('SN', _('Saxony')),
- ('ST', _('Saxony-Anhalt')),
- ('SH', _('Schleswig-Holstein')),
- ('TH', _('Thuringia')),
-)
88 django/contrib/localflavor/de/forms.py
View
@@ -1,88 +0,0 @@
-"""
-DE-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.de.de_states import STATE_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-
-
-id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday>\d{7})[-\ ]?(?P<validity>\d{7})[-\ ]?(?P<checksum>\d{1})$")
-
-class DEZipCodeField(RegexField):
- default_error_messages = {
- 'invalid': _('Enter a zip code in the format XXXXX.'),
- }
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(DEZipCodeField, self).__init__(r'^\d{5}$',
- max_length, min_length, *args, **kwargs)
-
-class DEStateSelect(Select):
- """
- A Select widget that uses a list of DE states as its choices.
- """
- def __init__(self, attrs=None):
- super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
-
-class DEIdentityCardNumberField(Field):
- """
- A German identity card number.
-
- Checks the following rules to determine whether the number is valid:
-
- * Conforms to the XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.
- * No group consists entirely of zeroes.
- * Included checksums match calculated checksums
-
- Algorithm is documented at http://de.wikipedia.org/wiki/Personalausweis
- """
- default_error_messages = {
- 'invalid': _('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'),
- }
-
- def has_valid_checksum(self, number):
- given_number, given_checksum = number[:-1], number[-1]
- calculated_checksum = 0
- fragment = ""
- parameter = 7
-
- for i in range(len(given_number)):
- fragment = str(int(given_number[i]) * parameter)
- if fragment.isalnum():
- calculated_checksum += int(fragment[-1])
- if parameter == 1:
- parameter = 7
- elif parameter == 3:
- parameter = 1
- elif parameter ==7:
- parameter = 3
-
- return str(calculated_checksum)[-1] == given_checksum
-
- def clean(self, value):
- super(DEIdentityCardNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- match = re.match(id_re, value)
- if not match:
- raise ValidationError(self.error_messages['invalid'])
-
- gd = match.groupdict()
- residence, origin = gd['residence'], gd['origin']
- birthday, validity, checksum = gd['birthday'], gd['validity'], gd['checksum']
-
- if residence == '0000000000' or birthday == '0000000' or validity == '0000000':
- raise ValidationError(self.error_messages['invalid'])
-
- all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum)
- 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):
- raise ValidationError(self.error_messages['invalid'])
-
- return '%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum)
0  django/contrib/localflavor/ec/__init__.py
View
No changes.
36 django/contrib/localflavor/ec/ec_provinces.py
View
@@ -1,36 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-A list of Ecuador departaments as `choices` in a
-formfield.
-
-This exists in this standalone file so that it's only
-imported into memory when explicitly needed.
-"""
-from __future__ import unicode_literals
-
-PROVINCE_CHOICES = (
- ('A', 'Azuay'),
- ('B', 'Bolívar'),
- ('F', 'Cañar'),
- ('C', 'Carchi'),
- ('H', 'Chimborazo'),
- ('X', 'Cotopaxi'),
- ('O', 'El Oro'),
- ('E', 'Esmeraldas'),
- ('W', 'Galápagos'),
- ('G', 'Guayas'),
- ('I', 'Imbabura'),
- ('L', 'Loja'),
- ('R', 'Los Ríos'),
- ('M', 'Manabí'),
- ('S', 'Morona Santiago'),
- ('N', 'Napo'),
- ('D', 'Orellana'),
- ('Y', 'Pastaza'),
- ('P', 'Pichincha'),
- ('SE', 'Santa Elena'),
- ('SD', 'Santo Domingo de los Tsáchilas'),
- ('U', 'Sucumbíos'),
- ('T', 'Tungurahua'),
- ('Z', 'Zamora Chinchipe'),
-)
15 django/contrib/localflavor/ec/forms.py
View
@@ -1,15 +0,0 @@
-"""
-Ecuador-specific form helpers.
-"""
-
-from __future__ import absolute_import
-
-from django.contrib.localflavor.ec.ec_provinces import PROVINCE_CHOICES
-from django.forms.fields import Select
-
-class ECProvinceSelect(Select):
- """
- A Select widget that uses a list of Ecuador provinces as its choices.
- """
- def __init__(self, attrs=None):
- super(ECProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
0  django/contrib/localflavor/es/__init__.py
View
No changes.
58 django/contrib/localflavor/es/es_provinces.py
View
@@ -1,58 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.utils.translation import ugettext_lazy as _
-
-PROVINCE_CHOICES = (
- ('01', _('Araba')),
- ('02', _('Albacete')),
- ('03', _('Alacant')),
- ('04', _('Almeria')),
- ('05', _('Avila')),
- ('06', _('Badajoz')),
- ('07', _('Illes Balears')),
- ('08', _('Barcelona')),
- ('09', _('Burgos')),
- ('10', _('Caceres')),
- ('11', _('Cadiz')),
- ('12', _('Castello')),
- ('13', _('Ciudad Real')),
- ('14', _('Cordoba')),
- ('15', _('A Coruna')),
- ('16', _('Cuenca')),
- ('17', _('Girona')),
- ('18', _('Granada')),
- ('19', _('Guadalajara')),
- ('20', _('Guipuzkoa')),
- ('21', _('Huelva')),
- ('22', _('Huesca')),
- ('23', _('Jaen')),
- ('24', _('Leon')),
- ('25', _('Lleida')),
- ('26', _('La Rioja')),
- ('27', _('Lugo')),
- ('28', _('Madrid')),
- ('29', _('Malaga')),
- ('30', _('Murcia')),
- ('31', _('Navarre')),
- ('32', _('Ourense')),
- ('33', _('Asturias')),
- ('34', _('Palencia')),
- ('35', _('Las Palmas')),
- ('36', _('Pontevedra')),
- ('37', _('Salamanca')),
- ('38', _('Santa Cruz de Tenerife')),
- ('39', _('Cantabria')),
- ('40', _('Segovia')),
- ('41', _('Seville')),
- ('42', _('Soria')),
- ('43', _('Tarragona')),
- ('44', _('Teruel')),
- ('45', _('Toledo')),
- ('46', _('Valencia')),
- ('47', _('Valladolid')),
- ('48', _('Bizkaia')),
- ('49', _('Zamora')),
- ('50', _('Zaragoza')),
- ('51', _('Ceuta')),
- ('52', _('Melilla')),
-)
-
23 django/contrib/localflavor/es/es_regions.py
View
@@ -1,23 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.utils.translation import ugettext_lazy as _
-
-REGION_CHOICES = (
- ('AN', _('Andalusia')),
- ('AR', _('Aragon')),
- ('O', _('Principality of Asturias')),
- ('IB', _('Balearic Islands')),
- ('PV', _('Basque Country')),
- ('CN', _('Canary Islands')),
- ('S', _('Cantabria')),
- ('CM', _('Castile-La Mancha')),
- ('CL', _('Castile and Leon')),
- ('CT', _('Catalonia')),
- ('EX', _('Extremadura')),
- ('GA', _('Galicia')),
- ('LO', _('La Rioja')),
- ('M', _('Madrid')),
- ('MU', _('Region of Murcia')),
- ('NA', _('Foral Community of Navarre')),
- ('VC', _('Valencian Community')),
-)
-
189 django/contrib/localflavor/es/forms.py
View
@@ -1,189 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Spanish-specific Form helpers
-"""
-
-from __future__ import absolute_import, unicode_literals
-
-import re
-
-from django.contrib.localflavor.es.es_provinces import PROVINCE_CHOICES
-from django.contrib.localflavor.es.es_regions import REGION_CHOICES
-from django.core.validators import EMPTY_VALUES
-from django.forms import ValidationError
-from django.forms.fields import RegexField, Select
-from django.utils.translation import ugettext_lazy as _
-
-
-class ESPostalCodeField(RegexField):
- """
- A form field that validates its input as a spanish postal code.
-
- Spanish postal code is a five digits string, with two first digits
- between 01 and 52, assigned to provinces code.
- """
- default_error_messages = {
- 'invalid': _('Enter a valid postal code in the range and format 01XXX - 52XXX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(ESPostalCodeField, self).__init__(
- r'^(0[1-9]|[1-4][0-9]|5[0-2])\d{3}$',
- max_length, min_length, *args, **kwargs)
-
-class ESPhoneNumberField(RegexField):
- """
- A form field that validates its input as a Spanish phone number.
- Information numbers are ommited.
-
- Spanish phone numbers are nine digit numbers, where first digit is 6 (for
- cell phones), 8 (for special phones), or 9 (for landlines and special
- phones)
-
- TODO: accept and strip characters like dot, hyphen... in phone number
- """
- default_error_messages = {
- 'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'),
- }
-
- def __init__(self, max_length=None, min_length=None, *args, **kwargs):
- super(ESPhoneNumberField, self).__init__(r'^(6|7|8|9)\d{8}$',
- max_length, min_length, *args, **kwargs)
-
-class ESIdentityCardNumberField(RegexField):
- """
- Spanish NIF/NIE/CIF (Fiscal Identification Number) code.
-
- Validates three diferent formats:
-
- NIF (individuals): 12345678A
- CIF (companies): A12345678
- NIE (foreigners): X12345678A
-
- according to a couple of simple checksum algorithms.
-
- Value can include a space or hyphen separator between number and letters.
- Number length is not checked for NIF (or NIE), old values start with a 1,
- and future values can contain digits greater than 8. The CIF control digit
- can be a number or a letter depending on company type. Algorithm is not
- public, and different authors have different opinions on which ones allows
- letters, so both validations are assumed true for all types.
- """
- default_error_messages = {
- 'invalid': _('Please enter a valid NIF, NIE, or CIF.'),
- 'invalid_only_nif': _('Please enter a valid NIF or NIE.'),
- 'invalid_nif': _('Invalid checksum for NIF.'),
- 'invalid_nie': _('Invalid checksum for NIE.'),
- 'invalid_cif': _('Invalid checksum for CIF.'),
- }
-
- def __init__(self, only_nif=False, max_length=None, min_length=None, *args, **kwargs):
- self.only_nif = only_nif
- self.nif_control = 'TRWAGMYFPDXBNJZSQVHLCKE'
- self.cif_control = 'JABCDEFGHI'
- self.cif_types = 'ABCDEFGHKLMNPQS'
- self.nie_types = 'XT'
- id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE)
- super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length, min_length,
- error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')],
- *args, **kwargs)
-
- def clean(self, value):
- super(ESIdentityCardNumberField, self).clean(value)
- if value in EMPTY_VALUES:
- return ''
- nif_get_checksum = lambda d: self.nif_control[int(d)%23]
-
- value = value.upper().replace(' ', '').replace('-', '')