From dc6702db78f062fda04b8c7e50ae2c27eaf3b95c Mon Sep 17 00:00:00 2001 From: Ben Konrath Date: Fri, 8 Dec 2017 14:12:38 +0100 Subject: [PATCH] Removed deprecated code. --- docs/changelog.rst | 49 +++++++++++- docs/index.rst | 1 - docs/localflavor/hk.rst | 8 -- localflavor/au/forms.py | 32 -------- localflavor/au/models.py | 24 ------ localflavor/be/forms.py | 43 ---------- localflavor/br/forms.py | 40 ---------- localflavor/ca/forms.py | 27 ------- localflavor/ch/forms.py | 32 -------- localflavor/cn/forms.py | 52 ------------ localflavor/deprecation.py | 24 +----- localflavor/dk/forms.py | 27 ------- localflavor/es/forms.py | 28 ------- localflavor/fr/forms.py | 45 ----------- localflavor/gr/forms.py | 69 ---------------- localflavor/hk/__init__.py | 0 localflavor/hk/forms.py | 73 ----------------- localflavor/hr/forms.py | 50 ------------ localflavor/id_/forms.py | 32 -------- localflavor/il/forms.py | 20 ----- localflavor/in_/forms.py | 36 +-------- localflavor/is_/forms.py | 29 ------- localflavor/it/forms.py | 36 +-------- localflavor/lt/forms.py | 127 ------------------------------ localflavor/nl/forms.py | 38 +-------- localflavor/nl/models.py | 87 +------------------- localflavor/nl/validators.py | 99 ----------------------- localflavor/no/forms.py | 25 ------ localflavor/nz/forms.py | 37 --------- localflavor/pk/forms.py | 39 +-------- localflavor/pk/models.py | 24 ------ localflavor/pt/forms.py | 38 --------- localflavor/ro/forms.py | 86 -------------------- localflavor/sg/forms.py | 46 ----------- localflavor/si/forms.py | 41 ---------- localflavor/tr/forms.py | 35 +------- localflavor/us/forms.py | 29 ------- localflavor/us/models.py | 27 ------- tests/settings.py | 1 - tests/test_au/forms.py | 5 +- tests/test_au/models.py | 5 +- tests/test_au/tests.py | 17 ---- tests/test_be.py | 34 +------- tests/test_br.py | 30 +------ tests/test_ca.py | 21 +---- tests/test_ch.py | 15 +--- tests/test_cn.py | 34 +------- tests/test_deprecated/__init__.py | 0 tests/test_deprecated/tests.py | 125 ----------------------------- tests/test_dk.py | 21 +---- tests/test_es.py | 20 +---- tests/test_fr.py | 19 +---- tests/test_gr.py | 37 +-------- tests/test_hk.py | 34 -------- tests/test_hr.py | 22 +----- tests/test_id.py | 21 +---- tests/test_il.py | 32 +------- tests/test_in.py | 20 +---- tests/test_is.py | 21 +---- tests/test_it.py | 32 +------- tests/test_lt.py | 107 +------------------------ tests/test_nl/forms.py | 2 +- tests/test_nl/models.py | 7 +- tests/test_nl/tests.py | 86 +------------------- tests/test_no.py | 22 +----- tests/test_nz.py | 28 +------ tests/test_pk/forms.py | 2 +- tests/test_pk/models.py | 3 +- tests/test_pk/tests.py | 23 +----- tests/test_pt.py | 25 +----- tests/test_ro.py | 40 +--------- tests/test_sg.py | 19 +---- tests/test_si.py | 21 +---- tests/test_tr.py | 26 +----- tests/test_us/tests.py | 18 ----- 75 files changed, 93 insertions(+), 2457 deletions(-) delete mode 100644 docs/localflavor/hk.rst delete mode 100644 localflavor/hk/__init__.py delete mode 100644 localflavor/hk/forms.py delete mode 100644 tests/test_deprecated/__init__.py delete mode 100644 tests/test_deprecated/tests.py delete mode 100644 tests/test_hk.py diff --git a/docs/changelog.rst b/docs/changelog.rst index adb789733..c96fe5886 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,8 @@ Changelog 2.0 (unreleased) ------------------ +All deprecated code has been removed in this release. See details below. + New flavors: - None @@ -23,7 +25,52 @@ Other changes: - Added support for Django 2.0 and dropped support for Django < 1.11 (`gh-310 `_). - Fixed README and changelog documentation about dropping Python 2 and Django 1.11. - +- Removed the following deprecated items + (`gh-321 `_): + + - `au.forms.AUPhoneNumberField` + - `au.models.AUPhoneNumberField` + - `be.forms.BEPhoneNumberField` + - `br.forms.BRPhoneNumberField` + - `br.forms.DV_maker` + - `ca.forms.CAPhoneNumberField` + - `ch.forms.CHPhoneNumberField` + - `cn.forms.CNPhoneNumberField` + - `cn.forms.CNCellNumberField` + - `dk.forms.DKPhoneNumberField` + - `es.forms.ESPhoneNumberField` + - `fr.forms.FRPhoneNumberField` + - `gr.forms.GRPhoneNumberField` + - `gr.forms.GRMobilePhoneNumberField` + - `hk.forms.HKPhoneNumberField` (`localflavor.hk` has been removed because it only contained this field) + - `hr.forms.HRPhoneNumberField` + - `id_.forms.IDPhoneNumberField` + - `il.forms.ILMobilePhoneNumberField` + - `in.forms.INPhoneNumberField` + - `is_.forms.ISPhoneNumberField` + - `it.forms.ITPhoneNumberField` + - `lt.forms.LTPhoneField` + - `nl.forms.NLPhoneNumberField` + - `nl.forms.NLSoFiNumberField` + - `nl.models.NLBankAccountNumberField` + - `nl.models.NLPhoneNumberField` + - `nl.models.NLSoFiNumberField` + - `nl.validators.NLBankAccountNumberFieldValidator` + - `nl.validators.NLPhoneNumberFieldValidator` + - `nl.validators.NLSoFiNumberFieldValidator` + - `no.forms.NOPhoneNumberField` + - `nz.forms.NZPhoneNumberField` + - `pk.forms.PKPhoneNumberField` + - `pk.models.PKPhoneNumberField` + - `pt.forms.PTPhoneNumberField` + - `ro.forms.ROIBANField` + - `ro.forms.ROPhoneNumberField` + - `sg.forms.SGPhoneNumberField` + - `sg.forms.SGNRIC_FINField` + - `si.forms.SIPhoneNumberField` + - `tr.forms.TRPhoneNumberField` + - `us.forms.USPhoneNumberField` + - `us.models.PhoneNumberField` 1.6 (2017-11-22) ------------------ diff --git a/docs/index.rst b/docs/index.rst index ae846cf0d..dd6f7ba5f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -44,7 +44,6 @@ validate Finnish social security numbers. * :doc:`localflavor/fr` * :doc:`localflavor/gb` * :doc:`localflavor/gr` - * :doc:`localflavor/hk` * :doc:`localflavor/hr` * :doc:`localflavor/hu` * :doc:`localflavor/id_` diff --git a/docs/localflavor/hk.rst b/docs/localflavor/hk.rst deleted file mode 100644 index ead86d243..000000000 --- a/docs/localflavor/hk.rst +++ /dev/null @@ -1,8 +0,0 @@ -Hong Kong (``hk``) -================== - -Forms ------ - -.. automodule:: localflavor.hk.forms - :members: diff --git a/localflavor/au/forms.py b/localflavor/au/forms.py index bb44c7048..5e8565d17 100644 --- a/localflavor/au/forms.py +++ b/localflavor/au/forms.py @@ -4,13 +4,9 @@ import re -from django.forms import ValidationError from django.forms.fields import CharField, RegexField, Select -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .au_states import STATE_CHOICES from .validators import AUBusinessNumberFieldValidator, AUCompanyNumberFieldValidator, AUTaxFileNumberFieldValidator @@ -33,34 +29,6 @@ def __init__(self, max_length=4, *args, **kwargs): super(AUPostCodeField, self).__init__(r'^\d{4}$', max_length=max_length, *args, **kwargs) -class AUPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as an Australian phone number. - - Valid numbers have ten digits. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-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 self.empty_values: - return self.empty_value - value = re.sub('(\(|\)|\s+|-)', '', force_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.""" diff --git a/localflavor/au/models.py b/localflavor/au/models.py index edc8680ba..e549f84da 100644 --- a/localflavor/au/models.py +++ b/localflavor/au/models.py @@ -1,8 +1,6 @@ from django.db.models import CharField from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberField - from . import forms from .au_states import STATE_CHOICES from .validators import AUBusinessNumberFieldValidator, AUCompanyNumberFieldValidator, AUTaxFileNumberFieldValidator @@ -47,28 +45,6 @@ def formfield(self, **kwargs): return super(AUPostCodeField, self).formfield(**defaults) -class AUPhoneNumberField(CharField, DeprecatedPhoneNumberField): - """ - A model field that checks that the value is a valid Australian phone number (ten digits). - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - 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) - - class AUBusinessNumberField(CharField): """ A model field that checks that the value is a valid Australian Business Number (ABN). diff --git a/localflavor/be/forms.py b/localflavor/be/forms.py index 511e9647d..620e1d916 100644 --- a/localflavor/be/forms.py +++ b/localflavor/be/forms.py @@ -3,8 +3,6 @@ from django.forms.fields import RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .be_provinces import PROVINCE_CHOICES from .be_regions import REGION_CHOICES @@ -29,47 +27,6 @@ def __init__(self, *args, **kwargs): super(BEPostalCodeField, self).__init__(r'^[1-9]\d{3}$', *args, **kwargs) -class BEPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - 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 - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - 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, *args, **kwargs): - super(BEPhoneNumberField, self).__init__(r'^[0]\d{1}[/. ]?' - r'\d{3}[. ]\d{2}[. ]?' - r'\d{2}$|^[0]\d{2}[/. ]?' - r'\d{2}[. ]?\d{2}[. ]?' - r'\d{2}$|^[0][4]\d{2}[/. ]?' - r'\d{2}[. ]?' - r'\d{2}[. ]?' - r'\d{2}$', - *args, **kwargs) - - class BERegionSelect(Select): """A Select widget that uses a list of belgium regions as its choices.""" diff --git a/localflavor/br/forms.py b/localflavor/br/forms.py index 1a9278611..a61619708 100644 --- a/localflavor/br/forms.py +++ b/localflavor/br/forms.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import re -import warnings from django.core.validators import EMPTY_VALUES from django.forms import ValidationError @@ -12,8 +11,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin, RemovedInLocalflavor20Warning - from .br_states import STATE_CHOICES phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4,5})[-\.]?(\d{4})$') @@ -37,34 +34,6 @@ def __init__(self, *args, **kwargs): super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$', *args, **kwargs) -class BRPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a Brazilian phone number. - - The phone number must be in either of the following formats: XX-XXXX-XXXX or XX-XXXXX-XXXX. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _(('Phone numbers must be in either of the following ' - 'formats: XX-XXXX-XXXX or XX-XXXXX-XXXX.')), - } - - def clean(self, value): - super(BRPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - value = re.sub('(\(|\)|\s+)', '', force_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.""" @@ -103,15 +72,6 @@ def dv_maker(v): return 0 -def DV_maker(v): # noqa - """ - .. deprecated:: 1.6 - Use `dv_maker` instead. - """ - warnings.warn('DV_maker is deprecated. Please use dv_maker instead.', RemovedInLocalflavor20Warning) - return dv_maker(v) - - class BRCPFField(CharField): """ A form field that validates a CPF number or a CPF string. diff --git a/localflavor/ca/forms.py b/localflavor/ca/forms.py index d1b16f563..173cb621d 100644 --- a/localflavor/ca/forms.py +++ b/localflavor/ca/forms.py @@ -7,10 +7,8 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import CharField, Field, Select -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin from localflavor.generic.checksums import luhn phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$') @@ -45,31 +43,6 @@ def clean(self, value): return "%s %s" % (m.group(1), m.group(2)) -class CAPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - Canadian phone number form field. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must be in XXX-XXX-XXXX format.'), - } - - def clean(self, value): - super(CAPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - value = re.sub('(\(|\)|\s+)', '', force_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. diff --git a/localflavor/ch/forms.py b/localflavor/ch/forms.py index 13b89ba69..2c82b64a8 100644 --- a/localflavor/ch/forms.py +++ b/localflavor/ch/forms.py @@ -7,11 +7,8 @@ from django.core.validators import EMPTY_VALUES, RegexValidator from django.forms import ValidationError from django.forms.fields import CharField, Field, RegexField, Select -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from ..generic import validators from .ch_states import STATE_CHOICES @@ -40,35 +37,6 @@ def __init__(self, *args, **kwargs): super(CHZipCodeField, self).__init__(zip_re, *args, **kwargs) -class CHPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - 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'. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - 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|/|-)', '', force_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.""" diff --git a/localflavor/cn/forms.py b/localflavor/cn/forms.py index d2f7f4256..9f2833291 100644 --- a/localflavor/cn/forms.py +++ b/localflavor/cn/forms.py @@ -8,16 +8,12 @@ from django.forms.fields import CharField, RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .cn_provinces import CN_PROVINCE_CHOICES __all__ = ( 'CNProvinceSelect', 'CNPostCodeField', 'CNIDCardField', - 'CNPhoneNumberField', - 'CNCellNumberField', ) @@ -167,51 +163,3 @@ def has_valid_checksum(self, value): value[:17],), ) % 11 return '10X98765432'[checksum_index] == value[-1] - - -class CNPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a telephone number in mainland China. - - A valid phone number could be like: 010-12345678. - Considering there might be extension numbers, this could also be: 010-12345678-35. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - 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, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a cellphone number in mainland China. - - A valid cellphone number could be like: 13012345678. - - A very rough rule is used here: the first digit should be 1, the second - should be 3, 4, 5, 7 or 8, followed by 9 more digits. - The total length of a cellphone number should be 11. - - .. versionchanged:: 1.1 - Added 7 as a valid second digit for Chinese virtual mobile ISPs. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid cell number.'), - } - - def __init__(self, *args, **kwargs): - super(CNCellNumberField, self).__init__(CELL_RE, *args, **kwargs) diff --git a/localflavor/deprecation.py b/localflavor/deprecation.py index 877a77bee..a13a05c89 100644 --- a/localflavor/deprecation.py +++ b/localflavor/deprecation.py @@ -1,24 +1,2 @@ -import warnings - - -class RemovedInLocalflavor20Warning(DeprecationWarning): +class RemovedInLocalflavor30Warning(PendingDeprecationWarning): pass - - -class DeprecatedPhoneNumberFormFieldMixin(object): - def __init__(self): - super(DeprecatedPhoneNumberFormFieldMixin, self).__init__() - warnings.warn( - "{} is deprecated in favor of the django-phonenumber-field library.".format( - self.__class__.__name__ - ), - RemovedInLocalflavor20Warning, - ) - - -class DeprecatedPhoneNumberField(object): - def __init__(self): - self.system_check_deprecated_details = { - 'msg': self.__class__.__name__ + " is deprecated.", - 'hint': 'Use django-phonenumber-field library instead.' - } diff --git a/localflavor/dk/forms.py b/localflavor/dk/forms.py index 3ae7e1a15..f1b9b5348 100644 --- a/localflavor/dk/forms.py +++ b/localflavor/dk/forms.py @@ -6,8 +6,6 @@ from django.forms import fields, widgets from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .dk_municipalities import DK_MUNICIPALITIES from .dk_postalcodes import DK_POSTALCODES @@ -33,28 +31,3 @@ def __init__(self, attrs=None, *args, **kwargs): *args, **kwargs ) - - -class DKPhoneNumberField(fields.RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - Field with phone number validation. - - Requires a phone number with 8 digits and optional country code. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _( - 'A phone number must be 8 digits and may have country code' - ), - } - - def __init__(self, *args, **kwargs): - super(DKPhoneNumberField, self).__init__( - r'^(?:\+45)? ?(\d{2}\s?\d{2}\s?\d{2}\s?\d{2})$', - *args, **kwargs - ) diff --git a/localflavor/es/forms.py b/localflavor/es/forms.py index 41b42176d..8383f6637 100644 --- a/localflavor/es/forms.py +++ b/localflavor/es/forms.py @@ -10,8 +10,6 @@ from django.utils import six from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .es_provinces import PROVINCE_CHOICES from .es_regions import REGION_CHOICES @@ -32,32 +30,6 @@ def __init__(self, *args, **kwargs): super(ESPostalCodeField, self).__init__(r'^(0[1-9]|[1-4][0-9]|5[0-2])\d{3}$', *args, **kwargs) -class ESPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - 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 - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'), - } - - def __init__(self, *args, **kwargs): - super(ESPhoneNumberField, self).__init__(r'^(6|7|8|9)\d{8}$', *args, **kwargs) - - class ESIdentityCardNumberField(RegexField): """ Spanish NIF/NIE/CIF (Fiscal Identification Number) code. diff --git a/localflavor/fr/forms.py b/localflavor/fr/forms.py index 9527e97f5..566584191 100644 --- a/localflavor/fr/forms.py +++ b/localflavor/fr/forms.py @@ -8,10 +8,8 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import CharField, RegexField, Select -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin from localflavor.generic.checksums import luhn from .fr_department import DEPARTMENT_CHOICES_PER_REGION @@ -41,49 +39,6 @@ def __init__(self, *args, **kwargs): super(FRZipCodeField, self).__init__(r'^\d{5}$', *args, **kwargs) -class FRPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - Validate local French phone number (not international ones). - - The correct format is '0X XX XX XX XX'. - '0X.XX.XX.XX.XX' and '0XXXXXXXXX' validate but are corrected to - '0X XX XX XX XX'. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - phone_digits_re = re.compile(r'^0\d(\s|\.)?(\d{2}(\s|\.)?){3}\d{2}$') - - default_error_messages = { - 'invalid': _('Phone numbers must be in 0X XX XX XX XX format.'), - } - - def __init__(self, *args, **kwargs): - kwargs.setdefault('label', _('Phone number')) - kwargs['max_length'] = 14 - kwargs['min_length'] = 10 - super(FRPhoneNumberField, self).__init__(*args, **kwargs) - - def clean(self, value): - value = super(FRPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub('(\.|\s)', '', force_text(value)) - m = self.phone_digits_re.search(value) - if m: - return '%s %s %s %s %s' % ( - value[0:2], - value[2:4], - value[4:6], - value[6:8], - value[8:10] - ) - raise ValidationError(self.error_messages['invalid']) - - class FRDepartmentSelect(Select): """A Select widget that uses a list of FR departments as its choices.""" diff --git a/localflavor/gr/forms.py b/localflavor/gr/forms.py index 29b844fef..0c7e5f09c 100644 --- a/localflavor/gr/forms.py +++ b/localflavor/gr/forms.py @@ -6,10 +6,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - -NUMERIC_RE = re.compile('^\d+$') - class GRPostalCodeField(RegexField): """ @@ -64,68 +60,3 @@ def clean(self, value): if mod != check: raise ValidationError(self.error_messages['invalid']) return val - - -class GRPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - Greek general phone field. - - 10 digits (can also start with +30 which is the country-code for greece) - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a 10-digit greek phone number.'), - } - - def clean(self, value): - super(GRPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - - phone_nr = re.sub('[\-\s\(\)]', '', force_text(value)) - - if len(phone_nr) == 10 and NUMERIC_RE.search(phone_nr): - return value - - if phone_nr[:3] == '+30' and len(phone_nr) == 13 and NUMERIC_RE.search(phone_nr[3:]): - return value - - raise ValidationError(self.error_messages['invalid']) - - -class GRMobilePhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - Greek mobile phone field. - - 10 digits starting with 69 (could also start with +30 which is the country-code for greece) - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a greek mobile phone number starting with 69.'), - } - - def clean(self, value): - super(GRMobilePhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - - phone_nr = re.sub('[\-\s\(\)]', '', force_text(value)) - - if len(phone_nr) == 10 and NUMERIC_RE.search(phone_nr) and phone_nr.startswith('69'): - return value - - if phone_nr[:3] == '+30' and len(phone_nr) == 13 and \ - NUMERIC_RE.search(phone_nr[3:]) and phone_nr[3:].startswith('69'): - return value - - raise ValidationError(self.error_messages['invalid']) diff --git a/localflavor/hk/__init__.py b/localflavor/hk/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/localflavor/hk/forms.py b/localflavor/hk/forms.py deleted file mode 100644 index 646c86257..000000000 --- a/localflavor/hk/forms.py +++ /dev/null @@ -1,73 +0,0 @@ -"""Hong Kong specific Form helpers.""" -from __future__ import unicode_literals - -import re - -from django.forms import CharField, ValidationError -from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ - -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - -hk_phone_digits_re = re.compile(r'^(?:852-?)?(\d{4})[-\.]?(\d{4})$') -hk_special_numbers = ('999', '992', '112') -hk_phone_prefixes = ('2', '3', '5', '6', '8', '9') -hk_formats = ['XXXX-XXXX', '852-XXXX-XXXX', '(+852) XXXX-XXXX', - 'XXXX XXXX', 'XXXXXXXX'] - - -class HKPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates Hong Kong phone numbers. - - The input format can be either one of the followings: - 'XXXX-XXXX', '852-XXXX-XXXX', '(+852) XXXX-XXXX', - 'XXXX XXXX', or 'XXXXXXXX'. - The output format is 'XXXX-XXXX'. - - Note: The phone number shall not start with 999, 992, or 112. - And, it should start with either 2, 3, 5, 6, 8, or 9. - - http://en.wikipedia.org/wiki/Telephone_numbers_in_Hong_Kong - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'disguise': _('Phone number should not start with ' - 'one of the followings: %s.' % - ', '.join(hk_special_numbers)), - 'invalid': _('Phone number must be in one of the following formats: ' - '%s.' % ', '.join(hk_formats)), - 'prefix': _('Phone number should start with ' - 'one of the followings: %s.' % - ', '.join(hk_phone_prefixes)), - } - - def __init__(self, *args, **kwargs): - super(HKPhoneNumberField, self).__init__(*args, **kwargs) - - def clean(self, value): - super(HKPhoneNumberField, self).clean(value) - - if value in self.empty_values: - return self.empty_value - - value = re.sub('(\(|\)|\s+|\+)', '', force_text(value)) - m = hk_phone_digits_re.search(value) - if not m: - raise ValidationError(self.error_messages['invalid']) - - value = '%s-%s' % (m.group(1), m.group(2)) - for special in hk_special_numbers: - if value.startswith(special): - raise ValidationError(self.error_messages['disguise']) - - prefix_found = map(value.startswith, hk_phone_prefixes) - if not any(prefix_found): - raise ValidationError(self.error_messages['prefix']) - - return value diff --git a/localflavor/hr/forms.py b/localflavor/hr/forms.py index 2c98a6b3f..7208cc77b 100644 --- a/localflavor/hr/forms.py +++ b/localflavor/hr/forms.py @@ -11,7 +11,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin from localflavor.generic.checksums import luhn from .hr_choices import HR_COUNTY_CHOICES, HR_LICENSE_PLATE_PREFIX_CHOICES, HR_PHONE_NUMBER_PREFIX_CHOICES @@ -23,7 +22,6 @@ r'(?P\d{3,4})' + r'(?P[ABCDEFGHIJKLMNOPRSTUVZ]{1,2})$') postal_code_re = re.compile(r'^\d{5}$') -phone_re = re.compile(r'^(\+385|00385|0)(?P\d{2})(?P\d{6,7})$') jmbag_re = re.compile(r'^601983(?P\d{1})1(?P\d{10})(?P\d{1})$') @@ -207,54 +205,6 @@ def clean(self, value): return '%s' % value -class HRPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - Phone number of Croatia field. - - Format: Complete country code or leading zero, area code prefix, 6 or 7 - digit number. - Validates fixed, mobile and FGSM numbers. Normalizes to a full number with - country code (+385 prefix). - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid phone number'), - 'area': _('Enter a valid area or mobile network code'), - 'number': _('The phone number is too long'), - } - - def clean(self, value): - super(HRPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - - value = re.sub(r'[\-\s\(\)]', '', force_text(value)) - - matches = phone_re.search(value) - if matches is None: - raise ValidationError(self.error_messages['invalid']) - - # Make sure the prefix is in the list of known codes. - prefix = matches.group('prefix') - number = matches.group('number') - if prefix[0] == '1': - number = prefix[1] + number - prefix = prefix[0] - if prefix not in [choice[0] for choice in HR_PHONE_NUMBER_PREFIX_CHOICES]: - raise ValidationError(self.error_messages['area']) - - # Make sure the number is of adequate length. - if prefix == '1' and len(number) != 7: - raise ValidationError(self.error_messages['number']) - - return '%s%s%s' % ('+385', prefix, number) - - class HRJMBAGField(Field): """ Unique Master Academic Citizen Number of Croatia (JMBAG) field. diff --git a/localflavor/id_/forms.py b/localflavor/id_/forms.py index 08e7cbc14..8b9444ec1 100644 --- a/localflavor/id_/forms.py +++ b/localflavor/id_/forms.py @@ -11,10 +11,7 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - postcode_re = re.compile(r'^[1-9]\d{4}$') -phone_re = re.compile(r'^(\+62|0)[2-9]\d{7,10}$') plate_re = re.compile(r'^(?P[A-Z]{1,2}) ' + r'(?P\d{1,5})( (?P([A-Z]{1,3}|[1-9][0-9]{,2})))?$') nik_re = re.compile(r'^\d{16}$') @@ -59,35 +56,6 @@ def __init__(self, attrs=None): super(IDProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) -class IDPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - An Indonesian telephone number field. - - http://id.wikipedia.org/wiki/Daftar_kode_telepon_di_Indonesia - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid phone number'), - } - - def clean(self, value): - super(IDPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - - phone_number = re.sub(r'[\-\s\(\)]', '', force_text(value)) - - if phone_re.search(phone_number): - return force_text(value) - - raise ValidationError(self.error_messages['invalid']) - - class IDLicensePlatePrefixSelect(Select): """ A Select widget that uses a list of vehicle license plate prefix code of Indonesia as its choices. diff --git a/localflavor/il/forms.py b/localflavor/il/forms.py index 7fb4fbfcd..99021c1cc 100644 --- a/localflavor/il/forms.py +++ b/localflavor/il/forms.py @@ -8,11 +8,9 @@ from django.forms.fields import Field, RegexField from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin from localflavor.generic.checksums import luhn id_number_re = re.compile(r'^(?P\d{1,8})-?(?P\d)$') -mobile_phone_number_re = re.compile(r'^(\()?0?(5[02-9])(?(1)\))-?\d{7}$') # including palestinian mobile carriers class ILPostalCodeField(RegexField): @@ -71,21 +69,3 @@ def clean(self, value): if not luhn(value): raise ValidationError(self.error_messages['invalid']) return value - - -class ILMobilePhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates its input as an Israeli Mobile phone number. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid Mobile Number.'), - } - - def __init__(self, *args, **kwargs): - super(ILMobilePhoneNumberField, self).__init__(mobile_phone_number_re, *args, **kwargs) diff --git a/localflavor/in_/forms.py b/localflavor/in_/forms.py index 7642e7dd3..b337fb14b 100644 --- a/localflavor/in_/forms.py +++ b/localflavor/in_/forms.py @@ -6,12 +6,10 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError -from django.forms.fields import CharField, Field, RegexField, Select +from django.forms.fields import Field, RegexField, Select from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .in_states import STATE_CHOICES, STATES_NORMALIZED phone_digits_re = re.compile(r""" @@ -146,35 +144,3 @@ class INStateSelect(Select): def __init__(self, attrs=None): super(INStateSelect, self).__init__(attrs, choices=STATE_CHOICES) - - -class INPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - INPhoneNumberField validates that the data is a valid Indian phone number, including the STD code. - - It's normalised to 0XXX-XXXXXXX or 0XXX XXXXXXX - format. The first string is the STD code which is a '0' followed by 2-4 - digits. The second string is 8 digits if the STD code is 3 digits, 7 - digits if the STD code is 4 digits and 6 digits if the STD code is 5 - digits. The second string will start with numbers between 1 and 6. The - separator is either a space or a hyphen. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must be in 02X-8X or 03X-7X or 04X-6X format.'), - } - - def clean(self, value): - value = super(INPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = force_text(value) - m = phone_digits_re.match(value) - if m: - return '%s' % (value) - raise ValidationError(self.error_messages['invalid']) diff --git a/localflavor/is_/forms.py b/localflavor/is_/forms.py index 98f15840d..8deb8d507 100644 --- a/localflavor/is_/forms.py +++ b/localflavor/is_/forms.py @@ -8,8 +8,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .is_postalcodes import IS_POSTALCODES @@ -61,33 +59,6 @@ def _format(self, value): return force_text(value[:6] + '-' + value[6:]) -class ISPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - Icelandic phone number. - - Seven digits with an optional hyphen or space after the first three digits. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - def __init__(self, max_length=8, min_length=7, *args, **kwargs): - super(ISPhoneNumberField, self).__init__( - r'^\d{3}(-| )?\d{4}$', max_length=max_length, min_length=min_length, - *args, **kwargs - ) - - def clean(self, value): - value = super(ISPhoneNumberField, self).clean(value) - - if value in self.empty_values: - return self.empty_value - - return value.replace('-', '').replace(' ', '') - - class ISPostalCodeSelect(Select): """A Select widget that uses a list of Icelandic postal codes as its choices.""" diff --git a/localflavor/it/forms.py b/localflavor/it/forms.py index d4f56980b..c4ef61a68 100644 --- a/localflavor/it/forms.py +++ b/localflavor/it/forms.py @@ -6,18 +6,13 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError -from django.forms.fields import CharField, Field, RegexField, Select -from django.utils.encoding import force_text +from django.forms.fields import Field, RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .it_province import PROVINCE_CHOICES from .it_region import REGION_CHOICES, REGION_PROVINCE_CHOICES from .util import ssn_validation, vat_number_validation -phone_digits_re = re.compile(r'^(?:\+?39)?((0\d{1,3})(\d{4,8})|(3\d{2})(\d{6,8}))$') - class ITZipCodeField(RegexField): """ @@ -113,32 +108,3 @@ def clean(self, value): return vat_number_validation(value) except ValueError: raise ValidationError(self.error_messages['invalid']) - - -class ITPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as an Italian phone number. - - Will strip any +39 country prefix from the number. - - .. versionadded:: 1.1 - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter a valid Italian phone number.'), - } - - def clean(self, value): - super(ITPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub(r'[^\+\d]', '', force_text(value)) - m = phone_digits_re.match(value) - if m: - return '%s %s' % tuple(group for group in m.groups()[1:] if group) - raise ValidationError(self.error_messages['invalid']) diff --git a/localflavor/lt/forms.py b/localflavor/lt/forms.py index 91a793cef..4e8ffed59 100644 --- a/localflavor/lt/forms.py +++ b/localflavor/lt/forms.py @@ -6,11 +6,8 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import Field, RegexField, Select -from django.utils.six import text_type from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .lt_choices import COUNTY_CHOICES, MUNICIPALITY_CHOICES postalcode = re.compile(r'^(LT\s?-\s?)?(?P\d{5})$', re.IGNORECASE) @@ -116,127 +113,3 @@ def clean(self, value): raise ValidationError(self.error_messages['invalid']) return 'LT-' + match.group('code') - - -class LTPhoneField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - Form field that validates as Lithuanian phone number. - - You can accept any permutation of following phone numbers: - - * Emergency (01, 02, 03, 04, 112) - * Mobile (370 600 00 000) - * Landline - * Service numbers - - If you accept landline numbers, you can opt in to accepting local landline - numbers too. Local landline numbers are numbers without area code. - - This field does not accept multiple numbers (as separated by /). - - The field tries its best to convert the number into one you can call to - internationally. Currently emergency and most of landline_local numbers are - not converted. - - .. versionadded:: 1.1 - - .. deprecated:: 1.6 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - # Order dependent (shorter codes cannot go before longer ones) - _area_codes = tuple(map(text_type, - [425, 315, 381, 319, 450, 313, 528, 386, 349, 426, 447, 346, 427, 347, - 445, 459, 318, 343, 443, 383, 469, 421, 460, 451, 448, 319, 422, 428, - 458, 440, 345, 380, 449, 441, 382, 387, 446, 444, 528, 340, 389, 310, - 342, 386, 385, 45, 46, 41, 37, 5])) - _stripable = re.compile(r'[\+()~ ]') - default_error_messages = { - 'non-digit': _('Phone number can only contain digits'), - 'no-parse': _('Could not validate the phone number'), - } - - def __init__(self, mobile=True, landline=True, emergency=False, - landline_local=False, service=False, **kwargs): - self._checks = [] - if mobile: - self._checks.append(self._clean_mobile) - if landline: - self._checks.append(self._clean_landline) - if service: - self._checks.append(self._clean_service) - if emergency: - self._checks.append(self._clean_emergency) - - if landline_local and not landline: - raise ValueError("Cannot accept local landline numbers if " + - "regular landline numbers are not accepted") - elif landline_local: - self._checks.append(self._clean_landline_local) - - super(LTPhoneField, self).__init__(**kwargs) - - def clean(self, value): - value = super(LTPhoneField, self).clean(value) - - if value in EMPTY_VALUES: - return '' - - value = self._stripable.sub('', value.strip()) - if not value.isdigit(): - raise ValidationError(self.error_messages['non-digit'], - code='invalid') - - results = list(filter(lambda x: x is not None, - map(lambda fn: fn(value), self._checks))) - if results: - # TODO: More than one result means code error, check for it. - return results[0] - raise ValidationError(self.error_messages['no-parse'], code='invalid') - - def _clean_emergency(self, value): - if value in ["112", "01", "02", "03", "04"]: - return value - - def _clean_mobile(self, value): - if len(value) == 9 and value[:2] == "86": - return "+370" + value[1:] - elif len(value) == 11 and value[:4] == "3706": - return "+" + value - - def _clean_service(self, value): - if len(value) == 9 and value[:4] == "8800": - return "+370" + value[1:] - elif len(value) == 11 and value[:6] == "370800": - return "+" + value - - # Now these two are most complex ones. - def _clean_landline_local(self, value): - # The landline phone number must always be 8 digits in length when the - # number contains an area code. Now area codes can range from 1 to 3 - # digits (ex. 5 for Vilnius district or 389 for Utena). For local - # (in district) calling you don't have to include the area code, - # therefore local numbers can range from 5 to 7 digits in length. - # - # We cannot prepend area code or country code to those numbers because - # there's more than one possibility in almost all cases with a - # single exception being Vilnius district. As Vilnius is the only - # district that has a single digit code, we can safely assume the - # number is for Vilnius. - - if 5 <= len(value) <= 6: - return value - elif len(value) == 7: - return "+3705" + value - - def _clean_landline(self, value): - if len(value) == 9 and value[0] == "8": - number = value[1:] - elif len(value) == 11 and value[:3] == "370": - number = value[3:] - else: - return None - if number.startswith(self._area_codes): - return "+370" + number diff --git a/localflavor/nl/forms.py b/localflavor/nl/forms.py index a45acaf88..c3fa09157 100644 --- a/localflavor/nl/forms.py +++ b/localflavor/nl/forms.py @@ -3,16 +3,11 @@ from __future__ import unicode_literals -import warnings - from django import forms from django.utils import six -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin, RemovedInLocalflavor20Warning - from .nl_provinces import PROVINCE_CHOICES -from .validators import (NLBSNFieldValidator, NLPhoneNumberFieldValidator, NLSoFiNumberFieldValidator, - NLZipCodeFieldValidator) +from .validators import NLBSNFieldValidator, NLZipCodeFieldValidator class NLZipCodeField(forms.CharField): @@ -37,19 +32,6 @@ def __init__(self, attrs=None): super(NLProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) -class NLPhoneNumberField(forms.CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A Dutch telephone number field. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_validators = [NLPhoneNumberFieldValidator()] - - class NLBSNFormField(forms.CharField): """ A Dutch social security number (BSN) field. @@ -64,21 +46,3 @@ class NLBSNFormField(forms.CharField): def __init__(self, *args, **kwargs): kwargs['max_length'] = 9 super(NLBSNFormField, self).__init__(*args, **kwargs) - - -class NLSoFiNumberField(NLBSNFormField): - """ - A Dutch social security number (SoFi/BSN) field. - - http://nl.wikipedia.org/wiki/Sofinummer - - .. versionadded:: 1.3 - .. deprecated:: 1.6 - Use `NLBSNFormField` instead. - """ - default_validators = [NLSoFiNumberFieldValidator()] - - def __init__(self, *args, **kwargs): - warnings.warn('NLSoFiNumberField is deprecated. Please use NLBSNFormField instead.', - RemovedInLocalflavor20Warning) - super(NLSoFiNumberField, self).__init__(*args, **kwargs) diff --git a/localflavor/nl/models.py b/localflavor/nl/models.py index d5f76758d..821e185a2 100644 --- a/localflavor/nl/models.py +++ b/localflavor/nl/models.py @@ -1,16 +1,11 @@ from __future__ import unicode_literals -import warnings - from django.db import models from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberField, RemovedInLocalflavor20Warning - from . import forms from .nl_provinces import PROVINCE_CHOICES -from .validators import (NLBankAccountNumberFieldValidator, NLBSNFieldValidator, NLPhoneNumberFieldValidator, - NLSoFiNumberFieldValidator, NLZipCodeFieldValidator) +from .validators import NLBSNFieldValidator, NLZipCodeFieldValidator class NLZipCodeField(models.CharField): @@ -87,83 +82,3 @@ def formfield(self, **kwargs): defaults = {'form_class': forms.NLBSNFormField} defaults.update(kwargs) return super(NLBSNField, self).formfield(**defaults) - - -class NLSoFiNumberField(NLBSNField): - """ - A Dutch social security number (SoFi). - - This model field uses :class:`validators.NLSoFiNumberFieldValidator` for validation. - - .. versionadded:: 1.3 - .. deprecated:: 1.6 - Use `NLBSNField` instead. - """ - - description = _('Dutch social security number (SoFi)') - - validators = [NLSoFiNumberFieldValidator()] - - def __init__(self, *args, **kwargs): - warnings.warn('NLSoFiNumberField is deprecated. Please use NLBSNField instead.', - RemovedInLocalflavor20Warning) - super(NLSoFiNumberField, self).__init__(*args, **kwargs) - - def formfield(self, **kwargs): - defaults = {'form_class': forms.NLSoFiNumberField} - defaults.update(kwargs) - return super(NLSoFiNumberField, self).formfield(**defaults) - - -class NLPhoneNumberField(models.CharField, DeprecatedPhoneNumberField): - """ - Dutch phone number model field. - - This model field uses :class:`validators.NLPhoneNumberFieldValidator` for validation. - - .. versionadded:: 1.3 - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - description = _('Dutch phone number') - - validator = [NLPhoneNumberFieldValidator()] - - def __init__(self, *args, **kwargs): - kwargs.setdefault('max_length', 12) - super(NLPhoneNumberField, self).__init__(*args, **kwargs) - - def formfield(self, **kwargs): - defaults = {'form_class': forms.NLPhoneNumberField} - defaults.update(kwargs) - return super(NLPhoneNumberField, self).formfield(**defaults) - - -class NLBankAccountNumberField(models.CharField): - """ - A Dutch bank account model field. - - This model field uses :class:`validators.NLBankAccountNumberFieldValidator` for validation. - - .. versionadded:: 1.1 - - .. deprecated:: 1.6 - Use `localflavor.generic.models.IBANField` with included_countries=('nl') option instead. - Note that a data migration is required to move the data from this field to a new IBANField: - it needs to calculate check digits, add the bank identifier and zero-pad the bank number - into a proper IBAN. - """ - - def __init__(self, *args, **kwargs): - self.system_check_deprecated_details = { - 'msg': self.__class__.__name__ + ' is deprecated.', - 'hint': "Use `localflavor.generic.models.IBANField` with included_countries=('nl') option instead." - } - - kwargs.setdefault('max_length', 10) - super(NLBankAccountNumberField, self).__init__(*args, **kwargs) - # Ensure that only the NLBankAccountNumberFieldValidator is set. - self.validators = [NLBankAccountNumberFieldValidator()] diff --git a/localflavor/nl/validators.py b/localflavor/nl/validators.py index cde7ccf40..cad6eccb4 100644 --- a/localflavor/nl/validators.py +++ b/localflavor/nl/validators.py @@ -1,17 +1,10 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -import re -import warnings - from django.core.exceptions import ValidationError from django.core.validators import RegexValidator -from django.utils.deconstruct import deconstructible -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import RemovedInLocalflavor20Warning - class NLZipCodeFieldValidator(RegexValidator): """ @@ -61,95 +54,3 @@ def __call__(self, value): if not self.bsn_checksum_ok(value): raise ValidationError(self.error_message) - - -class NLSoFiNumberFieldValidator(NLBSNFieldValidator): - """ - Validation for Dutch SoFinummers. - - .. versionadded:: 1.3 - .. deprecated:: 1.6 - Use `NLBSNFieldValidator` instead. - """ - error_message = _('Enter a valid SoFi number.') - - def __init__(self): - warnings.warn('NLSoFiNumberFieldValidator is deprecated. Please use NLBSNFieldValidator instead.', - RemovedInLocalflavor20Warning) - super(NLSoFiNumberFieldValidator, self).__init__() - - def sofi_checksum_ok(self, value): - return self.bsn_checksum_ok(value) - - -@deconstructible -class NLPhoneNumberFieldValidator(object): - """ - Validation for Dutch phone numbers. - - .. versionadded:: 1.3 - """ - - def __eq__(self, other): - # The is no outside modification of properties so this should always be true by default. - return True - - def __call__(self, value): - phone_nr = re.sub('[\-\s\(\)]', '', force_text(value)) - numeric_re = re.compile('^\d+$') - - if len(phone_nr) == 10 and numeric_re.search(phone_nr): - return - - if phone_nr[:3] == '+31' and len(phone_nr) == 12 and numeric_re.search(phone_nr[3:]): - return - - raise ValidationError(_('Enter a valid phone number.')) - - -class NLBankAccountNumberFieldValidator(RegexValidator): - """ - Validation for Dutch bank accounts. - - Validation references: - http://www.mobilefish.com/services/elfproef/elfproef.php - http://www.credit-card.be/BankAccount/ValidationRules.htm#NL_Validation - - .. versionadded:: 1.1 - """ - - default_error_messages = { - 'invalid': _('Enter a valid bank account number.'), - 'wrong_length': _('Bank account numbers have 1 - 7, 9 or 10 digits.'), - } - - def __init__(self, regex=None, message=None, code=None): - super(NLBankAccountNumberFieldValidator, self).__init__(regex='^[0-9]+$', - message=self.default_error_messages['invalid']) - self.no_leading_zeros_regex = re.compile('[1-9]+') - - def __call__(self, value): - super(NLBankAccountNumberFieldValidator, self).__call__(value) - - # Need to check for values over the field's max length before the zero are stripped. - # This check is needed to allow this validator to be used without Django's MaxLengthValidator. - if len(value) > 10: - raise ValidationError(self.default_error_messages['wrong_length']) - - # Strip the leading zeros. - m = re.search(self.no_leading_zeros_regex, value) - if not m: - raise ValidationError(self.default_error_messages['invalid']) - value = value[m.start():] - - if len(value) != 9 and len(value) != 10 and not 1 <= len(value) <= 7: - raise ValidationError(self.default_error_messages['wrong_length']) - - # Perform the eleven test validation on non-PostBank numbers. - if len(value) == 9 or len(value) == 10: - if len(value) == 9: - value = "0" + value - - eleven_test_sum = sum([int(a) * b for a, b in zip(value, range(1, 11))]) - if eleven_test_sum % 11 != 0: - raise ValidationError(self.default_error_messages['invalid']) diff --git a/localflavor/no/forms.py b/localflavor/no/forms.py index 09a5d0655..9734397d9 100644 --- a/localflavor/no/forms.py +++ b/localflavor/no/forms.py @@ -10,8 +10,6 @@ from django.forms.fields import CharField, Field, RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .no_municipalities import MUNICIPALITY_CHOICES @@ -162,26 +160,3 @@ def prepare_value(self, value): if value in self.empty_values: return self.empty_value return '{}.{}.{}'.format(value[0:4], value[4:6], value[6:11]) - - -class NOPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - Field with phonenumber validation. - - Requires a phone number with 8 digits and optional country code - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('A phone number must be 8 digits and may have country code'), - } - - def __init__(self, *args, **kwargs): - super(NOPhoneNumberField, self).__init__( - r'^(?:\+47)? ?(\d{3}\s?\d{2}\s?\d{3}|\d{2}\s?\d{2}\s?\d{2}\s?\d{2})$', - *args, **kwargs - ) diff --git a/localflavor/nz/forms.py b/localflavor/nz/forms.py index eca38a666..668cc1ba2 100644 --- a/localflavor/nz/forms.py +++ b/localflavor/nz/forms.py @@ -10,16 +10,10 @@ from django.utils.encoding import smart_str from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .nz_councils import NORTH_ISLAND_COUNCIL_CHOICES, SOUTH_ISLAND_COUNCIL_CHOICES from .nz_provinces import PROVINCE_CHOICES from .nz_regions import REGION_CHOICES -PHONE_08_RE = re.compile(r'^((0800\d{6})|(0800\w{6,10}))$') -PHONE_IN_RE = re.compile(r'^((0064|064|\+64|\+\+64)((\d{8})|(2\d{7,9})))$') -PHONE_NZ_RE = re.compile(r'^((0\d{8})|(02\d{7,9}))$') - BANK_ACCOUNT_NUMBER_RE = re.compile(r'^(\d{2})(\d{4})(\d{7})(\d{2,3})$') @@ -63,37 +57,6 @@ def __init__(self, *args, **kwargs): *args, **kwargs) -class NZPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates its input as New Zealand phone number. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = {'invalid': _('Invalid phone number.')} - - def clean(self, value): - super(NZPhoneNumberField, self).clean(value) - if value in EMPTY_VALUES: - return '' - value = re.sub('(\(|\)|\s+|_|-)', '', smart_str(value)) - value = re.sub('^(\+\+)', '00', smart_str(value)) - value = re.sub('^(\+)', '00', smart_str(value)) - phone_08_match = PHONE_08_RE.search(value) - if phone_08_match: - return '%s' % phone_08_match.group(0) - phone_nz_match = PHONE_NZ_RE.search(value) - if phone_nz_match: - return '%s' % phone_nz_match.group(0) - phone_in_match = PHONE_IN_RE.search(value) - if phone_in_match: - return '%s' % phone_in_match.group(0) - raise ValidationError(self.error_messages['invalid']) - - class NZBankAccountNumberField(Field): """ A form field that validates its input as New Zealand bank account number. diff --git a/localflavor/pk/forms.py b/localflavor/pk/forms.py index 78cdd8c7a..84adf9969 100644 --- a/localflavor/pk/forms.py +++ b/localflavor/pk/forms.py @@ -4,17 +4,12 @@ import re -from django.forms import ValidationError -from django.forms.fields import CharField, RegexField, Select -from django.utils.encoding import force_text +from django.forms.fields import RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .pk_states import STATE_CHOICES POSTCODE_DIGITS_RE = re.compile(r'^(\d{5})$') -PHONE_DIGITS_RE = re.compile(r'^(\d{9,11})$') class PKPostCodeField(RegexField): @@ -32,38 +27,6 @@ def __init__(self, *args, **kwargs): super(PKPostCodeField, self).__init__(POSTCODE_DIGITS_RE, *args, **kwargs) -class PKPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as an Pakistani phone number. - - Valid numbers have nine to eleven digits. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must contain 9, 10 or 11 digits.'), - } - - def clean(self, value): - """ - Validate a phone number. - - Strips parentheses, whitespace and hyphens. - """ - super(PKPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub('(\(|\)|\s+|-)', '', force_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 PKStateSelect(Select): """A Select widget that uses a list of Pakistani states/territories as its choices.""" diff --git a/localflavor/pk/models.py b/localflavor/pk/models.py index debc41bad..4952c8805 100644 --- a/localflavor/pk/models.py +++ b/localflavor/pk/models.py @@ -1,8 +1,6 @@ from django.db.models import CharField from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberField - from . import forms from .pk_states import STATE_CHOICES @@ -44,25 +42,3 @@ def formfield(self, **kwargs): defaults = {'form_class': forms.PKPostCodeField} defaults.update(kwargs) return super(PKPostCodeField, self).formfield(**defaults) - - -class PKPhoneNumberField(CharField, DeprecatedPhoneNumberField): - """ - A model field that checks that the value is a valid Pakistani phone number (nine to eleven digits). - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - description = _("Pakistani Phone number") - - def __init__(self, *args, **kwargs): - kwargs['max_length'] = 20 - super(PKPhoneNumberField, self).__init__(*args, **kwargs) - - def formfield(self, **kwargs): - defaults = {'form_class': forms.PKPhoneNumberField} - defaults.update(kwargs) - return super(PKPhoneNumberField, self).formfield(**defaults) diff --git a/localflavor/pt/forms.py b/localflavor/pt/forms.py index 8f15d96c6..4ce058fcc 100644 --- a/localflavor/pt/forms.py +++ b/localflavor/pt/forms.py @@ -11,20 +11,15 @@ from __future__ import unicode_literals from re import compile as regex_compile -from re import sub as regex_replace 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 force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .pt_regions import REGION_CHOICES CITIZEN_CARD_NUMBER_REGEX = regex_compile(r'^(\d{8})-?(\d[A-Z0-9]{2}\d)$') -PHONE_NUMBER_REGEX = regex_compile(r'^((00|\+)351)?\d{3,9}$') SOCIAL_SECURITY_NUMBER_MULTIPLIERS = [29, 23, 19, 17, 13, 11, 7, 5, 3, 2] SOCIAL_SECURITY_NUMBER_REGEX = regex_compile(r'^[12]\d{10}$') ZIP_CODE_REGEX = regex_compile(r'^[1-9]\d{3}-\d{3}$') @@ -80,39 +75,6 @@ def compute(index, value): return value if value < 10 else value - 9 -class PTPhoneNumberField(Field, DeprecatedPhoneNumberFormFieldMixin): - """ - A field which validates Portuguese phone numbers. - - - Phone numbers have at least 3 and at most 9 digits and may optionally be prefixed with '00351' or '+351'. - - The input string is allowed to contain spaces (though they will be stripped). - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers have at least 3 and at most 9 digits ' - 'and may optionally be prefixed with \'00351\' or \'+351\'.'), - } - - def clean(self, value): - super(PTPhoneNumberField, self).clean(value) - - if value in EMPTY_VALUES: - return '' - - value = regex_replace('(\.|\s)', '', force_text(value)) - match = PHONE_NUMBER_REGEX.search(value) - - if not match: - raise ValidationError(self.error_messages['invalid']) - - return '{0}'.format(value) - - class PTRegionSelect(Select): """ A select widget which uses a list of Portuguese regions as its choices. diff --git a/localflavor/ro/forms.py b/localflavor/ro/forms.py index b76977ee9..0f737b13b 100644 --- a/localflavor/ro/forms.py +++ b/localflavor/ro/forms.py @@ -3,20 +3,13 @@ from __future__ import unicode_literals import datetime -import re -import warnings from django.core.validators import EMPTY_VALUES from django.forms import Field, RegexField, Select, ValidationError from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin, RemovedInLocalflavor20Warning - -from ..generic.forms import IBANFormField from .ro_counties import COUNTIES_CHOICES -phone_digits_re = re.compile(r'^[0-9\-\.\(\)\s]{3,20}$') - class ROCIFField(RegexField): """ @@ -182,85 +175,6 @@ def __init__(self, attrs=None): super(ROCountySelect, self).__init__(attrs, choices=COUNTIES_CHOICES) -class ROIBANField(IBANFormField): - """ - Romanian International Bank Account Number (IBAN) field. - - .. versionchanged:: 1.1 - Validation error messages changed to the messages used in :class:`.IBANFormField` - - .. deprecated:: 1.1 - Use `IBANFormField` with `included_countries=('RO',)` option instead. - """ - - def __init__(self, *args, **kwargs): - warnings.warn('ROIBANField is deprecated. Use `IBANFormField` with `included_countries=(\'RO\',)` option ' - 'instead.', RemovedInLocalflavor20Warning) - kwargs['use_nordea_extensions'] = False - kwargs['include_countries'] = ('RO',) - super(ROIBANField, self).__init__(*args, **kwargs) - - -class ROPhoneNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin): - """ - Romanian phone number field. - - .. versionchanged:: 1.1 - - | Made the field also accept national short phone numbers and 7-digit - regional phone numbers besides the regular ones. - | Official documentation (in English): http://www.ancom.org.ro/en/pnn_1300 - | Official documentation (in Romanian): http://www.ancom.org.ro/pnn_1300 - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid_length': - _('Phone numbers may only have 7 or 10 digits, except the ' - 'national short numbers which have 3 to 6 digits'), - 'invalid_long_format': - _('Normal phone numbers (7 or 10 digits) must begin with "0"'), - 'invalid_short_format': - _('National short numbers (3 to 6 digits) must begin with "1"'), - } - - def __init__(self, max_length=20, min_length=3, *args, **kwargs): - super(ROPhoneNumberField, self).__init__( - phone_digits_re, max_length=max_length, min_length=min_length, - *args, **kwargs - ) - - def clean(self, value): - """ - Strips braces, dashes, dots and spaces. Checks the final length. - - Args: - value: the phone number - """ - value = super(ROPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - - value = re.sub('[()-. ]', '', value) - length = len(value) - - if length in (3, 4, 5, 6, 7, 10): - if (length == 7 or length == 10) and value[0] != '0': - raise ValidationError( - self.error_messages['invalid_long_format']) - elif (3 <= length <= 6) and value[0] != '1': - raise ValidationError( - self.error_messages['invalid_short_format']) - else: - raise ValidationError(self.error_messages['invalid_length']) - - return value - - class ROPostalCodeField(RegexField): """Romanian postal code field.""" diff --git a/localflavor/sg/forms.py b/localflavor/sg/forms.py index 5a69c6e6b..10a468563 100644 --- a/localflavor/sg/forms.py +++ b/localflavor/sg/forms.py @@ -3,17 +3,12 @@ from __future__ import unicode_literals import re -import warnings from django.forms import ValidationError from django.forms.fields import CharField, RegexField from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin, RemovedInLocalflavor20Warning - -PHONE_DIGITS_RE = re.compile(r'^[689](\d{7})$') - NRIC_FIN_RE = re.compile(r'^[SFTG](\d{7})[A-Z]$') NRIC_FIN_DIGIT_WEIGHT = [2, 7, 6, 5, 4, 3, 2] NRIC_FIN_CHECKSUM_ST = ['J', 'Z', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'] @@ -35,36 +30,6 @@ def __init__(self, *args, **kwargs): super(SGPostCodeField, self).__init__(r'^\d{6}$', *args, **kwargs) -class SGPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a Singapore phone number. - - Valid numbers have 8 digits and start with either 6, 8, or 9 - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must contain 8 digits and start with ' - 'either 6, or 8, or 9.') - - } - - def clean(self, value): - """Validate a phone number. Strips parentheses, whitespace and hyphens.""" - super(SGPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub('(\(|\)|\s+|-)', '', force_text(value)) - phone_match = PHONE_DIGITS_RE.search(value) - if phone_match: - return '%s' % phone_match.group() - raise ValidationError(self.error_messages['invalid']) - - class SGNRICFINField(CharField): """ A form field that validates input as a Singapore National Registration. @@ -116,14 +81,3 @@ def clean(self, value): return value raise ValidationError(self.error_messages['invalid']) - - -class SGNRIC_FINField(SGNRICFINField): # noqa - """ - .. deprecated:: 1.6 - Use `SGNRICFINField` instead. - """ - def __init__(self, *args, **kwargs): - warnings.warn('SGNRIC_FINField is deprecated. Please use SGNRICFINField instead.', - RemovedInLocalflavor20Warning) - super(SGNRIC_FINField, self).__init__(*args, **kwargs) diff --git a/localflavor/si/forms.py b/localflavor/si/forms.py index 1ce9dc224..cca76d2db 100644 --- a/localflavor/si/forms.py +++ b/localflavor/si/forms.py @@ -9,8 +9,6 @@ from django.forms.fields import CharField, ChoiceField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .si_postalcodes import SI_POSTALCODES_CHOICES @@ -136,42 +134,3 @@ class SIPostalCodeSelect(Select): def __init__(self, attrs=None): super(SIPostalCodeSelect, self).__init__(attrs, choices=SI_POSTALCODES_CHOICES) - - -class SIPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - Slovenian phone number field. - - Phone number must contain at least local area code. - Country code can be present. - - Examples: - - * +38640XXXXXX - * 0038640XXXXXX - * 040XXXXXX - * 01XXXXXX - * 0590XXXXX - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Enter phone number in form +386XXXXXXXX or 0XXXXXXXX.'), - } - phone_regex = re.compile('^(?:(?:00|\+)386|0)(\d{7,8})$') - - def clean(self, value): - super(SIPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - - value = value.replace(' ', '').replace('-', '').replace('/', '') - m = self.phone_regex.match(value) - - if m is None: - raise ValidationError(self.error_messages['invalid']) - return m.groups()[0] diff --git a/localflavor/tr/forms.py b/localflavor/tr/forms.py index 2f3d1c6e0..2c05b6b57 100644 --- a/localflavor/tr/forms.py +++ b/localflavor/tr/forms.py @@ -4,16 +4,11 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError -from django.forms.fields import CharField, Field, RegexField, Select -from django.utils.encoding import force_text +from django.forms.fields import Field, RegexField, Select from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - from .tr_provinces import PROVINCE_CHOICES -phone_digits_re = re.compile(r'^(\+90|0)? ?(([1-9]\d{2})|\([1-9]\d{2}\)) ?([2-9]\d{2} ?\d{2} ?\d{2})$') - class TRPostalCodeField(RegexField): """ @@ -44,34 +39,6 @@ def clean(self, value): return value -class TRPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a Turkish phone number. - - The correct format is 0xxx xxx xxxx. +90xxx xxx xxxx and inputs without spaces also - validates. The result is normalized to xxx xxx xxxx format. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must be in 0XXX XXX XXXX format.'), - } - - def clean(self, value): - super(TRPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub('(\(|\)|\s+)', '', force_text(value)) - m = phone_digits_re.search(value) - if m: - return '%s%s' % (m.group(2), m.group(4)) - raise ValidationError(self.error_messages['invalid']) - - class TRIdentificationNumberField(Field): """ A Turkey Identification Number number. diff --git a/localflavor/us/forms.py b/localflavor/us/forms.py index 397191779..25d2823a8 100644 --- a/localflavor/us/forms.py +++ b/localflavor/us/forms.py @@ -7,12 +7,8 @@ from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import CharField, Field, RegexField, Select -from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberFormFieldMixin - -phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$') ssn_re = re.compile(r"^(?P\d{3})[-\ ]?(?P\d{2})[-\ ]?(?P\d{4})$") @@ -46,31 +42,6 @@ def to_python(self, value): return value.strip() -class USPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin): - """ - A form field that validates input as a U.S. phone number. - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - default_error_messages = { - 'invalid': _('Phone numbers must be in XXX-XXX-XXXX format.'), - } - - def clean(self, value): - super(USPhoneNumberField, self).clean(value) - if value in self.empty_values: - return self.empty_value - value = re.sub('(\(|\)|\s+)', '', force_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 USSocialSecurityNumberField(CharField): """ A United States Social Security number. diff --git a/localflavor/us/models.py b/localflavor/us/models.py index aa42e1e8e..de999925b 100644 --- a/localflavor/us/models.py +++ b/localflavor/us/models.py @@ -1,9 +1,6 @@ from django.db.models import CharField from django.utils.translation import ugettext_lazy as _ -from localflavor.deprecation import DeprecatedPhoneNumberField - -from .forms import USPhoneNumberField as USPhoneNumberFormField from .forms import USSocialSecurityNumberField as USSocialSecurityNumberFieldFormField from .forms import USZipCodeField as USZipCodeFormField from .us_states import STATE_CHOICES, USPS_CHOICES @@ -81,30 +78,6 @@ def formfield(self, **kwargs): return super(USZipCodeField, self).formfield(**defaults) -class PhoneNumberField(CharField, DeprecatedPhoneNumberField): - """ - A :class:`~django.db.models.CharField` that checks that the value is a valid U.S.A.-style phone number. - - (in the format ``XXX-XXX-XXXX``). - - .. deprecated:: 1.4 - Use the django-phonenumber-field_ library instead. - - .. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field - """ - - description = _("Phone number") - - def __init__(self, *args, **kwargs): - kwargs['max_length'] = 20 - super(PhoneNumberField, self).__init__(*args, **kwargs) - - def formfield(self, **kwargs): - defaults = {'form_class': USPhoneNumberFormField} - defaults.update(kwargs) - return super(PhoneNumberField, self).formfield(**defaults) - - class USSocialSecurityNumberField(CharField): """ A model field that stores the security number in the format ``XXX-XX-XXXX``. diff --git a/tests/settings.py b/tests/settings.py index a82000a83..754ec7e64 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -18,7 +18,6 @@ 'tests.test_pk', 'tests.test_cu', 'tests.test_generic', - 'tests.test_deprecated', ] SECRET_KEY = 'spam-spam-spam-spam' diff --git a/tests/test_au/forms.py b/tests/test_au/forms.py index ab14cc6fd..4c79aa9eb 100644 --- a/tests/test_au/forms.py +++ b/tests/test_au/forms.py @@ -8,6 +8,5 @@ class AustralianPlaceForm(ModelForm): class Meta: model = AustralianPlace - fields = ('state', 'state_required', 'state_default', 'postcode', - 'postcode_required', 'postcode_default', - 'phone', 'name', 'abn', 'tfn') + fields = ('state', 'state_required', 'state_default', 'postcode', 'postcode_required', 'postcode_default', + 'name', 'abn', 'tfn') diff --git a/tests/test_au/models.py b/tests/test_au/models.py index a8323f9ca..46dd722d1 100644 --- a/tests/test_au/models.py +++ b/tests/test_au/models.py @@ -1,7 +1,7 @@ from django.db import models -from localflavor.au.models import (AUBusinessNumberField, AUCompanyNumberField, AUPhoneNumberField, AUPostCodeField, - AUStateField, AUTaxFileNumberField) +from localflavor.au.models import (AUBusinessNumberField, AUCompanyNumberField, AUPostCodeField, AUStateField, + AUTaxFileNumberField) class AustralianPlace(models.Model): @@ -11,7 +11,6 @@ class AustralianPlace(models.Model): postcode = AUPostCodeField(blank=True) postcode_required = AUPostCodeField() postcode_default = AUPostCodeField(default="2500", blank=True) - phone = AUPhoneNumberField(blank=True) name = models.CharField(max_length=20) abn = AUBusinessNumberField() acn = AUCompanyNumberField() diff --git a/tests/test_au/tests.py b/tests/test_au/tests.py index a7161951f..5b47e86ca 100644 --- a/tests/test_au/tests.py +++ b/tests/test_au/tests.py @@ -103,23 +103,6 @@ def test_AUPostCodeField(self): } self.assertFieldOutput(forms.AUPostCodeField, valid, invalid) - def test_AUPhoneNumberField(self): - error_format = ['Phone numbers must contain 10 digits.'] - valid = { - '1234567890': '1234567890', - '0213456789': '0213456789', - '02 13 45 67 89': '0213456789', - '(02) 1345 6789': '0213456789', - '(02) 1345-6789': '0213456789', - '(02)1345-6789': '0213456789', - '0408 123 456': '0408123456', - } - invalid = { - '123': error_format, - '1800DJANGO': error_format, - } - self.assertFieldOutput(forms.AUPhoneNumberField, valid, invalid) - def test_abn(self): error_format = ['Enter a valid ABN.'] valid = { diff --git a/tests/test_be.py b/tests/test_be.py index 3bd1276db..a73069bb0 100644 --- a/tests/test_be.py +++ b/tests/test_be.py @@ -2,7 +2,7 @@ from django.test import SimpleTestCase -from localflavor.be.forms import BEPhoneNumberField, BEPostalCodeField, BEProvinceSelect, BERegionSelect +from localflavor.be.forms import BEPostalCodeField, BEProvinceSelect, BERegionSelect class BELocalFlavorTests(SimpleTestCase): @@ -21,38 +21,6 @@ def test_BEPostalCodeField(self): } self.assertFieldOutput(BEPostalCodeField, valid, invalid) - def test_BEPhoneNumberField(self): - error_format = [ - ('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.') - ] - valid = { - '01 234 56 78': '01 234 56 78', - '01/234.56.78': '01/234.56.78', - '01.234.56.78': '01.234.56.78', - '012 34 56 78': '012 34 56 78', - '012/34.56.78': '012/34.56.78', - '012.34.56.78': '012.34.56.78', - '0412 34 56 78': '0412 34 56 78', - '0412/34.56.78': '0412/34.56.78', - '0412.34.56.78': '0412.34.56.78', - '012345678': '012345678', - '0412345678': '0412345678', - } - invalid = { - '01234567': error_format, - '12/345.67.89': error_format, - '012/345.678.90': error_format, - '012/34.56.789': error_format, - '0123/45.67.89': error_format, - '012/345 678 90': error_format, - '012/34 56 789': error_format, - '012.34 56 789': error_format, - } - self.assertFieldOutput(BEPhoneNumberField, valid, invalid) - def test_BERegionSelect(self): f = BERegionSelect() out = '''''' self.assertHTMLEqual(f.render('license', 'BJ'), out) - def test_HRPhoneNumberField(self): - error_invalid = ['Enter a valid phone number'] - error_area = ['Enter a valid area or mobile network code'] - error_number = ['The phone number is too long'] - valid = { - '+38511234567': '+38511234567', - '0038511234567': '+38511234567', - '011234567': '+38511234567', - '+38521123456': '+38521123456', - '0038521123456': '+38521123456', - '021123456': '+38521123456', - } - invalid = { - '123456789': error_invalid, - '0811234567': error_area, - '0111234567': error_number, - } - self.assertFieldOutput(HRPhoneNumberField, valid, invalid) - def test_HRLicensePlateField(self): error_invalid = ['Enter a valid vehicle license plate number'] error_area = ['Enter a valid location code'] diff --git a/tests/test_id.py b/tests/test_id.py index 8feead932..466a9c5fa 100644 --- a/tests/test_id.py +++ b/tests/test_id.py @@ -3,7 +3,7 @@ from django.test import SimpleTestCase from localflavor.id_.forms import (IDLicensePlateField, IDLicensePlatePrefixSelect, IDNationalIdentityNumberField, - IDPhoneNumberField, IDPostCodeField, IDProvinceSelect) + IDPostCodeField, IDProvinceSelect) class IDLocalFlavorTests(SimpleTestCase): @@ -108,25 +108,6 @@ def test_IDLicensePlatePrefixSelect(self): ''' self.assertHTMLEqual(f.render('codes', 'BE'), out) - def test_IDPhoneNumberField(self): - error_invalid = ['Enter a valid phone number'] - valid = { - '0812-3456789': '0812-3456789', - '081234567890': '081234567890', - '021 345 6789': '021 345 6789', - '0213456789': '0213456789', - '+62-21-3456789': '+62-21-3456789', - '(021) 345 6789': '(021) 345 6789', - } - invalid = { - '0123456789': error_invalid, - '+62-021-3456789': error_invalid, - '+62-0812-3456789': error_invalid, - '0812345678901': error_invalid, - 'foo': error_invalid, - } - self.assertFieldOutput(IDPhoneNumberField, valid, invalid) - def test_IDPostCodeField(self): error_invalid = ['Enter a valid post code'] valid = { diff --git a/tests/test_il.py b/tests/test_il.py index d49ffe7b2..5cd6600bd 100644 --- a/tests/test_il.py +++ b/tests/test_il.py @@ -2,7 +2,7 @@ from django.test import SimpleTestCase -from localflavor.il.forms import ILIDNumberField, ILMobilePhoneNumberField, ILPostalCodeField +from localflavor.il.forms import ILIDNumberField, ILPostalCodeField class ILLocalFlavorTests(SimpleTestCase): @@ -40,33 +40,3 @@ def test_ILIDNumberField(self): '0001': error_invalid, } self.assertFieldOutput(ILIDNumberField, valid, invalid) - - def test_ILMobilePhoneNumber(self): - error_invalid = ['Enter a valid Mobile Number.'] - valid = { - '0500000000': '0500000000', - '0522222222': '0522222222', - '0533333333': '0533333333', - '0544444444': '0544444444', - '0555555555': '0555555555', - '0566666666': '0566666666', - '0577777777': '0577777777', - '0588888888': '0588888888', - '0599999999': '0599999999', - '052-2222222': '052-2222222', - '52-2222222': '52-2222222', - '525555555': '525555555', - '(050)-1111111': '(050)-1111111', - '(050)1111111': '(050)1111111' - } - invalid = { - '05556': error_invalid, - '0605555555': error_invalid, - '050)1111111': error_invalid, - '55--2222222': error_invalid, - '0511111111': error_invalid, - '05777777': error_invalid, - '05555555555': error_invalid, - '0054673446': error_invalid, - } - self.assertFieldOutput(ILMobilePhoneNumberField, valid, invalid) diff --git a/tests/test_in.py b/tests/test_in.py index 156ee1cdf..c586e1ae5 100644 --- a/tests/test_in.py +++ b/tests/test_in.py @@ -2,28 +2,10 @@ from django.test import SimpleTestCase -from localflavor.in_.forms import INAadhaarNumberField, INPhoneNumberField, INStateField, INStateSelect, INZipCodeField +from localflavor.in_.forms import INAadhaarNumberField, INStateField, INStateSelect, INZipCodeField class INLocalFlavorTests(SimpleTestCase): - def test_INPhoneNumberField(self): - error_format = ['Phone numbers must be in 02X-8X or 03X-7X or 04X-6X format.'] - valid = { - '0423-2443667': '0423-2443667', - '0423 2443667': '0423 2443667', - '04236-244366': '04236-244366', - '040-24436678': '040-24436678', - } - invalid = { - '04-2443667': error_format, - '423-2443667': error_format, - '0423-9442667': error_format, - '0423-0443667': error_format, - '0423-244366': error_format, - '04232442667': error_format, - '0423DJANGO': error_format, - } - self.assertFieldOutput(INPhoneNumberField, valid, invalid) def test_INPStateSelect(self): f = INStateSelect() diff --git a/tests/test_is.py b/tests/test_is.py index f243aebfd..a34f7606d 100644 --- a/tests/test_is.py +++ b/tests/test_is.py @@ -2,7 +2,7 @@ from django.test import SimpleTestCase -from localflavor.is_.forms import ISIdNumberField, ISPhoneNumberField, ISPostalCodeSelect +from localflavor.is_.forms import ISIdNumberField, ISPostalCodeSelect class ISLocalFlavorTests(SimpleTestCase): @@ -181,22 +181,3 @@ def test_ISIdNumberField(self): } self.assertFieldOutput(ISIdNumberField, valid, invalid) - - def test_ISPhoneNumberField(self): - error_invalid = ['Enter a valid value.'] - error_atleast = ['Ensure this value has at least 7 characters (it has 6).'] - error_atmost = ['Ensure this value has at most 8 characters (it has 9).'] - valid = { - '1234567': '1234567', - '123 4567': '1234567', - '123-4567': '1234567', - } - invalid = { - '123-456': error_invalid, - '123456': error_atleast + error_invalid, - '123456555': error_atmost + error_invalid, - 'abcdefg': error_invalid, - ' 1234567 ': error_atmost + error_invalid, - ' 12367 ': error_invalid - } - self.assertFieldOutput(ISPhoneNumberField, valid, invalid) diff --git a/tests/test_it.py b/tests/test_it.py index 531e5697c..55e42fade 100644 --- a/tests/test_it.py +++ b/tests/test_it.py @@ -4,8 +4,8 @@ from django.test import SimpleTestCase -from localflavor.it.forms import (ITPhoneNumberField, ITRegionProvinceSelect, ITRegionSelect, - ITSocialSecurityNumberField, ITVatNumberField, ITZipCodeField) +from localflavor.it.forms import (ITRegionProvinceSelect, ITRegionSelect, ITSocialSecurityNumberField, ITVatNumberField, + ITZipCodeField) class ITLocalFlavorTests(SimpleTestCase): @@ -240,31 +240,3 @@ def test_ITVatNumberField(self): 'A7973780013': error_invalid, } self.assertFieldOutput(ITVatNumberField, valid, invalid) - - def test_ITPhoneNumberField(self): - error_format = ['Enter a valid Italian phone number.'] - valid = { - '+39 347 1234567': '347 1234567', - '39 347 123 4567': '347 1234567', - '347-1234567': '347 1234567', - '3471234567': '347 1234567', - '+39 347 12345678': '347 12345678', - '39 347 123 45678': '347 12345678', - '347-12345678': '347 12345678', - '34712345678': '347 12345678', - '+39 347 123456': '347 123456', - '39 347 123 456': '347 123456', - '347-123456': '347 123456', - '347123456': '347 123456', - '+39 0861 12345678': '0861 12345678', - '39 0861 1234 5678': '0861 12345678', - '0861-12345678': '0861 12345678', - '0861 12345': '0861 12345', - } - invalid = { - '+44 347 1234567': error_format, - '14471234567': error_format, - '0861 123456789': error_format, - '08661234567890': error_format, - } - self.assertFieldOutput(ITPhoneNumberField, valid, invalid) diff --git a/tests/test_lt.py b/tests/test_lt.py index b9f335e97..e779cb15e 100644 --- a/tests/test_lt.py +++ b/tests/test_lt.py @@ -3,7 +3,7 @@ from django.test import SimpleTestCase -from localflavor.lt.forms import LTCountySelect, LTIDCodeField, LTMunicipalitySelect, LTPhoneField, LTPostalCodeField +from localflavor.lt.forms import LTCountySelect, LTIDCodeField, LTMunicipalitySelect, LTPostalCodeField class LTLocalFlavorTests(SimpleTestCase): @@ -133,108 +133,3 @@ def test_LTMunicipalitySelect(self): """ self.assertHTMLEqual(f.render('test', None), expected) - - def test_LTPhoneField(self): - errors = LTPhoneField().error_messages - invalid = {'8 600 00 00o': [errors['non-digit']], - '8 600 00 000 o': [errors['non-digit']], - 'o 600 00 000': [errors['non-digit']]} - self.assertFieldOutput(LTPhoneField, {}, invalid) - - def test_LTPhoneField_emergency(self): - errors = LTPhoneField().error_messages - - valid = {'112': '112', '01': '01', '02': '02', '03': '03', '04': '04'} - invalid = {'1112': [errors['no-parse']]} - self.assertFieldOutput(LTPhoneField, valid, invalid, - field_kwargs={'emergency': True, - 'mobile': False, - 'landline': False}) - - self.assertFieldOutput(LTPhoneField, {}, {'112': [errors['no-parse']]}, - field_kwargs={'emergency': False, - 'mobile': False, - 'landline': False}) - - def test_LTPhoneField_mobile(self): - errors = LTPhoneField().error_messages - valid = {'8 600 00 000': '+37060000000', - '370 600 00 000': '+37060000000', - '+370 612 34 567': '+37061234567'} - invalid = {'8 600 00 00': [errors['no-parse']], - '370 600 00 00': [errors['no-parse']], - '370 600 00 0': [errors['no-parse']], - '860 000 00 000': [errors['no-parse']]} - - self.assertFieldOutput(LTPhoneField, valid, invalid, - field_kwargs={'landline': False}) - - self.assertFieldOutput(LTPhoneField, {}, - {'8 600 00 000': [errors['no-parse']], - '370 600 00 000': [errors['no-parse']], - '+370 612 34 567': [errors['no-parse']]}, - field_kwargs={'mobile': False, - 'landline': False}) - - def test_LTPhoneField_service(self): - errors = LTPhoneField().error_messages - valid = {'8 800 00 000': '+37080000000', - '370 800 00 000': '+37080000000', - '+370 800 34 567': '+37080034567'} - invalid = {'8 800 00 00': [errors['no-parse']], - '370 800 00 00': [errors['no-parse']], - '370 800 00 0': [errors['no-parse']], - '860 800 00 000': [errors['no-parse']], - '8 812 00 000': [errors['no-parse']], - '370 812 00 000': [errors['no-parse']]} - - self.assertFieldOutput(LTPhoneField, valid, invalid, - field_kwargs={'landline': False, - 'mobile': False, - 'service': True}) - - self.assertFieldOutput(LTPhoneField, {}, - {'8 800 00 000': [errors['no-parse']], - '370 800 00 000': [errors['no-parse']], - '+370 800 34 567': [errors['no-parse']]}, - field_kwargs={'mobile': False, - 'landline': False, - 'service': False}) - - def test_LTPhoneField_landline_local(self): - errors = LTPhoneField().error_messages - - valid = {"2123456": "+37052123456", - "123456": "123456", - "12345": "12345"} - invalid = {"1234": [errors['no-parse']]} - - self.assertFieldOutput(LTPhoneField, valid, invalid, - field_kwargs={'landline': True, - 'mobile': False, - 'landline_local': True}) - - invalid = {"2123456": [errors['no-parse']], - "123456": [errors['no-parse']], - "12345": [errors['no-parse']], - "1234": [errors['no-parse']]} - - self.assertFieldOutput(LTPhoneField, {}, invalid, - field_kwargs={'mobile': False}) - - self.assertRaises(ValueError, LTPhoneField, landline=False, - landline_local=True) - - def test_LTPhoneField_landline(self): - errors = LTPhoneField().error_messages - - valid = {'850000000': '+37050000000', - '37050000000': '+37050000000', - '+37050000000': '+37050000000'} - invalid = {'3705000000': [errors['no-parse']], - '370500000000': [errors['no-parse']], - '50000000': [errors['no-parse']], - '800023456': [errors['no-parse']]} - - self.assertFieldOutput(LTPhoneField, valid, invalid, - field_kwargs={'mobile': False}) diff --git a/tests/test_nl/forms.py b/tests/test_nl/forms.py index 18601557b..741401de1 100644 --- a/tests/test_nl/forms.py +++ b/tests/test_nl/forms.py @@ -7,4 +7,4 @@ class NLPlaceForm(ModelForm): class Meta: model = NLPlace - fields = ('zipcode', 'province', 'sofinr', 'bsn', 'phone', 'bankaccount') + fields = ('zipcode', 'province', 'bsn') diff --git a/tests/test_nl/models.py b/tests/test_nl/models.py index 8af899fa1..65b9b60fc 100644 --- a/tests/test_nl/models.py +++ b/tests/test_nl/models.py @@ -1,18 +1,13 @@ from django.db import models -from localflavor.nl.models import (NLBankAccountNumberField, NLBSNField, NLPhoneNumberField, NLProvinceField, - NLSoFiNumberField, NLZipCodeField) +from localflavor.nl.models import NLBSNField, NLProvinceField, NLZipCodeField class NLPlace(models.Model): zipcode = NLZipCodeField() province = NLProvinceField(default='ZH') - - sofinr = NLSoFiNumberField() bsn = NLBSNField() - phone = NLPhoneNumberField() - bankaccount = NLBankAccountNumberField() class Meta: app_label = 'test_nl' diff --git a/tests/test_nl/tests.py b/tests/test_nl/tests.py index 95303dad5..a3b09f0ac 100644 --- a/tests/test_nl/tests.py +++ b/tests/test_nl/tests.py @@ -11,7 +11,7 @@ class NLLocalFlavorValidatorTests(SimpleTestCase): - def assert_validator(self, validator, valid=[], invalid=[]): + def assert_validator(self, validator, valid=(), invalid=()): for item in valid: validator(item) @@ -45,46 +45,6 @@ def test_NLBSNValidator(self): 'foo', ] self.assert_validator(validators.NLBSNFieldValidator(), valid, invalid) - self.assert_validator(validators.NLSoFiNumberFieldValidator(), valid, invalid) - - def test_NLPhoneNumberValidator(self): - valid = [ - '0123456789', - '012-3456789', - '+31-12-3456789', - '(0123) 456789', - ] - invalid = [ - '(010) 12345678', - '06-123456789', - '+31 6123456789', - 'foo', - ] - self.assert_validator(validators.NLPhoneNumberFieldValidator(), valid, invalid) - - def test_NLPhoneNumberValidator_deconstruct(self): - nlphone1 = validators.NLPhoneNumberFieldValidator() - nlphone2 = validators.NLPhoneNumberFieldValidator() - self.assertEqual(nlphone1, nlphone2, msg="NLPhoneNumberFieldValidator are not equal.") - - # Call to the required deconstruct method to see if it exists. - nlphone1.deconstruct() - - def test_NLBankAccountNumberFieldValidator(self): - valid = [ - '0417164300', - '755490975', - '12345', - ] - invalid = [ - '7584955151', - 'foo', - '0', - '75849551519', - '00417164300', - '75849551', - ] - self.assert_validator(validators.NLBankAccountNumberFieldValidator(), valid, invalid) class NLLocalFlavorModelTests(SimpleTestCase): @@ -101,19 +61,13 @@ def test_NL_model(self): m = NLPlace(**{ 'zipcode': '2403BW', 'province': 'OV', - 'sofinr': '123456782', 'bsn': '123456782', - 'phone': '012-3456789', - 'bankaccount': '0417164300' }) self.assertEqual(str(m.zipcode), '2403BW') self.assertEqual(str(m.province), 'OV') - self.assertEqual(str(m.sofinr), '123456782') self.assertEqual(str(m.bsn), '123456782') - self.assertEqual(str(m.phone), '012-3456789') - self.assertEqual(str(m.bankaccount), '0417164300') m.clean_fields() @@ -121,10 +75,7 @@ def test_NL_model_cleanup(self): m = NLPlace(**{ 'zipcode': '2403 bwa', 'province': 'OV', - 'sofinr': '123456782', 'bsn': '123456782', - 'phone': '012-3456789', - 'bankaccount': '0417164300' }) # zipcode is not quite right, so it should raise an error self.assertRaises(ValidationError, lambda: m.clean_fields()) @@ -172,24 +123,6 @@ def test_NLProvinceSelect(self): ''' self.assertHTMLEqual(f.render('provinces', 'OV'), out) - def test_NLPhoneNumberField(self): - error_invalid = ['Enter a valid phone number.'] - valid = { - '012-3456789': '012-3456789', - '0123456789': '0123456789', - '+31-12-3456789': '+31-12-3456789', - '(0123) 456789': '(0123) 456789', - '0623456789': '0623456789', - - } - invalid = { - '(010) 12345678': error_invalid, - '06-123456789': error_invalid, - '+31 6123456789': error_invalid, - 'foo': error_invalid, - } - self.assertFieldOutput(forms.NLPhoneNumberField, valid, invalid) - def test_NLBSNFormField(self): error_invalid = ['Enter a valid BSN.'] valid = { @@ -202,22 +135,11 @@ def test_NLBSNFormField(self): } self.assertFieldOutput(forms.NLBSNFormField, valid, invalid) - sofinr_error_invalid = ['Enter a valid SoFi number.'] - sofinr_invalid = { - '000000000': sofinr_error_invalid, - '123456789': sofinr_error_invalid, - 'foo': sofinr_error_invalid, - } - self.assertFieldOutput(forms.NLSoFiNumberField, valid, sofinr_invalid) - def test_NL_ModelForm_errors(self): form = NLPlaceForm({ 'zipcode': 'invalid', 'province': 'invalid', - 'sofinr': 'invalid', 'bsn': 'invalid', - 'phone': 'invalid', - 'bankaccount': 'invalid', }) self.assertFalse(form.is_valid()) @@ -225,18 +147,12 @@ def test_NL_ModelForm_errors(self): invalid_choice = 'Select a valid choice. invalid is not one of the available choices.' self.assertEqual(form.errors['zipcode'], ['Enter a valid zip code.']) self.assertEqual(form.errors['province'], [invalid_choice]) - self.assertEqual(form.errors['sofinr'], ['Enter a valid SoFi number.']) self.assertEqual(form.errors['bsn'], ['Enter a valid BSN.']) - self.assertEqual(form.errors['phone'], ['Enter a valid phone number.']) - self.assertEqual(form.errors['bankaccount'], ['Enter a valid bank account number.']) def test_NL_ModelForm_valid(self): form = NLPlaceForm({ 'zipcode': '2233 AB', 'province': 'OV', - 'sofinr': '123456782', 'bsn': '123456782', - 'phone': '0623456789', - 'bankaccount': '0417164300' }) self.assertTrue(form.is_valid()) diff --git a/tests/test_no.py b/tests/test_no.py index 86bb6bf03..e59c9598a 100644 --- a/tests/test_no.py +++ b/tests/test_no.py @@ -3,8 +3,7 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.translation import override -from localflavor.no.forms import (NOBankAccountNumber, NOMunicipalitySelect, NOPhoneNumberField, NOSocialSecurityNumber, - NOZipCodeField) +from localflavor.no.forms import NOBankAccountNumber, NOMunicipalitySelect, NOSocialSecurityNumber, NOZipCodeField class NOLocalFlavorTests(SimpleTestCase): @@ -20,25 +19,6 @@ def test_NOZipCodeField(self): } self.assertFieldOutput(NOZipCodeField, valid, invalid) - def test_NOPhoneNumberField(self): - error_format = [_('A phone number must be 8 digits and may have country code')] - valid = { - '12345678': '12345678', - '12 34 56 78': '12 34 56 78', - '123 45 678': '123 45 678', - '+4712345678': '+4712345678', - '+47 12345678': '+47 12345678', - '+47 12 34 56 78': '+47 12 34 56 78', - '+47 123 45 678': '+47 123 45 678', - } - invalid = { - '12': error_format, # to few digits - 'abcdefgh': error_format, # illegal characters - '1234567890': error_format, # to many digits - '+4512345678': error_format, # wrong country code - } - self.assertFieldOutput(NOPhoneNumberField, valid, invalid) - def test_NOBankAccountNumber(self): error_format = [_('Enter a valid Norwegian bank account number.')] error_checksum = [_('Invalid control digit. Enter a valid Norwegian bank account number.')] diff --git a/tests/test_nz.py b/tests/test_nz.py index 3525cab6c..1ae5e3daa 100644 --- a/tests/test_nz.py +++ b/tests/test_nz.py @@ -2,8 +2,8 @@ from django.test import SimpleTestCase -from localflavor.nz.forms import (NZBankAccountNumberField, NZNorthIslandCouncilSelect, NZPhoneNumberField, - NZPostCodeField, NZProvinceSelect, NZRegionSelect, NZSouthIslandCouncilSelect) +from localflavor.nz.forms import (NZBankAccountNumberField, NZNorthIslandCouncilSelect, NZPostCodeField, + NZProvinceSelect, NZRegionSelect, NZSouthIslandCouncilSelect) class NZLocalFlavorTests(SimpleTestCase): @@ -138,30 +138,6 @@ def test_NZPostCodeField(self): } self.assertFieldOutput(NZPostCodeField, valid, invalid) - def test_NZPhoneNumberField(self): - error_format = ['Invalid phone number.'] - valid = { - '0800 DJANGO': '0800DJANGO', - '0800 123456': '0800123456', - '(0800) 123456': '0800123456', - '0800 - 123456': '0800123456', - '0800_DJANGO': '0800DJANGO', - '021 123 4567': '0211234567', - '021 123 45678': '02112345678', - '021 - 123567': '021123567', - '+64 21 123 4567': '0064211234567', - '++64 21 123 4567': '0064211234567', - '0064 21 123 4567': '0064211234567', - '03 123 4567': '031234567', - '+ 64 3 123 4567': '006431234567', - '++ 64 3 123 4567': '006431234567', - } - invalid = { - '+64 800 DJANGO': error_format, - '03 123 456': error_format, - } - self.assertFieldOutput(NZPhoneNumberField, valid, invalid) - def test_NZBankAccountNumberField(self): error_format = ['Invalid bank account number.'] valid = { diff --git a/tests/test_pk/forms.py b/tests/test_pk/forms.py index 33171d56f..b027c92e1 100644 --- a/tests/test_pk/forms.py +++ b/tests/test_pk/forms.py @@ -9,4 +9,4 @@ class PakistaniPlaceForm(ModelForm): class Meta: model = PakistaniPlace fields = ('state', 'state_required', 'state_default', 'postcode', 'postcode_required', 'postcode_default', - 'phone', 'name') + 'name') diff --git a/tests/test_pk/models.py b/tests/test_pk/models.py index 6057683ca..28a723837 100644 --- a/tests/test_pk/models.py +++ b/tests/test_pk/models.py @@ -1,6 +1,6 @@ from django.db import models -from localflavor.pk.models import PKPhoneNumberField, PKPostCodeField, PKStateField +from localflavor.pk.models import PKPostCodeField, PKStateField class PakistaniPlace(models.Model): @@ -10,5 +10,4 @@ class PakistaniPlace(models.Model): postcode = PKPostCodeField(blank=True) postcode_required = PKPostCodeField() postcode_default = PKPostCodeField(default="44000", blank=True) - phone = PKPhoneNumberField(blank=True) name = models.CharField(max_length=20) diff --git a/tests/test_pk/tests.py b/tests/test_pk/tests.py index 69271f9f6..a7d1c101f 100644 --- a/tests/test_pk/tests.py +++ b/tests/test_pk/tests.py @@ -4,7 +4,7 @@ from django.test import TestCase -from localflavor.pk.forms import PKPhoneNumberField, PKPostCodeField, PKStateSelect +from localflavor.pk.forms import PKPostCodeField, PKStateSelect from .forms import PakistaniPlaceForm @@ -88,24 +88,3 @@ def test_PKPostCodeField(self): '123456': error_format, } self.assertFieldOutput(PKPostCodeField, valid, invalid) - - def test_PKPhoneNumberField(self): - error_format = ['Phone numbers must contain 9, 10 or 11 digits.'] - valid = { - '123456789': '123456789', - '1234567890': '1234567890', - '12345678901': '12345678901', - '0513456789': '0513456789', - '051 3456789': '0513456789', - '051 3456 789': '0513456789', - '(051) 3456 789': '0513456789', - '(051) 3456-789': '0513456789', - '(051)3456-789': '0513456789', - '0300 1234567': '03001234567', - '0300 1234 567': '03001234567', - } - invalid = { - '123': error_format, - '1800DJANGO': error_format, - } - self.assertFieldOutput(PKPhoneNumberField, valid, invalid) diff --git a/tests/test_pt.py b/tests/test_pt.py index c5adf8a1d..e16b2e528 100644 --- a/tests/test_pt.py +++ b/tests/test_pt.py @@ -4,8 +4,7 @@ from django.test import SimpleTestCase -from localflavor.pt.forms import (PTCitizenCardNumberField, PTPhoneNumberField, PTRegionSelect, - PTSocialSecurityNumberField, PTZipCodeField) +from localflavor.pt.forms import PTCitizenCardNumberField, PTRegionSelect, PTSocialSecurityNumberField, PTZipCodeField class PTLocalFlavorTests(SimpleTestCase): @@ -42,28 +41,6 @@ def test_PTCitizenCardNumberField(self): } self.assertFieldOutput(PTCitizenCardNumberField, valid, invalid) - def test_PTPhoneNumberField(self): - error_invalid = ['Phone numbers have at least 3 and at most 9 digits ' - 'and may optionally be prefixed with \'00351\' or \'+351\'.'] - valid = { - '117': '117', - '4800': '4800', - '16912': '16912', - '917845189': '917845189', - '+351 16912': '+35116912', - '91 784 5189': '917845189', - '+351 91 111': '+35191111', - '00351 917 845 189': '00351917845189', - '+351 917 845 189': '+351917845189', - } - invalid = { - '1': error_invalid, - '21': error_invalid, - '091 456 987 1': error_invalid, - '00+351917845189': error_invalid, - } - self.assertFieldOutput(PTPhoneNumberField, valid, invalid) - def test_PTRegionSelect(self): field = PTRegionSelect() output = '''') - def test_USPhoneNumberField(self): - error_format = ['Phone numbers must be in XXX-XXX-XXXX format.'] - valid = { - '312-555-1212': '312-555-1212', - '3125551212': '312-555-1212', - '312 555-1212': '312-555-1212', - '(312) 555-1212': '312-555-1212', - '312 555 1212': '312-555-1212', - '312.555.1212': '312-555-1212', - '312.555-1212': '312-555-1212', - ' (312) 555.1212 ': '312-555-1212', - } - invalid = { - '555-1212': error_format, - '312-55-1212': error_format, - } - self.assertFieldOutput(forms.USPhoneNumberField, valid, invalid) - def test_USStateField(self): error_invalid = ['Enter a U.S. state or territory.'] valid = {