1
0
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:
Syed Waheed 2024-01-23 14:17:31 +05:30 committed by GitHub
parent bbfbf0ab68
commit d9b91e3836
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -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]

View File

@ -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