From f0042633d7d7b35dc0d1210be806f161d1cd6296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Krej=C4=8D=C3=AD?= Date: Sat, 5 Jun 2021 22:07:22 +0200 Subject: [PATCH] Add formatting for file fields --- adminlte3_theme/static/admin/css/forms.css | 4 ++++ .../admin/widgets/clearable_file_input.html | 12 ++++++++++++ adminlte3_theme/templatetags/bootstrap_forms.py | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 adminlte3_theme/templates/admin/widgets/clearable_file_input.html diff --git a/adminlte3_theme/static/admin/css/forms.css b/adminlte3_theme/static/admin/css/forms.css index 03b1e11..39a2815 100644 --- a/adminlte3_theme/static/admin/css/forms.css +++ b/adminlte3_theme/static/admin/css/forms.css @@ -39,6 +39,10 @@ label { color: #333; } +.custom-file label { + font-size: 16px; +} + /* RADIO BUTTONS */ form ul.radiolist li { diff --git a/adminlte3_theme/templates/admin/widgets/clearable_file_input.html b/adminlte3_theme/templates/admin/widgets/clearable_file_input.html new file mode 100644 index 0000000..fa73971 --- /dev/null +++ b/adminlte3_theme/templates/admin/widgets/clearable_file_input.html @@ -0,0 +1,12 @@ +{% if widget.is_initial %}

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

+
+ + +
+
+{% if widget.is_initial %}

{% endif %} diff --git a/adminlte3_theme/templatetags/bootstrap_forms.py b/adminlte3_theme/templatetags/bootstrap_forms.py index 0c9c6f5..abb7c6a 100644 --- a/adminlte3_theme/templatetags/bootstrap_forms.py +++ b/adminlte3_theme/templatetags/bootstrap_forms.py @@ -1,4 +1,4 @@ -from django.contrib.admin.widgets import RelatedFieldWidgetWrapper, AdminSplitDateTime +from django.contrib.admin.widgets import RelatedFieldWidgetWrapper, AdminSplitDateTime, AdminFileWidget from django.template import Library from django.utils.safestring import mark_safe @@ -11,12 +11,18 @@ def bootstrap_input(value): current_classes = value.field.widget.attrs.get("class", "").strip().split(" ") field_type = value.field.widget.attrs.get("type", "text") + print(type(value.field.widget)) + if field_type == "range": bootstrap_class = "form-control-range" elif field_type == "checkbox" or field_type == "radio": bootstrap_class = "form-check-input" + elif field_type == "file": + bootstrap_class = "custom-file-input" elif isinstance(value.field.widget, RelatedFieldWidgetWrapper): bootstrap_class = "custom-select" # For wrapped widgets (those with edit, add and delete icons) + elif isinstance(value.field.widget, AdminFileWidget): + bootstrap_class = "custom-file-input" elif isinstance(value.field.widget, AdminSplitDateTime): return value # We don't want to style the date time field (for now) else: