mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +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[:]
|
result.validators = self.validators[:]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _clean_bound_field(self, bf):
|
||||||
|
value = bf.initial if self.disabled else bf.data
|
||||||
|
return self.clean(value)
|
||||||
|
|
||||||
|
|
||||||
class CharField(Field):
|
class CharField(Field):
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -694,6 +698,10 @@ class FileField(Field):
|
|||||||
def has_changed(self, initial, data):
|
def has_changed(self, initial, data):
|
||||||
return not self.disabled and data is not None
|
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):
|
class ImageField(FileField):
|
||||||
default_validators = [validators.validate_image_file_extension]
|
default_validators = [validators.validate_image_file_extension]
|
||||||
|
@ -6,7 +6,7 @@ import copy
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
|
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.utils import ErrorDict, ErrorList, RenderableFormMixin
|
||||||
from django.forms.widgets import Media, MediaDefiningClass
|
from django.forms.widgets import Media, MediaDefiningClass
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
@ -329,13 +329,8 @@ class BaseForm(RenderableFormMixin):
|
|||||||
def _clean_fields(self):
|
def _clean_fields(self):
|
||||||
for name, bf in self._bound_items():
|
for name, bf in self._bound_items():
|
||||||
field = bf.field
|
field = bf.field
|
||||||
value = bf.initial if field.disabled else bf.data
|
|
||||||
try:
|
try:
|
||||||
if isinstance(field, FileField):
|
self.cleaned_data[name] = field._clean_bound_field(bf)
|
||||||
value = field.clean(value, bf.initial)
|
|
||||||
else:
|
|
||||||
value = field.clean(value)
|
|
||||||
self.cleaned_data[name] = value
|
|
||||||
if hasattr(self, "clean_%s" % name):
|
if hasattr(self, "clean_%s" % name):
|
||||||
value = getattr(self, "clean_%s" % name)()
|
value = getattr(self, "clean_%s" % name)()
|
||||||
self.cleaned_data[name] = value
|
self.cleaned_data[name] = value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user