1
0
mirror of https://github.com/django/django.git synced 2025-04-05 05:56:42 +00:00

[1.10.x] Fixed #27805 -- Fixed ClearableFileInput's "Clear" checkbox on model fields with a default.

Backport of 4353640ea9495d58fabd0357253b82de3b069408 from master
This commit is contained in:
Tim Graham 2017-02-03 11:11:39 -05:00
parent 82e316ea54
commit cd69ac06d6
3 changed files with 14 additions and 1 deletions

View File

@ -440,6 +440,12 @@ class ClearableFileInput(FileInput):
def use_required_attribute(self, initial):
return super(ClearableFileInput, self).use_required_attribute(initial) and not initial
def value_omitted_from_data(self, data, files, name):
return (
super(ClearableFileInput, self).value_omitted_from_data(data, files, name) and
self.clear_checkbox_name(name) not in data
)
class Textarea(Widget):
def __init__(self, attrs=None):

View File

@ -9,4 +9,5 @@ Django 1.10.6 fixes several bugs in 1.10.5.
Bugfixes
========
* ...
* Fixed ``ClearableFileInput``s "Clear" checkbox on model form fields where
the model field has a ``default`` (:ticket:`27805`).

View File

@ -149,3 +149,9 @@ class ClearableFileInputTest(WidgetTest):
# user to keep the existing, initial value.
self.assertIs(self.widget.use_required_attribute(None), True)
self.assertIs(self.widget.use_required_attribute('resume.txt'), False)
def test_value_omitted_from_data(self):
widget = ClearableFileInput()
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
self.assertIs(widget.value_omitted_from_data({}, {'field': 'x'}, 'field'), False)
self.assertIs(widget.value_omitted_from_data({'field-clear': 'y'}, {}, 'field'), False)