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/edit_inline/tabular.html b/adminlte3_theme/templates/admin/edit_inline/tabular.html new file mode 100644 index 0000000..d305254 --- /dev/null +++ b/adminlte3_theme/templates/admin/edit_inline/tabular.html @@ -0,0 +1,120 @@ +{% load i18n admin_urls static admin_modify bootstrap_forms %} +
+ {{ inline_admin_formset.formset.management_form }} +
+

+ {% if inline_admin_formset.formset.max_num == 1 %} + {{ inline_admin_formset.opts.verbose_name|capfirst }} + {% else %} + {{ inline_admin_formset.opts.verbose_name_plural|capfirst }} + {% endif %} +

+
+ +
+
+
+ {{ inline_admin_formset.formset.non_form_errors }} + + + + + {% for field in inline_admin_formset.fields %} + {% if not field.widget.is_hidden %} + + {% endif %} + {% endfor %} + {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %} + + {% endif %} + + + + {% for inline_admin_form in inline_admin_formset %} + {% if inline_admin_form.form.non_field_errors %} + + + + {% endif %} + + + {% for fieldset in inline_admin_form %} + {% for line in fieldset %} + {% for field in line %} + {% if field.is_readonly or not field.field.is_hidden %} + + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %} + + {% endif %} + + {% endfor %} + +
+ {{ field.label|capfirst }} + {% if field.help_text %} + ({{ field.help_text|striptags }}) + {% endif %} + {% translate "Delete?" %}
{{ inline_admin_form.form.non_field_errors }} +
+ {% if inline_admin_form.original or inline_admin_form.show_url %} +

+ {% if inline_admin_form.original %} + {{ inline_admin_form.original }} + {% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %} + + {% if inline_admin_formset.has_change_permission %} + {% translate "Change" %} + {% else %} + {% translate "View" %} + {% endif %} + + {% endif %} + {% endif %} + {% if inline_admin_form.show_url %} + {% translate "View on site" %} + {% endif %} +

+ {% endif %} + {% if inline_admin_form.needs_explicit_pk_field %} + {{ inline_admin_form.pk_field.field|bootstrap_input }} + {% endif %} + {% if inline_admin_form.fk_field %} + {{ inline_admin_form.fk_field.field|bootstrap_input }} + {% endif %} + {% spaceless %} + {% for fieldset in inline_admin_form %} + {% for line in fieldset %} + {% for field in line %} + {% if not field.is_readonly and field.field.is_hidden %} + {{ field.field }} + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + {% endspaceless %} +
+ {% if field.is_readonly %} +

{{ field.contents }}

+ {% else %} +
+ {{ field.field|bootstrap_input }} + {% if field.field.errors %} +
+ {{ field.field.errors.as_ul }} +
+ {% endif %} +
+ {% endif %} +
+ {% if inline_admin_form.original %} +
+ {{ inline_admin_form.deletion_field.field|bootstrap_input }} +
+ {% endif %} +
+
+
diff --git a/adminlte3_theme/templates/admin/includes/fieldset.html b/adminlte3_theme/templates/admin/includes/fieldset.html index b9b7ed1..c32e61a 100644 --- a/adminlte3_theme/templates/admin/includes/fieldset.html +++ b/adminlte3_theme/templates/admin/includes/fieldset.html @@ -1,3 +1,4 @@ +{% load bootstrap_forms %}

{% if fieldset.name %}{{ fieldset.name }}{% endif %}

@@ -18,13 +19,13 @@

{% if fieldset.name %}{{ fieldset.name }}{% endif %}

{% if field.is_checkbox %} - {{ field.field }} + {{ field.field|bootstrap_input }} {% else %} {% if field.is_readonly %}
{{ field.contents }}
{% else %} - {{ field.field }} + {{ field.field|bootstrap_input }} {% endif %} {% endif %} {% if field.field.help_text %} @@ -37,4 +38,4 @@

{% if fieldset.name %}{{ fieldset.name }}{% endif %}

{% endfor %}
-
\ No newline at end of file + 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/templates/admin/widgets/related_widget_wrapper.html b/adminlte3_theme/templates/admin/widgets/related_widget_wrapper.html new file mode 100644 index 0000000..135237e --- /dev/null +++ b/adminlte3_theme/templates/admin/widgets/related_widget_wrapper.html @@ -0,0 +1,31 @@ +{% load i18n static %} +
+ {{ rendered_widget }} + {% block links %} + {% spaceless %} + {% if not is_hidden %} + {% if can_change_related %} +
+ + + +
+ {% endif %} + {% if can_add_related %} +
+ + + +
+ {% endif %} + {% if can_delete_related %} +
+ + + +
+ {% endif %} + {% endif %} + {% endspaceless %} + {% endblock %} +
diff --git a/adminlte3_theme/templatetags/bootstrap_forms.py b/adminlte3_theme/templatetags/bootstrap_forms.py new file mode 100644 index 0000000..abb7c6a --- /dev/null +++ b/adminlte3_theme/templatetags/bootstrap_forms.py @@ -0,0 +1,43 @@ +from django.contrib.admin.widgets import RelatedFieldWidgetWrapper, AdminSplitDateTime, AdminFileWidget +from django.template import Library +from django.utils.safestring import mark_safe + +register = Library() + + +@register.filter(is_safe=True) +def bootstrap_input(value): + """Adds appropriate bootstrap CSS classes to widgets so that they are rendered bootstrap-ish""" + 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: + bootstrap_class = "form-control" + + # We always have a list. This checks if first item contains something (list is not [''], meaning the attribute + # contained something) and then adds the bootstrap_class if it is not already there. If the list is "empty" then we create + # a new one that contains only the bootstrap_class we want. + if current_classes[0] and bootstrap_class not in current_classes: + current_classes.append(bootstrap_class) + else: + current_classes = [bootstrap_class] + + # Also add the is-invalid class to render the field with a red border if there are any errors. + if value.errors: + current_classes.append("is-invalid") + + return value.as_widget(attrs={"class": " ".join(current_classes)})