Fixed #20439 -- Started deprecation of IPAddressField

This commit is contained in:
Erik Romijn 2013-09-28 10:22:46 +02:00 committed by Aymeric Augustin
parent 8f51ba669a
commit 1a63092981
14 changed files with 68 additions and 12 deletions

View File

@ -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 File

@ -9,6 +9,7 @@ import datetime
import os
import re
import sys
import warnings
from decimal import Decimal, DecimalException
from io import BytesIO
@ -1144,6 +1145,11 @@ class SplitDateTimeField(MultiValueField):
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 File

@ -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 File

@ -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 File

@ -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 File

@ -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 File

@ -1,3 +1,4 @@
import warnings
from django.test import TestCase
from django.db import models
@ -173,7 +174,9 @@ class FieldDeconstructionTests(TestCase):
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 File

@ -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 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
'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 File

@ -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 FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
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 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
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 File

@ -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 File

@ -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 File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
import datetime
from decimal import Decimal
import unittest
import warnings
from django import test
from django import forms
@ -603,9 +604,11 @@ class PromiseTest(test.TestCase):
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 File

@ -4,6 +4,7 @@ A test spanning all the capabilities of all the serializers.
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 File

@ -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 @@ class Base(models.Model):
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