Skip to content

Commit fc770aa

Browse files
authored
fix: improve safe icon rendering (#80)
1 parent 0c5d439 commit fc770aa

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

image_uploader_widget/templates/admin/edit_inline/image_uploader.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{% endfor %}
3434
<div class="iuw-add-image-btn">
3535
{% if inline_admin_formset.formset.add_icon %}
36-
{{ inline_admin_formset.formset.add_icon }}
36+
{{ inline_admin_formset.formset.add_icon|safe }}
3737
{% else %}
3838
<svg class="add-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100%" height="100%"><path xmlns="http://www.w3.org/2000/svg" d="M21 15v3h3v2h-3v3h-2v-3h-3v-2h3v-3h2zm.008-12c.548 0 .992.445.992.993V13h-2V5H4v13.999L14 9l3 3v2.829l-3-3L6.827 19H14v2H2.992A.993.993 0 0 1 2 20.007V3.993A1 1 0 0 1 2.992 3h18.016zM8 7a2 2 0 1 1 0 4 2 2 0 0 1 0-4z"></path></svg>
3939
{% endif %}
@@ -47,7 +47,7 @@
4747
</div>
4848
<div class="iuw-empty">
4949
{% if inline_admin_formset.formset.empty_icon %}
50-
{{ inline_admin_formset.formset.empty_icon }}
50+
{{ inline_admin_formset.formset.empty_icon|safe }}
5151
{% else %}
5252
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-cloud-upload" viewBox="0 0 16 16" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100%" height="100%"><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M4.406 1.342A5.53 5.53 0 0 1 8 0c2.69 0 4.923 2 5.166 4.579C14.758 4.804 16 6.137 16 7.773 16 9.569 14.502 11 12.687 11H10a.5.5 0 0 1 0-1h2.688C13.979 10 15 8.988 15 7.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 2.825 10.328 1 8 1a4.53 4.53 0 0 0-2.941 1.1c-.757.652-1.153 1.438-1.153 2.055v.448l-.445.049C2.064 4.805 1 5.952 1 7.318 1 8.785 2.23 10 3.781 10H6a.5.5 0 0 1 0 1H3.781C1.708 11 0 9.366 0 7.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"></path><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M7.646 4.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V14.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3z"></path></svg>
5353
{% endif %}
@@ -61,7 +61,7 @@
6161
</div>
6262
<div class="iuw-drop-label">
6363
{% if inline_admin_formset.formset.drop_icon %}
64-
{{ inline_admin_formset.formset.drop_icon }}
64+
{{ inline_admin_formset.formset.drop_icon|safe }}
6565
{% else %}
6666
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-cloud-upload" viewBox="0 0 16 16" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100%" height="100%"><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M4.406 1.342A5.53 5.53 0 0 1 8 0c2.69 0 4.923 2 5.166 4.579C14.758 4.804 16 6.137 16 7.773 16 9.569 14.502 11 12.687 11H10a.5.5 0 0 1 0-1h2.688C13.979 10 15 8.988 15 7.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 2.825 10.328 1 8 1a4.53 4.53 0 0 0-2.941 1.1c-.757.652-1.153 1.438-1.153 2.055v.448l-.445.049C2.064 4.805 1 5.952 1 7.318 1 8.785 2.23 10 3.781 10H6a.5.5 0 0 1 0 1H3.781C1.708 11 0 9.366 0 7.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"></path><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M7.646 4.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V14.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3z"></path></svg>
6767
{% endif %}

image_uploader_widget/templates/admin/widgets/image_uploader_widget.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div class="iuw-drop-label">
77
{% if custom.drop_icon %}
8-
{{ custom.drop_icon }}
8+
{{ custom.drop_icon|safe }}
99
{% else %}
1010
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-cloud-upload" viewBox="0 0 16 16" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100%" height="100%"><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M4.406 1.342A5.53 5.53 0 0 1 8 0c2.69 0 4.923 2 5.166 4.579C14.758 4.804 16 6.137 16 7.773 16 9.569 14.502 11 12.687 11H10a.5.5 0 0 1 0-1h2.688C13.979 10 15 8.988 15 7.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 2.825 10.328 1 8 1a4.53 4.53 0 0 0-2.941 1.1c-.757.652-1.153 1.438-1.153 2.055v.448l-.445.049C2.064 4.805 1 5.952 1 7.318 1 8.785 2.23 10 3.781 10H6a.5.5 0 0 1 0 1H3.781C1.708 11 0 9.366 0 7.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"></path><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M7.646 4.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V14.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3z"></path></svg>
1111
{% endif %}
@@ -19,7 +19,7 @@
1919
</div>
2020
<div class="iuw-empty">
2121
{% if custom.empty_icon %}
22-
{{ custom.empty_icon }}
22+
{{ custom.empty_icon|safe }}
2323
{% else %}
2424
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-cloud-upload" viewBox="0 0 16 16" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100%" height="100%"><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M4.406 1.342A5.53 5.53 0 0 1 8 0c2.69 0 4.923 2 5.166 4.579C14.758 4.804 16 6.137 16 7.773 16 9.569 14.502 11 12.687 11H10a.5.5 0 0 1 0-1h2.688C13.979 10 15 8.988 15 7.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 2.825 10.328 1 8 1a4.53 4.53 0 0 0-2.941 1.1c-.757.652-1.153 1.438-1.153 2.055v.448l-.445.049C2.064 4.805 1 5.952 1 7.318 1 8.785 2.23 10 3.781 10H6a.5.5 0 0 1 0 1H3.781C1.708 11 0 9.366 0 7.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"></path><path xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" d="M7.646 4.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V14.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3z"></path></svg>
2525
{% endif %}

image_uploader_widget_demo/demo_application/forms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class Meta:
1414
model = CustomWidget
1515
widgets = {
1616
'image': ImageUploaderWidget(
17-
drop_icon="<drop_icon>",
18-
drop_text="<drop_text>",
19-
empty_icon="<empty_icon>",
20-
empty_text="<empty_text>",
17+
drop_icon="@drop_icon@",
18+
drop_text="@drop_text@",
19+
empty_icon="@empty_icon@",
20+
empty_text="@empty_text@",
2121
),
2222
}
2323
fields = '__all__'

image_uploader_widget_demo/tests/widget_customized.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_render_custom_icons_and_texts(self):
66
form = TestCustomForm()
77
text = form.as_p()
88

9-
self.assertTrue("&lt;drop_icon&gt;" in text)
10-
self.assertTrue("&lt;drop_text&gt;" in text)
11-
self.assertTrue("&lt;empty_icon&gt;" in text)
12-
self.assertTrue("&lt;empty_text&gt;" in text)
9+
self.assertTrue("@drop_icon@" in text)
10+
self.assertTrue("@drop_text@" in text)
11+
self.assertTrue("@empty_icon@" in text)
12+
self.assertTrue("@empty_text@" in text)

0 commit comments

Comments
 (0)