diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-03-24 10:31:52 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:50 +0200 |
commit | c814bd19a943dcc71ec435caafa7cc9569137e20 (patch) | |
tree | 74f205d9d8e4c22e479fba867e8983879d477a51 /ishtar_common | |
parent | c4326466ffed98aea0cb65f0adedb64c24bfe3d1 (diff) | |
download | Ishtar-c814bd19a943dcc71ec435caafa7cc9569137e20.tar.bz2 Ishtar-c814bd19a943dcc71ec435caafa7cc9569137e20.zip |
Improve file widget with bootstrap
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 4 | ||||
-rw-r--r-- | ishtar_common/templates/widgets/clearable_file_input.html | 8 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 4 |
3 files changed, 16 insertions, 0 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 80fb984c6..572c1b70a 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -176,6 +176,10 @@ class BaseImportForm(BSForm, forms.ModelForm): "conservative_import", "skip_lines", ) + widgets = { + "imported_file": widgets.BSClearableFileInput, + "imported_images": widgets.BSClearableFileInput, + } def __init__(self, *args, **kwargs): user = kwargs.pop("user") diff --git a/ishtar_common/templates/widgets/clearable_file_input.html b/ishtar_common/templates/widgets/clearable_file_input.html new file mode 100644 index 000000000..f2721fbfd --- /dev/null +++ b/ishtar_common/templates/widgets/clearable_file_input.html @@ -0,0 +1,8 @@ +{% load i18n %}{% if widget.is_initial %} +<p class="file-upload w-100 mb-1">{{ widget.initial_text }}{% trans ":" %} <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} + <span class="clearable-file-input"> +<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"> +<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %} +</p> +<p class="w-100 m-0">{{ widget.input_text }}{% trans ":" %}</p>{% endif %} +<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}> diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index efea07065..1f5a169ba 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -479,6 +479,10 @@ class DeleteSwitchWidget(SwitchWidget): extra_label = _("Delete") +class BSClearableFileInput(ClearableFileInput): + template_name = "widgets/clearable_file_input.html" + + class ImageFileInput(ClearableFileInput): template_name = "widgets/image_input.html" NO_FORM_CONTROL = True |