forms: mark file widgets expecting images (#29102)

This commit is contained in:
Frédéric Péters 2018-12-16 14:43:32 +01:00
parent 054d5511de
commit 88be1de770
2 changed files with 4 additions and 1 deletions

View File

@ -660,6 +660,9 @@ class FileWithPreviewWidget(CompositeWidget):
if value:
self.set_value(value)
def is_image(self):
return all([x.startswith('image/') for x in getattr(self, 'file_type', None) or []])
def set_value(self, value):
self.value = value
if hasattr(self.value, 'token'):

View File

@ -2,7 +2,7 @@
{% load i18n %}
{% block widget-control %}
<div class="file-button">
<div class="file-button {% if widget.is_image %}file-image{% endif %}">
{% for w in widget.get_widgets %}
{{ w.render|safe }}
{% endfor %}