Refs #23151 -- Removed RegexField.error_message per deprecation timeline.
This commit is contained in:
parent
54fd769eb4
commit
b6ea1961eb
|
@ -10,7 +10,6 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
|
||||||
from decimal import Decimal, DecimalException
|
from decimal import Decimal, DecimalException
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -513,16 +512,6 @@ class RegexField(CharField):
|
||||||
'Enter a valid value' is too generic for you.
|
'Enter a valid value' is too generic for you.
|
||||||
"""
|
"""
|
||||||
kwargs.setdefault('strip', False)
|
kwargs.setdefault('strip', False)
|
||||||
# error_message is just kept for backwards compatibility:
|
|
||||||
if error_message is not None:
|
|
||||||
warnings.warn(
|
|
||||||
"The 'error_message' argument is deprecated. Use "
|
|
||||||
"Field.error_messages['invalid'] instead.",
|
|
||||||
RemovedInDjango110Warning, stacklevel=2
|
|
||||||
)
|
|
||||||
error_messages = kwargs.get('error_messages') or {}
|
|
||||||
error_messages['invalid'] = error_message
|
|
||||||
kwargs['error_messages'] = error_messages
|
|
||||||
super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
|
super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
|
||||||
self._set_regex(regex)
|
self._set_regex(regex)
|
||||||
|
|
||||||
|
|
|
@ -853,14 +853,6 @@ For each field, we describe the default widget used if you don't specify
|
||||||
Defaults to ``False``. If enabled, stripping will be applied before the
|
Defaults to ``False``. If enabled, stripping will be applied before the
|
||||||
regex validation.
|
regex validation.
|
||||||
|
|
||||||
.. deprecated:: 1.8
|
|
||||||
|
|
||||||
The optional argument ``error_message`` is also accepted for backwards
|
|
||||||
compatibility but will be removed in Django 1.10. The preferred way to
|
|
||||||
provide an error message is to use the :attr:`~Field.error_messages`
|
|
||||||
argument, passing a dictionary with ``'invalid'`` as a key and the error
|
|
||||||
message as the value.
|
|
||||||
|
|
||||||
``SlugField``
|
``SlugField``
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -759,13 +759,6 @@ class FieldsTests(SimpleTestCase):
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, ' 2A2')
|
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, ' 2A2')
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '2A2 ')
|
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, '2A2 ')
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango110Warning) # error_message deprecation
|
|
||||||
def test_regexfield_4(self):
|
|
||||||
f = RegexField('^[0-9][0-9][0-9][0-9]$', error_message='Enter a four-digit number.')
|
|
||||||
self.assertEqual('1234', f.clean('1234'))
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a four-digit number.'", f.clean, '123')
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a four-digit number.'", f.clean, 'abcd')
|
|
||||||
|
|
||||||
def test_regexfield_5(self):
|
def test_regexfield_5(self):
|
||||||
f = RegexField('^[0-9]+$', min_length=5, max_length=10)
|
f = RegexField('^[0-9]+$', min_length=5, max_length=10)
|
||||||
self.assertRaisesMessage(
|
self.assertRaisesMessage(
|
||||||
|
|
Loading…
Reference in New Issue