summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkakulukia <andy@freilandkiwis.de>2017-06-05 22:17:10 +0200
committerTim Graham <timograham@gmail.com>2017-06-06 15:57:08 -0400
commit992f143bad4143da7e43e21c41dfdab79ddd5070 (patch)
tree9554069c1c6eb939478c901b30755eb318f3c90f
parent6ae60295d71b29e55d0498551c0dd6ee07cee1c4 (diff)
[1.11.x] Fixed #28278 -- Fixed invalid HTML for a required AdminFileWidget.
Backport of 525dc283a68c0d47f5eb2192cc4a20111d561ae0 from master
-rw-r--r--django/contrib/admin/templates/admin/widgets/clearable_file_input.html2
-rw-r--r--docs/releases/1.11.3.txt2
-rw-r--r--tests/admin_widgets/tests.py12
3 files changed, 15 insertions, 1 deletions
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 327b8ad16a..9fee235819 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 %}<p class="file-upload">{{ initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
<span class="clearable-file-input">
<input type="checkbox" name="{{ checkbox_name }}" id="{{ checkbox_id }}" />
-<label for="{{ checkbox_id }}">{{ clear_checkbox_label }}</label>{% endif %}</span><br />
+<label for="{{ checkbox_id }}">{{ clear_checkbox_label }}</label></span>{% endif %}<br />
{{ input_text }}:{% endif %}
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} />{% if is_initial %}</p>{% endif %}
diff --git a/docs/releases/1.11.3.txt b/docs/releases/1.11.3.txt
index 5b3b1066a9..7085b02669 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 f9c6d6a614..2e2bdb0b52 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -434,6 +434,18 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
'<input type="file" name="test" />',
)
+ def test_render_required(self):
+ widget = widgets.AdminFileWidget()
+ widget.is_required = True
+ self.assertHTMLEqual(
+ widget.render('test', self.album.cover_art),
+ '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
+ r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a><br />'
+ 'Change: <input type="file" name="test" /></p>' % {
+ 'STORAGE_URL': default_storage.url(''),
+ },
+ )
+
def test_readonly_fields(self):
"""
File widgets should render as a link when they're marked "read only."