Kaydet (Commit) 1a630929 authored tarafından Erik Romijn's avatar Erik Romijn Kaydeden (comit) Aymeric Augustin

Fixed #20439 -- Started deprecation of IPAddressField

üst 8f51ba66
...@@ -1312,6 +1312,8 @@ class IPAddressField(Field): ...@@ -1312,6 +1312,8 @@ class IPAddressField(Field):
description = _("IPv4 address") description = _("IPv4 address")
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
PendingDeprecationWarning)
kwargs['max_length'] = 15 kwargs['max_length'] = 15
Field.__init__(self, *args, **kwargs) Field.__init__(self, *args, **kwargs)
......
...@@ -9,6 +9,7 @@ import datetime ...@@ -9,6 +9,7 @@ import datetime
import os import os
import re import re
import sys import sys
import warnings
from decimal import Decimal, DecimalException from decimal import Decimal, DecimalException
from io import BytesIO from io import BytesIO
...@@ -1144,6 +1145,11 @@ class SplitDateTimeField(MultiValueField): ...@@ -1144,6 +1145,11 @@ class SplitDateTimeField(MultiValueField):
class IPAddressField(CharField): class IPAddressField(CharField):
default_validators = [validators.validate_ipv4_address] 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): def to_python(self, value):
if value in self.empty_values: if value in self.empty_values:
return '' return ''
......
...@@ -436,6 +436,8 @@ these changes. ...@@ -436,6 +436,8 @@ these changes.
:ref:`initial SQL data<initial-sql>` in ``myapp/models/sql/``. Move your :ref:`initial SQL data<initial-sql>` in ``myapp/models/sql/``. Move your
custom SQL files to ``myapp/sql/``. custom SQL files to ``myapp/sql/``.
* The model and form ``IPAddressField`` will be removed.
* FastCGI support via the ``runfcgi`` management command will be * FastCGI support via the ``runfcgi`` management command will be
removed. Please deploy your project using WSGI. removed. Please deploy your project using WSGI.
......
...@@ -657,6 +657,10 @@ For each field, we describe the default widget used if you don't specify ...@@ -657,6 +657,10 @@ For each field, we describe the default widget used if you don't specify
.. class:: IPAddressField(**kwargs) .. class:: IPAddressField(**kwargs)
.. deprecated:: 1.7
This field has been deprecated in favour of
:class:`~django.forms.GenericIPAddressField`.
* Default widget: :class:`TextInput` * Default widget: :class:`TextInput`
* Empty value: ``''`` (an empty string) * Empty value: ``''`` (an empty string)
* Normalizes to: A Unicode object. * Normalizes to: A Unicode object.
......
...@@ -849,6 +849,10 @@ An integer. The default form widget for this field is a ...@@ -849,6 +849,10 @@ An integer. The default form widget for this field is a
.. class:: IPAddressField([**options]) .. 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 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`. for this field is a :class:`~django.forms.TextInput`.
......
...@@ -529,3 +529,12 @@ to ``utils.py`` in an effort to unify all util and utils references: ...@@ -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 ``ModelAdmin.get_formsets`` has been deprecated in favor of the new
:meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to :meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to
better handle the case of selecting showing inlines on a ``ModelAdmin``. 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`.
import warnings
from django.test import TestCase from django.test import TestCase
from django.db import models from django.db import models
...@@ -173,6 +174,8 @@ class FieldDeconstructionTests(TestCase): ...@@ -173,6 +174,8 @@ class FieldDeconstructionTests(TestCase):
self.assertEqual(kwargs, {}) self.assertEqual(kwargs, {})
def test_ip_address_field(self): def test_ip_address_field(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
field = models.IPAddressField() field = models.IPAddressField()
name, path, args, kwargs = field.deconstruct() name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.IPAddressField") self.assertEqual(path, "django.db.models.IPAddressField")
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import * from django.forms import *
from django.test import TestCase from django.test import TestCase
...@@ -192,6 +194,8 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): ...@@ -192,6 +194,8 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
'required': 'REQUIRED', 'required': 'REQUIRED',
'invalid': 'INVALID IP ADDRESS', 'invalid': 'INVALID IP ADDRESS',
} }
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
f = IPAddressField(error_messages=e) f = IPAddressField(error_messages=e)
self.assertFormErrors(['REQUIRED'], f.clean, '') self.assertFormErrors(['REQUIRED'], f.clean, '')
self.assertFormErrors(['INVALID IP ADDRESS'], f.clean, '127.0.0') self.assertFormErrors(['INVALID IP ADDRESS'], f.clean, '127.0.0')
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
import warnings
from django.forms import * from django.forms import *
from django.forms.extras import SelectDateWidget from django.forms.extras import SelectDateWidget
...@@ -535,6 +536,8 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin): ...@@ -535,6 +536,8 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00') self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00')
def test_ipaddress(self): def test_ipaddress(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
f = IPAddressField() f = IPAddressField()
self.assertFormErrors(['This field is required.'], f.clean, '') self.assertFormErrors(['This field is required.'], f.clean, '')
self.assertFormErrors(['This field is required.'], f.clean, None) self.assertFormErrors(['This field is required.'], f.clean, None)
...@@ -544,6 +547,8 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin): ...@@ -544,6 +547,8 @@ 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, '1.2.3.4.5')
self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5') self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
f = IPAddressField(required=False) f = IPAddressField(required=False)
self.assertEqual(f.clean(''), '') self.assertEqual(f.clean(''), '')
self.assertEqual(f.clean(None), '') self.assertEqual(f.clean(None), '')
......
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.db import models from django.db import models
...@@ -49,6 +50,8 @@ class ColumnTypes(models.Model): ...@@ -49,6 +50,8 @@ class ColumnTypes(models.Model):
file_path_field = models.FilePathField() file_path_field = models.FilePathField()
float_field = models.FloatField() float_field = models.FloatField()
int_field = models.IntegerField() int_field = models.IntegerField()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
ip_address_field = models.IPAddressField() ip_address_field = models.IPAddressField()
gen_ip_adress_field = models.GenericIPAddressField(protocol="ipv4") gen_ip_adress_field = models.GenericIPAddressField(protocol="ipv4")
pos_int_field = models.PositiveIntegerField() pos_int_field = models.PositiveIntegerField()
......
import os import os
import tempfile import tempfile
import warnings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
...@@ -85,6 +86,8 @@ class VerboseNameField(models.Model): ...@@ -85,6 +86,8 @@ class VerboseNameField(models.Model):
# Don't want to depend on Pillow/PIL in this test # Don't want to depend on Pillow/PIL in this test
#field_image = models.ImageField("verbose field") #field_image = models.ImageField("verbose field")
field12 = models.IntegerField("verbose field12") field12 = models.IntegerField("verbose field12")
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
field13 = models.IPAddressField("verbose field13") field13 = models.IPAddressField("verbose field13")
field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4") field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4")
field15 = models.NullBooleanField("verbose field15") field15 = models.NullBooleanField("verbose field15")
......
...@@ -3,6 +3,7 @@ from __future__ import unicode_literals ...@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import datetime import datetime
from decimal import Decimal from decimal import Decimal
import unittest import unittest
import warnings
from django import test from django import test
from django import forms from django import forms
...@@ -603,6 +604,8 @@ class PromiseTest(test.TestCase): ...@@ -603,6 +604,8 @@ class PromiseTest(test.TestCase):
def test_IPAddressField(self): def test_IPAddressField(self):
lazy_func = lazy(lambda: '127.0.0.1', six.text_type) lazy_func = lazy(lambda: '127.0.0.1', six.text_type)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.assertIsInstance( self.assertIsInstance(
IPAddressField().get_prep_value(lazy_func()), IPAddressField().get_prep_value(lazy_func()),
six.text_type) six.text_type)
......
...@@ -4,6 +4,7 @@ A test spanning all the capabilities of all the serializers. ...@@ -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 This class sets up a model for each model field type
(except for image types, because of the Pillow/PIL dependency). (except for image types, because of the Pillow/PIL dependency).
""" """
import warnings
from django.db import models from django.db import models
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
...@@ -52,6 +53,8 @@ class BigIntegerData(models.Model): ...@@ -52,6 +53,8 @@ class BigIntegerData(models.Model):
# data = models.ImageField(null=True) # data = models.ImageField(null=True)
class IPAddressData(models.Model): class IPAddressData(models.Model):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
data = models.IPAddressField(null=True) data = models.IPAddressField(null=True)
class GenericIPAddressData(models.Model): class GenericIPAddressData(models.Model):
...@@ -199,6 +202,8 @@ class IntegerPKData(models.Model): ...@@ -199,6 +202,8 @@ class IntegerPKData(models.Model):
# data = models.ImageField(primary_key=True) # data = models.ImageField(primary_key=True)
class IPAddressPKData(models.Model): class IPAddressPKData(models.Model):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
data = models.IPAddressField(primary_key=True) data = models.IPAddressField(primary_key=True)
class GenericIPAddressPKData(models.Model): class GenericIPAddressPKData(models.Model):
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
...@@ -49,6 +50,8 @@ class Base(models.Model): ...@@ -49,6 +50,8 @@ class Base(models.Model):
class Article(models.Model): class Article(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
text = models.TextField() text = models.TextField()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
submitted_from = models.IPAddressField(blank=True, null=True) submitted_from = models.IPAddressField(blank=True, null=True)
def __str__(self): def __str__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment