mirror of
https://github.com/django/django.git
synced 2025-01-22 08:10:28 +00:00
Fixed #32923 -- Refactored out Field._clean_bound_field().
This commit is contained in:
parent
bbfbf0ab68
commit
d9b91e3836
@ -261,6 +261,10 @@ class Field:
|
||||
result.validators = self.validators[:]
|
||||
return result
|
||||
|
||||
def _clean_bound_field(self, bf):
|
||||
value = bf.initial if self.disabled else bf.data
|
||||
return self.clean(value)
|
||||
|
||||
|
||||
class CharField(Field):
|
||||
def __init__(
|
||||
@ -694,6 +698,10 @@ class FileField(Field):
|
||||
def has_changed(self, initial, data):
|
||||
return not self.disabled and data is not None
|
||||
|
||||
def _clean_bound_field(self, bf):
|
||||
value = bf.initial if self.disabled else bf.data
|
||||
return self.clean(value, bf.initial)
|
||||
|
||||
|
||||
class ImageField(FileField):
|
||||
default_validators = [validators.validate_image_file_extension]
|
||||
|
@ -6,7 +6,7 @@ import copy
|
||||
import datetime
|
||||
|
||||
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
||||
from django.forms.fields import Field, FileField
|
||||
from django.forms.fields import Field
|
||||
from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin
|
||||
from django.forms.widgets import Media, MediaDefiningClass
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
@ -329,13 +329,8 @@ class BaseForm(RenderableFormMixin):
|
||||
def _clean_fields(self):
|
||||
for name, bf in self._bound_items():
|
||||
field = bf.field
|
||||
value = bf.initial if field.disabled else bf.data
|
||||
try:
|
||||
if isinstance(field, FileField):
|
||||
value = field.clean(value, bf.initial)
|
||||
else:
|
||||
value = field.clean(value)
|
||||
self.cleaned_data[name] = value
|
||||
self.cleaned_data[name] = field._clean_bound_field(bf)
|
||||
if hasattr(self, "clean_%s" % name):
|
||||
value = getattr(self, "clean_%s" % name)()
|
||||
self.cleaned_data[name] = value
|
||||
|
Loading…
x
Reference in New Issue
Block a user