diff options
-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 |