Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecating Phone Fields #262

Merged
merged 1 commit into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 follow `semver`_.
Within one month of django release we would release a new verision.
We might have an extra release if there are enough features in between django releases.

=========== =========== ===============
Version Django Date
=========== =========== ===============
1.4 1.10 December 2016
1.x ... ...
2.0 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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
A form field that validates input as an Australian phone number.

Expand Down
3 changes: 2 additions & 1 deletion localflavor/au/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db.models import CharField
from django.utils.translation import ugettext_lazy as _

from localflavor.generic.models import DeprecatedPhoneNumberField
from . import forms
from .au_states import STATE_CHOICES
from .validators import AUBusinessNumberFieldValidator, AUTaxFileNumberFieldValidator
Expand Down Expand Up @@ -45,7 +46,7 @@ def formfield(self, **kwargs):
return super(AUPostCodeField, self).formfield(**defaults)


class AUPhoneNumberField(CharField):
class AUPhoneNumberField(CharField, DeprecatedPhoneNumberField):
"""A model field that checks that the value is a valid Australian phone number (ten digits)."""

description = _("Australian Phone number")
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
Validate local Swiss phone number (not international ones).

Expand Down
6 changes: 4 additions & 2 deletions 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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
A form field that validates input as a telephone number in mainland China.

Expand All @@ -183,7 +185,7 @@ def __init__(self, *args, **kwargs):
super(CNPhoneNumberField, self).__init__(PHONE_RE, *args, **kwargs)


class CNCellNumberField(RegexField):
class CNCellNumberField(RegexField, DeprecatedPhoneNumberFormFieldMixin):
"""
A form field that validates input as a cellphone 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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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
16 changes: 16 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,14 @@ def prepare_value(self, value):
if value is not None:
return value.upper()
return value


class DeprecatedPhoneNumberFormFieldMixin(object):
def __init__(self):
super(DeprecatedPhoneNumberFormFieldMixin, self).__init__()
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with Django, I'd rather if you used from __future__ import unicode_literals rather than u prefixes (which are obsolete when dropping support for Python 2).

Django style is:

warnings.warn(
    "PhoneNumber form fields are deprecated in favor of the "
    "django-phonenumber-field library.",
    RemovedInLocalflavor20Warning,
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timgraham I agree this is a good way to go. I'll update the docs that asks for u prefixed strings.
https://django-localflavor.readthedocs.io/en/latest/#adding-flavors

"{} is deprecated in favor of the django-phonenumber-field library.".format(
self.__class__.__name__
),
RemovedInLocalflavor20Warning,
)
8 changes: 8 additions & 0 deletions localflavor/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ def formfield(self, **kwargs):
defaults = {'form_class': BICFormField}
defaults.update(kwargs)
return super(BICField, self).formfield(**defaults)


class DeprecatedPhoneNumberField(object):
def __init__(self):
self.system_check_deprecated_details = {
'msg': self.__class__.__name__ + " is deprecated.",
'hint': 'Use django-phonenumber-field library instead.'
}
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 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):
class HKPhoneNumberField(CharField, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 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<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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
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 DeprecatedPhoneNumberFormFieldMixin

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, DeprecatedPhoneNumberFormFieldMixin):
"""
Icelandic phone number.

Expand Down
Loading