mirror of
https://github.com/django/django.git
synced 2025-10-30 00:56:09 +00:00
Fixed #23162 -- Renamed forms.Field._has_changed() to has_changed().
This commit is contained in:
committed by
Tim Graham
parent
99561eef26
commit
deed00c0d8
@@ -25,7 +25,7 @@ from django.forms.widgets import (
|
||||
from django.utils import formats
|
||||
from django.utils.encoding import smart_text, force_str, force_text
|
||||
from django.utils.ipv6 import clean_ipv6_address
|
||||
from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning
|
||||
from django.utils.deprecation import RemovedInDjango19Warning, RemovedInDjango20Warning, RenameMethodsBase
|
||||
from django.utils import six
|
||||
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
|
||||
@@ -45,7 +45,13 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
class Field(object):
|
||||
class RenameFieldMethods(RenameMethodsBase):
|
||||
renamed_methods = (
|
||||
('_has_changed', 'has_changed', RemovedInDjango20Warning),
|
||||
)
|
||||
|
||||
|
||||
class Field(six.with_metaclass(RenameFieldMethods, object)):
|
||||
widget = TextInput # Default widget to use when rendering this type of Field.
|
||||
hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden".
|
||||
default_validators = [] # Default set of validators
|
||||
@@ -185,7 +191,7 @@ class Field(object):
|
||||
return self.limit_choices_to()
|
||||
return self.limit_choices_to
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
"""
|
||||
Return True if data differs from initial.
|
||||
"""
|
||||
@@ -629,7 +635,7 @@ class FileField(Field):
|
||||
return initial
|
||||
return data
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
if data is None:
|
||||
return False
|
||||
return True
|
||||
@@ -744,7 +750,7 @@ class BooleanField(Field):
|
||||
if not value and self.required:
|
||||
raise ValidationError(self.error_messages['required'], code='required')
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
# Sometimes data or initial could be None or '' which should be the
|
||||
# same thing as False.
|
||||
if initial == 'False':
|
||||
@@ -779,7 +785,7 @@ class NullBooleanField(BooleanField):
|
||||
def validate(self, value):
|
||||
pass
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
# None (unknown) and False (No) are not the same
|
||||
if initial is not None:
|
||||
initial = bool(initial)
|
||||
@@ -906,7 +912,7 @@ class MultipleChoiceField(ChoiceField):
|
||||
params={'value': val},
|
||||
)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
if initial is None:
|
||||
initial = []
|
||||
if data is None:
|
||||
@@ -1084,14 +1090,14 @@ class MultiValueField(Field):
|
||||
"""
|
||||
raise NotImplementedError('Subclasses must implement this method.')
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
if initial is None:
|
||||
initial = ['' for x in range(0, len(data))]
|
||||
else:
|
||||
if not isinstance(initial, list):
|
||||
initial = self.widget.decompress(initial)
|
||||
for field, initial, data in zip(self.fields, initial, data):
|
||||
if field._has_changed(field.to_python(initial), data):
|
||||
if field.has_changed(field.to_python(initial), data):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ class BaseForm(object):
|
||||
# Always assume data has changed if validation fails.
|
||||
self._changed_data.append(name)
|
||||
continue
|
||||
if field._has_changed(initial_value, data_value):
|
||||
if field.has_changed(initial_value, data_value):
|
||||
self._changed_data.append(name)
|
||||
return self._changed_data
|
||||
|
||||
|
||||
@@ -1058,7 +1058,7 @@ class InlineForeignKeyField(Field):
|
||||
raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice')
|
||||
return self.parent_instance
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
return False
|
||||
|
||||
|
||||
@@ -1186,7 +1186,7 @@ class ModelChoiceField(ChoiceField):
|
||||
def validate(self, value):
|
||||
return Field.validate(self, value)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
initial_value = initial if initial is not None else ''
|
||||
data_value = data if data is not None else ''
|
||||
return force_text(self.prepare_value(initial_value)) != force_text(data_value)
|
||||
@@ -1254,7 +1254,7 @@ class ModelMultipleChoiceField(ModelChoiceField):
|
||||
return [super(ModelMultipleChoiceField, self).prepare_value(v) for v in value]
|
||||
return super(ModelMultipleChoiceField, self).prepare_value(value)
|
||||
|
||||
def _has_changed(self, initial, data):
|
||||
def has_changed(self, initial, data):
|
||||
if initial is None:
|
||||
initial = []
|
||||
if data is None:
|
||||
|
||||
Reference in New Issue
Block a user