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