MCPcopy
hub / github.com/django/django / clean

Method clean

django/forms/fields.py:681–700  ·  view source on GitHub ↗
(self, data, initial=None)

Source from the content-addressed store, hash-verified

679 return data
680
681 def clean(self, data, initial=None):
682 # If the widget got contradictory inputs, we raise a validation error
683 if data is FILE_INPUT_CONTRADICTION:
684 raise ValidationError(
685 self.error_messages["contradiction"], code="contradiction"
686 )
687 # False means the field value should be cleared; further validation is
688 # not needed.
689 if data is False:
690 if not self.required:
691 return False
692 # If the field is required, clearing is not possible (the widget
693 # shouldn't return False data in that case anyway). False is not
694 # in self.empty_value; if a False value makes it this far
695 # it should be validated from here on out as None (so it will be
696 # caught by the required check).
697 data = None
698 if not data and initial:
699 return initial
700 return super().clean(data)
701
702 def bound_data(self, _, initial):
703 return initial

Callers 6

_clean_bound_fieldMethod · 0.95
test_clean_falseMethod · 0.95
test_filefield_1Method · 0.95
test_filefield_2Method · 0.95
test_filefield_3Method · 0.95

Calls 2

ValidationErrorClass · 0.90
cleanMethod · 0.45

Tested by 5

test_clean_falseMethod · 0.76
test_filefield_1Method · 0.76
test_filefield_2Method · 0.76
test_filefield_3Method · 0.76