Skip to content

Commit 67ca33e

Browse files
committed
Deprecated NLBankAccountNumberFieldValidator and NLPhoneNumberFieldValidator.
The validators as well as the fields will be removed in the next version of django-localflavor. Technically this breaks semver but I think it's ok because it's a bug fix for the previous release. These should have been deprecated along with the fields.
1 parent 4d0c6ac commit 67ca33e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Modifications to existing flavors:
99
- Changed RUT to NIT in CONITField form field error message.
1010
- Fixed validation of Czech birth numbers for birth dates after 1st January 1954
1111
(`gh-315 <https://github.com/django/django-localflavor/issues/315>`_).
12+
- Deprecated `nl.validators.NLBankAccountNumberFieldValidator` and `nl.validators.NLPhoneNumberFieldValidator`.
1213

1314
1.6 (2017-11-22)
1415
------------------

localflavor/nl/validators.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ class NLPhoneNumberFieldValidator(object):
8888
Validation for Dutch phone numbers.
8989
9090
.. versionadded:: 1.3
91+
.. deprecated:: 1.6.1
92+
Use the django-phonenumber-field_ library instead.
93+
94+
.. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field
9195
"""
9296

97+
def __init__(self):
98+
warnings.warn('NLPhoneNumberFieldValidator is deprecated in favor of the django-phonenumber-field library.',
99+
RemovedInLocalflavor20Warning)
100+
super(NLPhoneNumberFieldValidator, self).__init__()
101+
93102
def __eq__(self, other):
94103
# The is no outside modification of properties so this should always be true by default.
95104
return True
@@ -116,6 +125,10 @@ class NLBankAccountNumberFieldValidator(RegexValidator):
116125
http://www.credit-card.be/BankAccount/ValidationRules.htm#NL_Validation
117126
118127
.. versionadded:: 1.1
128+
.. deprecated:: 1.6.1
129+
Use the django-phonenumber-field_ library instead.
130+
131+
.. _django-phonenumber-field: https://github.com/stefanfoulis/django-phonenumber-field
119132
"""
120133

121134
default_error_messages = {
@@ -124,6 +137,8 @@ class NLBankAccountNumberFieldValidator(RegexValidator):
124137
}
125138

126139
def __init__(self, regex=None, message=None, code=None):
140+
warnings.warn('NLBankAccountNumberFieldValidator is deprecated in favor of the django-phonenumber-field '
141+
'library.', RemovedInLocalflavor20Warning)
127142
super(NLBankAccountNumberFieldValidator, self).__init__(regex='^[0-9]+$',
128143
message=self.default_error_messages['invalid'])
129144
self.no_leading_zeros_regex = re.compile('[1-9]+')

tests/test_deprecated/tests.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from localflavor.nl.forms import NLSoFiNumberField as NLSoFiNumberFormField
3030
from localflavor.nl.forms import NLPhoneNumberField
3131
from localflavor.nl.models import NLSoFiNumberField
32-
from localflavor.nl.validators import NLSoFiNumberFieldValidator
32+
from localflavor.nl.validators import (NLBankAccountNumberFieldValidator, NLPhoneNumberFieldValidator,
33+
NLSoFiNumberFieldValidator)
3334
from localflavor.no.forms import NOPhoneNumberField
3435
from localflavor.nz.forms import NZPhoneNumberField
3536
from localflavor.pk import models as pk_models
@@ -60,7 +61,7 @@ class PhoneNumberModel(Model):
6061
self.assertIn('deprecated::', field.__class__.__doc__)
6162

6263
def test_PhoneNumberFormField_deprecated(self):
63-
deprecated_form_fields = (
64+
deprecated_classes = (
6465
AUPhoneNumberField,
6566
BEPhoneNumberField,
6667
BRPhoneNumberField,
@@ -82,6 +83,7 @@ def test_PhoneNumberFormField_deprecated(self):
8283
ITPhoneNumberField,
8384
LTPhoneField,
8485
NLPhoneNumberField,
86+
NLPhoneNumberFieldValidator,
8587
NOPhoneNumberField,
8688
NZPhoneNumberField,
8789
PKPhoneNumberField,
@@ -95,7 +97,7 @@ def test_PhoneNumberFormField_deprecated(self):
9597

9698
with warnings.catch_warnings(record=True) as recorded:
9799
warnings.simplefilter("always")
98-
for form_field in deprecated_form_fields:
100+
for form_field in deprecated_classes:
99101
self.assertIn('deprecated::', form_field.__doc__)
100102
form_field()
101103

@@ -134,3 +136,9 @@ class BankAccountModel(Model):
134136

135137
nl_bank_account_field = BankAccountModel._meta.get_field('nl_bank_account')
136138
self.assertIn('deprecated::', nl_bank_account_field.__class__.__doc__)
139+
140+
with warnings.catch_warnings(record=True) as recorded:
141+
warnings.simplefilter('always')
142+
NLBankAccountNumberFieldValidator()
143+
144+
self.assertTrue(all(w.category is RemovedInLocalflavor20Warning for w in recorded))

0 commit comments

Comments
 (0)