From c814bd19a943dcc71ec435caafa7cc9569137e20 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 24 Mar 2022 10:31:52 +0100 Subject: Improve file widget with bootstrap --- ishtar_common/forms_common.py | 4 ++++ ishtar_common/templates/widgets/clearable_file_input.html | 8 ++++++++ ishtar_common/widgets.py | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 ishtar_common/templates/widgets/clearable_file_input.html 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 %} +

{{ widget.initial_text }}{% trans ":" %} {{ widget.value }}{% if not widget.required %} +  + +{% endif %} +

+

{{ widget.input_text }}{% trans ":" %}

{% endif %} + 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 -- cgit v1.2.3