Skip to content

Commit

Permalink
Deprecating Phone Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirnani committed Nov 11, 2016
1 parent 9a336e4 commit 5132306
Show file tree
Hide file tree
Showing 39 changed files with 168 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ support for an unsupported version of Django.
**2014-12-10 - 1.1**: Django 1.5 - 1.7

**2013-07-29 - 1.0**: Django 1.5 - 1.6

4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Other changes:
(`gh-257 <https://github.com/django/django-localflavor/pull/257>`_). Users will need to generate migrations for any
model fields they use with 'makemigrations'.

- Deprecated Phone Number fields
(`gh-262 <https://github.com/django/django-localflavor/pull/262>`_)


1.3 (2016-05-06)
------------------

Expand Down
17 changes: 17 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ Version numbers follow the appropriate Python standards, e.g. PEPs 386_ and 440_
.. _440: http://www.python.org/dev/peps/pep-0440/
.. _`Django's release process`: https://docs.djangoproject.com/en/dev/internals/release-process/

Roadmap
-------

django-localflavor releases follows `semver`_.
Within one month of django release we would release a new verision.
We might have an extra release if there is lots features in between django releases.

=========== ===============
Version Date
=========== ===============
1.4 November 2016
1.x ...
2.0 January 2018
=========== ===============

.. _semver: http://semver.org/

How to migrate
==============

Expand Down
4 changes: 3 additions & 1 deletion localflavor/au/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .au_states import STATE_CHOICES
from .validators import AUBusinessNumberFieldValidator, AUTaxFileNumberFieldValidator

Expand All @@ -33,7 +35,7 @@ def __init__(self, max_length=4, min_length=None, *args, **kwargs):
max_length, min_length, *args, **kwargs)


class AUPhoneNumberField(CharField):
class AUPhoneNumberField(CharField, PhoneNumberFormFieldMixin):
"""
A form field that validates input as an Australian phone number.
Expand Down
6 changes: 6 additions & 0 deletions localflavor/au/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class AUPhoneNumberField(CharField):
"""A model field that checks that the value is a valid Australian phone number (ten digits)."""

description = _("Australian Phone number")
system_check_deprecated_details = {
'msg': (
"PhoneNumberFields are deprecated.",
),
'hint': 'Use django-phonenumber-field library instead.'
}

def __init__(self, *args, **kwargs):
kwargs['max_length'] = 20
Expand Down
4 changes: 3 additions & 1 deletion localflavor/be/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.forms.fields import RegexField, Select
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .be_provinces import PROVINCE_CHOICES
from .be_regions import REGION_CHOICES

Expand All @@ -28,7 +30,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
max_length, min_length, *args, **kwargs)


class BEPhoneNumberField(RegexField):
class BEPhoneNumberField(RegexField, PhoneNumberFormFieldMixin):
"""
A form field that validates its input as a belgium phone number.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/br/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .br_states import STATE_CHOICES

phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4,5})[-\.]?(\d{4})$')
Expand All @@ -35,7 +37,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
max_length, min_length, *args, **kwargs)


class BRPhoneNumberField(Field):
class BRPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
A form field that validates input as a Brazilian phone number.
Expand Down
3 changes: 2 additions & 1 deletion localflavor/ca/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.checksums import luhn
from localflavor.generic.forms import PhoneNumberFormFieldMixin

phone_digits_re = re.compile(r'^(?:1-?)?(\d{3})[-\.]?(\d{3})[-\.]?(\d{4})$')
sin_re = re.compile(r"^(\d{3})-(\d{3})-(\d{3})$")
Expand Down Expand Up @@ -44,7 +45,7 @@ def clean(self, value):
return "%s %s" % (m.group(1), m.group(2))


class CAPhoneNumberField(Field):
class CAPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""Canadian phone number form field."""

default_error_messages = {
Expand Down
4 changes: 3 additions & 1 deletion localflavor/ch/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from ..generic import validators
from .ch_states import STATE_CHOICES

Expand Down Expand Up @@ -38,7 +40,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
super(CHZipCodeField, self).__init__(zip_re, max_length, min_length, *args, **kwargs)


class CHPhoneNumberField(Field):
class CHPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
Validate local Swiss phone number (not international ones).
Expand Down
4 changes: 3 additions & 1 deletion localflavor/cn/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.forms.fields import CharField, RegexField, Select
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .cn_provinces import CN_PROVINCE_CHOICES

__all__ = (
Expand Down Expand Up @@ -167,7 +169,7 @@ def has_valid_checksum(self, value):
return '10X98765432'[checksum_index] == value[-1]


class CNPhoneNumberField(RegexField):
class CNPhoneNumberField(RegexField, PhoneNumberFormFieldMixin):
"""
A form field that validates input as a telephone number in mainland China.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/dk/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.forms import fields, widgets
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .dk_municipalities import DK_MUNICIPALITIES
from .dk_postalcodes import DK_POSTALCODES

Expand Down Expand Up @@ -33,7 +35,7 @@ def __init__(self, attrs=None, *args, **kwargs):
)


class DKPhoneNumberField(fields.RegexField):
class DKPhoneNumberField(fields.RegexField, PhoneNumberFormFieldMixin):
"""
Field with phone number validation.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/es/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from django.utils import six
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .es_provinces import PROVINCE_CHOICES
from .es_regions import REGION_CHOICES

Expand All @@ -33,7 +35,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
max_length, min_length, *args, **kwargs)


class ESPhoneNumberField(RegexField):
class ESPhoneNumberField(RegexField, PhoneNumberFormFieldMixin):
"""
A form field that validates its input as a Spanish phone number.
Expand Down
3 changes: 2 additions & 1 deletion localflavor/fr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.checksums import luhn
from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .fr_department import DEPARTMENT_CHOICES_PER_REGION
from .fr_region import REGION_CHOICES
Expand Down Expand Up @@ -40,7 +41,7 @@ def __init__(self, *args, **kwargs):
super(FRZipCodeField, self).__init__(r'^\d{5}$', *args, **kwargs)


class FRPhoneNumberField(CharField):
class FRPhoneNumberField(CharField, PhoneNumberFormFieldMixin):
"""
Validate local French phone number (not international ones).
Expand Down
2 changes: 2 additions & 0 deletions localflavor/generic/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class RemovedInLocalflavor20Warning(PendingDeprecationWarning):
pass
15 changes: 15 additions & 0 deletions localflavor/generic/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from __future__ import unicode_literals

import warnings

from django import forms

from localflavor.generic.deprecation import RemovedInLocalflavor20Warning
from .validators import IBAN_COUNTRY_CODE_LENGTH, BICValidator, IBANValidator

DEFAULT_DATE_INPUT_FORMATS = (
Expand Down Expand Up @@ -127,3 +132,13 @@ def prepare_value(self, value):
if value is not None:
return value.upper()
return value


class PhoneNumberFormFieldMixin(object):
def __init__(self):
super(PhoneNumberFormFieldMixin, self).__init__()
warnings.warn(
"PhoneNumber form fields are deprecated in favor of the "
"django-phonenumber-field library.",
RemovedInLocalflavor20Warning,
)
6 changes: 4 additions & 2 deletions localflavor/gr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

NUMERIC_RE = re.compile('^\d+$')


Expand Down Expand Up @@ -65,7 +67,7 @@ def clean(self, value):
return val


class GRPhoneNumberField(Field):
class GRPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
Greek general phone field.
Expand All @@ -92,7 +94,7 @@ def clean(self, value):
raise ValidationError(self.error_messages['invalid'])


class GRMobilePhoneNumberField(Field):
class GRMobilePhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
Greek mobile phone field.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/hk/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

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):
class HKPhoneNumberField(CharField, PhoneNumberFormFieldMixin):
"""
A form field that validates Hong Kong phone numbers.
Expand Down
3 changes: 2 additions & 1 deletion localflavor/hr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.checksums import luhn
from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .hr_choices import HR_COUNTY_CHOICES, HR_LICENSE_PLATE_PREFIX_CHOICES, HR_PHONE_NUMBER_PREFIX_CHOICES

Expand Down Expand Up @@ -204,7 +205,7 @@ def clean(self, value):
return '%s' % value


class HRPhoneNumberField(Field):
class HRPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
Phone number of Croatia field.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/id_/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

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<prefix>[A-Z]{1,2}) ' +
Expand Down Expand Up @@ -57,7 +59,7 @@ def __init__(self, attrs=None):
super(IDProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)


class IDPhoneNumberField(Field):
class IDPhoneNumberField(Field, PhoneNumberFormFieldMixin):
"""
An Indonesian telephone number field.
Expand Down
3 changes: 2 additions & 1 deletion localflavor/il/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.checksums import luhn
from localflavor.generic.forms import PhoneNumberFormFieldMixin

id_number_re = re.compile(r'^(?P<number>\d{1,8})-?(?P<check>\d)$')
mobile_phone_number_re = re.compile(r'^(\()?0?(5[02-9])(?(1)\))-?\d{7}$') # including palestinian mobile carriers
Expand Down Expand Up @@ -72,7 +73,7 @@ def clean(self, value):
return value


class ILMobilePhoneNumberField(RegexField):
class ILMobilePhoneNumberField(RegexField, PhoneNumberFormFieldMixin):
"""A form field that validates its input as an Israeli Mobile phone number."""

default_error_messages = {
Expand Down
4 changes: 3 additions & 1 deletion localflavor/in_/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .in_states import STATE_CHOICES, STATES_NORMALIZED

phone_digits_re = re.compile(r"""
Expand Down Expand Up @@ -147,7 +149,7 @@ def __init__(self, attrs=None):
super(INStateSelect, self).__init__(attrs, choices=STATE_CHOICES)


class INPhoneNumberField(CharField):
class INPhoneNumberField(CharField, PhoneNumberFormFieldMixin):
"""
INPhoneNumberField validates that the data is a valid Indian phone number, including the STD code.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/is_/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .is_postalcodes import IS_POSTALCODES


Expand Down Expand Up @@ -58,7 +60,7 @@ def _format(self, value):
return force_text(value[:6] + '-' + value[6:])


class ISPhoneNumberField(RegexField):
class ISPhoneNumberField(RegexField, PhoneNumberFormFieldMixin):
"""
Icelandic phone number.
Expand Down
4 changes: 3 additions & 1 deletion localflavor/it/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.forms import PhoneNumberFormFieldMixin

from .it_province import PROVINCE_CHOICES
from .it_region import REGION_CHOICES, REGION_PROVINCE_CHOICES
from .util import ssn_validation, vat_number_validation
Expand Down Expand Up @@ -114,7 +116,7 @@ def clean(self, value):
raise ValidationError(self.error_messages['invalid'])


class ITPhoneNumberField(CharField):
class ITPhoneNumberField(CharField, PhoneNumberFormFieldMixin):
"""
A form field that validates input as an Italian phone number.
Expand Down
Loading

0 comments on commit 5132306

Please sign in to comment.