summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
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
commit0fb2540a3359a38a2df7db05b76f6238e0d5ae35 (patch)
tree74f205d9d8e4c22e479fba867e8983879d477a51 /ishtar_common
parentcec6d7b3112b95ea2c10848f824d48a3e8cce035 (diff)
downloadIshtar-0fb2540a3359a38a2df7db05b76f6238e0d5ae35.tar.bz2
Ishtar-0fb2540a3359a38a2df7db05b76f6238e0d5ae35.zip
Improve file widget with bootstrap
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms_common.py4
-rw-r--r--ishtar_common/templates/widgets/clearable_file_input.html8
-rw-r--r--ishtar_common/widgets.py4
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 %}
+&nbsp; <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