Skip to content

Commit

Permalink
Add formatting for file fields
Browse files Browse the repository at this point in the history
  • Loading branch information
krejcar25 committed Jun 5, 2021
1 parent 3f64e1e commit f004263
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions adminlte3_theme/static/admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ label {
color: #333;
}

.custom-file label {
font-size: 16px;
}

/* RADIO BUTTONS */

form ul.radiolist li {
Expand Down
12 changes: 12 additions & 0 deletions adminlte3_theme/templates/admin/widgets/clearable_file_input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <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 }}"{% if widget.attrs.disabled %} disabled{% endif %}>
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br>
{{ widget.input_text }}:{% endif %}
<div class="input-group">
<div class="custom-file">
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>
<label class="custom-file-label" for="{{ widget.attrs.id }}">Choose file</label>
</div>
</div>
{% if widget.is_initial %}</p>{% endif %}
8 changes: 7 additions & 1 deletion adminlte3_theme/templatetags/bootstrap_forms.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down

0 comments on commit f004263

Please sign in to comment.