Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20439 -- Started deprecation of IPAddressField

  • Loading branch information...
commit 1a63092981c685214ea189a14007da7bcc823c17 1 parent 8f51ba6
@erikr erikr authored aaugustin committed
View
2  django/db/models/fields/__init__.py
@@ -1312,6 +1312,8 @@ class IPAddressField(Field):
description = _("IPv4 address")
def __init__(self, *args, **kwargs):
+ warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
+ PendingDeprecationWarning)
kwargs['max_length'] = 15
Field.__init__(self, *args, **kwargs)
View
6 django/forms/fields.py
@@ -9,6 +9,7 @@
import os
import re
import sys
+import warnings
from decimal import Decimal, DecimalException
from io import BytesIO
@@ -1144,6 +1145,11 @@ def compress(self, data_list):
class IPAddressField(CharField):
default_validators = [validators.validate_ipv4_address]
+ def __init__(self, *args, **kwargs):
+ warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
+ PendingDeprecationWarning)
+ super(IPAddressField, self).__init__(*args, **kwargs)
+
def to_python(self, value):
if value in self.empty_values:
return ''
View
2  docs/internals/deprecation.txt
@@ -436,6 +436,8 @@ these changes.
:ref:`initial SQL data<initial-sql>` in ``myapp/models/sql/``. Move your
custom SQL files to ``myapp/sql/``.
+* The model and form ``IPAddressField`` will be removed.
+
* FastCGI support via the ``runfcgi`` management command will be
removed. Please deploy your project using WSGI.
View
4 docs/ref/forms/fields.txt
@@ -657,6 +657,10 @@ For each field, we describe the default widget used if you don't specify
.. class:: IPAddressField(**kwargs)
+ .. deprecated:: 1.7
+ This field has been deprecated in favour of
+ :class:`~django.forms.GenericIPAddressField`.
+
* Default widget: :class:`TextInput`
* Empty value: ``''`` (an empty string)
* Normalizes to: A Unicode object.
View
4 docs/ref/models/fields.txt
@@ -849,6 +849,10 @@ An integer. The default form widget for this field is a
.. class:: IPAddressField([**options])
+.. deprecated:: 1.7
+ This field has been deprecated in favour of
+ :class:`~django.db.models.GenericIPAddressField`.
+
An IP address, in string format (e.g. "192.0.2.30"). The default form widget
for this field is a :class:`~django.forms.TextInput`.
View
9 docs/releases/1.7.txt
@@ -529,3 +529,12 @@ to ``utils.py`` in an effort to unify all util and utils references:
``ModelAdmin.get_formsets`` has been deprecated in favor of the new
:meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to
better handle the case of selecting showing inlines on a ``ModelAdmin``.
+
+``IPAddressField``
+~~~~~~~~~~~~~~~~~~
+
+The :class:`django.db.models.IPAddressField` and
+:class:`django.forms.IPAddressField` fields have been deprecated in favor of
+:class:`django.db.models.GenericIPAddressField` and
+:class:`django.forms.GenericIPAddressField`.
+
View
5 tests/field_deconstruction/tests.py
@@ -1,3 +1,4 @@
+import warnings
from django.test import TestCase
from django.db import models
@@ -173,7 +174,9 @@ def test_integer_field(self):
self.assertEqual(kwargs, {})
def test_ip_address_field(self):
- field = models.IPAddressField()
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ field = models.IPAddressField()
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.IPAddressField")
self.assertEqual(args, [])
View
6 tests/forms_tests/tests/test_error_messages.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import warnings
+
from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import *
from django.test import TestCase
@@ -192,7 +194,9 @@ def test_ipaddressfield(self):
'required': 'REQUIRED',
'invalid': 'INVALID IP ADDRESS',
}
- f = IPAddressField(error_messages=e)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ f = IPAddressField(error_messages=e)
self.assertFormErrors(['REQUIRED'], f.clean, '')
self.assertFormErrors(['INVALID IP ADDRESS'], f.clean, '127.0.0')
View
9 tests/forms_tests/tests/test_extra.py
@@ -2,6 +2,7 @@
from __future__ import unicode_literals
import datetime
+import warnings
from django.forms import *
from django.forms.extras import SelectDateWidget
@@ -535,7 +536,9 @@ class ComplexFieldForm(Form):
self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00')
def test_ipaddress(self):
- f = IPAddressField()
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ f = IPAddressField()
self.assertFormErrors(['This field is required.'], f.clean, '')
self.assertFormErrors(['This field is required.'], f.clean, None)
self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
@@ -544,7 +547,9 @@ def test_ipaddress(self):
self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
- f = IPAddressField(required=False)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ f = IPAddressField(required=False)
self.assertEqual(f.clean(''), '')
self.assertEqual(f.clean(None), '')
self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
View
5 tests/inspectdb/models.py
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
+import warnings
from django.db import models
@@ -49,7 +50,9 @@ class ColumnTypes(models.Model):
file_path_field = models.FilePathField()
float_field = models.FloatField()
int_field = models.IntegerField()
- ip_address_field = models.IPAddressField()
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ ip_address_field = models.IPAddressField()
gen_ip_adress_field = models.GenericIPAddressField(protocol="ipv4")
pos_int_field = models.PositiveIntegerField()
pos_small_int_field = models.PositiveSmallIntegerField()
View
5 tests/model_fields/models.py
@@ -1,5 +1,6 @@
import os
import tempfile
+import warnings
from django.core.exceptions import ImproperlyConfigured
@@ -85,7 +86,9 @@ class VerboseNameField(models.Model):
# Don't want to depend on Pillow/PIL in this test
#field_image = models.ImageField("verbose field")
field12 = models.IntegerField("verbose field12")
- field13 = models.IPAddressField("verbose field13")
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ field13 = models.IPAddressField("verbose field13")
field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4")
field15 = models.NullBooleanField("verbose field15")
field16 = models.PositiveIntegerField("verbose field16")
View
9 tests/model_fields/tests.py
@@ -3,6 +3,7 @@
import datetime
from decimal import Decimal
import unittest
+import warnings
from django import test
from django import forms
@@ -603,9 +604,11 @@ def test_IntegerField(self):
def test_IPAddressField(self):
lazy_func = lazy(lambda: '127.0.0.1', six.text_type)
- self.assertIsInstance(
- IPAddressField().get_prep_value(lazy_func()),
- six.text_type)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ self.assertIsInstance(
+ IPAddressField().get_prep_value(lazy_func()),
+ six.text_type)
def test_GenericIPAddressField(self):
lazy_func = lazy(lambda: '127.0.0.1', six.text_type)
View
9 tests/serializers_regress/models.py
@@ -4,6 +4,7 @@
This class sets up a model for each model field type
(except for image types, because of the Pillow/PIL dependency).
"""
+import warnings
from django.db import models
from django.contrib.contenttypes import generic
@@ -52,7 +53,9 @@ class BigIntegerData(models.Model):
# data = models.ImageField(null=True)
class IPAddressData(models.Model):
- data = models.IPAddressField(null=True)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ data = models.IPAddressField(null=True)
class GenericIPAddressData(models.Model):
data = models.GenericIPAddressField(null=True)
@@ -199,7 +202,9 @@ class IntegerPKData(models.Model):
# data = models.ImageField(primary_key=True)
class IPAddressPKData(models.Model):
- data = models.IPAddressField(primary_key=True)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ data = models.IPAddressField(primary_key=True)
class GenericIPAddressPKData(models.Model):
data = models.GenericIPAddressField(primary_key=True)
View
5 tests/string_lookup/models.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import warnings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@@ -49,7 +50,9 @@ def __str__(self):
class Article(models.Model):
name = models.CharField(max_length=50)
text = models.TextField()
- submitted_from = models.IPAddressField(blank=True, null=True)
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ submitted_from = models.IPAddressField(blank=True, null=True)
def __str__(self):
return "Article %s" % self.name
Please sign in to comment.
Something went wrong with that request. Please try again.