From 525dc283a68c0d47f5eb2192cc4a20111d561ae0 Mon Sep 17 00:00:00 2001 From: kakulukia Date: Mon, 5 Jun 2017 22:17:10 +0200 Subject: [PATCH] Fixed #28278 -- Fixed invalid HTML for a required AdminFileWidget. --- .../admin/widgets/clearable_file_input.html | 2 +- docs/releases/1.11.3.txt | 2 ++ tests/admin_widgets/tests.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/templates/admin/widgets/clearable_file_input.html b/django/contrib/admin/templates/admin/widgets/clearable_file_input.html index 327b8ad16a9..9fee235819b 100644 --- a/django/contrib/admin/templates/admin/widgets/clearable_file_input.html +++ b/django/contrib/admin/templates/admin/widgets/clearable_file_input.html @@ -1,6 +1,6 @@ {% if is_initial %}

{{ initial_text }}: {{ widget.value }}{% if not widget.required %} -{% endif %}
+{% endif %}
{{ input_text }}:{% endif %} {% if is_initial %}

{% endif %} diff --git a/docs/releases/1.11.3.txt b/docs/releases/1.11.3.txt index 5b3b1066a93..7085b026692 100644 --- a/docs/releases/1.11.3.txt +++ b/docs/releases/1.11.3.txt @@ -21,3 +21,5 @@ Bugfixes * Fixed admin's ``FieldListFilter.get_queryset()`` crash on invalid input (:ticket:`28202`). + +* Fixed invalid HTML for a required ``AdminFileWidget`` (:ticket:`28278`). diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index d53ac0b4351..bb8f9df63f0 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -431,6 +431,18 @@ class AdminFileWidgetTests(TestDataMixin, TestCase): '', ) + def test_render_required(self): + widget = widgets.AdminFileWidget() + widget.is_required = True + self.assertHTMLEqual( + widget.render('test', self.album.cover_art), + '

Currently: albums\hybrid_theory.jpg
' + 'Change:

' % { + 'STORAGE_URL': default_storage.url(''), + }, + ) + def test_readonly_fields(self): """ File widgets should render as a link when they're marked "read only."