mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
Fixed #8898 -- Obsoleted SplitDateTimeWidget usage with DateTimeField
Thanks Tim Graham for the review.
This commit is contained in:
parent
6d1ecc7f40
commit
8116726173
@ -486,6 +486,10 @@ class DateTimeField(BaseTemporalField):
|
|||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
# Input comes from a SplitDateTimeWidget, for example. So, it's two
|
# Input comes from a SplitDateTimeWidget, for example. So, it's two
|
||||||
# components: date and time.
|
# components: date and time.
|
||||||
|
warnings.warn(
|
||||||
|
'Using SplitDateTimeWidget with DateTimeField is deprecated. '
|
||||||
|
'Use SplitDateTimeField instead.',
|
||||||
|
PendingDeprecationWarning, stacklevel=2)
|
||||||
if len(value) != 2:
|
if len(value) != 2:
|
||||||
raise ValidationError(self.error_messages['invalid'], code='invalid')
|
raise ValidationError(self.error_messages['invalid'], code='invalid')
|
||||||
if value[0] in self.empty_values and value[1] in self.empty_values:
|
if value[0] in self.empty_values and value[1] in self.empty_values:
|
||||||
|
@ -215,6 +215,9 @@ these changes.
|
|||||||
|
|
||||||
* ``django.forms.get_declared_fields`` will be removed.
|
* ``django.forms.get_declared_fields`` will be removed.
|
||||||
|
|
||||||
|
* The ability to use a ``SplitDateTimeWidget`` with ``DateTimeField`` will be
|
||||||
|
removed.
|
||||||
|
|
||||||
* The ``WSGIRequest.REQUEST`` property will be removed.
|
* The ``WSGIRequest.REQUEST`` property will be removed.
|
||||||
|
|
||||||
* The class ``django.utils.datastructures.MergeDict`` will be removed.
|
* The class ``django.utils.datastructures.MergeDict`` will be removed.
|
||||||
|
@ -458,6 +458,12 @@ For each field, we describe the default widget used if you don't specify
|
|||||||
|
|
||||||
See also :ref:`format localization <format-localization>`.
|
See also :ref:`format localization <format-localization>`.
|
||||||
|
|
||||||
|
.. deprecated:: 1.7
|
||||||
|
|
||||||
|
The ability to use :class:`SplitDateTimeWidget` with ``DateTimeField``
|
||||||
|
has been deprecated and will be removed in Django 1.9. Use
|
||||||
|
:class:`SplitDateTimeField` instead.
|
||||||
|
|
||||||
``DecimalField``
|
``DecimalField``
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -1084,3 +1084,10 @@ the arguments may have been evaluated at query time.
|
|||||||
|
|
||||||
The ``ADMIN_FOR`` feature, part of the admindocs, has been removed. You can
|
The ``ADMIN_FOR`` feature, part of the admindocs, has been removed. You can
|
||||||
remove the setting from your configuration at your convenience.
|
remove the setting from your configuration at your convenience.
|
||||||
|
|
||||||
|
``SplitDateTimeWidget`` with ``DateTimeField``
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
``SplitDateTimeWidget`` support in :class:`~django.forms.DateTimeField` is
|
||||||
|
deprecated, use ``SplitDateTimeWidget`` with
|
||||||
|
:class:`~django.forms.SplitDateTimeField` instead.
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
@ -1092,18 +1093,22 @@ class WidgetTests(TestCase):
|
|||||||
class SplitDateForm(Form):
|
class SplitDateForm(Form):
|
||||||
field = DateTimeField(widget=SplitDateTimeWidget, required=False)
|
field = DateTimeField(widget=SplitDateTimeWidget, required=False)
|
||||||
|
|
||||||
form = SplitDateForm({'field': ''})
|
with warnings.catch_warnings():
|
||||||
self.assertTrue(form.is_valid())
|
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
||||||
form = SplitDateForm({'field': ['', '']})
|
form = SplitDateForm({'field': ''})
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
|
form = SplitDateForm({'field': ['', '']})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
class SplitDateRequiredForm(Form):
|
class SplitDateRequiredForm(Form):
|
||||||
field = DateTimeField(widget=SplitDateTimeWidget, required=True)
|
field = DateTimeField(widget=SplitDateTimeWidget, required=True)
|
||||||
|
|
||||||
form = SplitDateRequiredForm({'field': ''})
|
with warnings.catch_warnings():
|
||||||
self.assertFalse(form.is_valid())
|
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
||||||
form = SplitDateRequiredForm({'field': ['', '']})
|
form = SplitDateRequiredForm({'field': ''})
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
|
form = SplitDateRequiredForm({'field': ['', '']})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
|
||||||
|
|
||||||
class LiveWidgetTests(AdminSeleniumWebDriverTestCase):
|
class LiveWidgetTests(AdminSeleniumWebDriverTestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user