From ec513cd974390da4af0af530b31a64f0cc954123 Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 20 Sep 2024 14:24:21 +0200 Subject: [PATCH 1/4] Uncrispyfy NAV's override of crispy-forms-foundation field template This template is extensively used across the whole site. Also removes redundant checkbox class append which is not defined anywhere in CSS and is never rendered in computed styles in browser. --- .../nav/web/templates/foundation-5/field.html | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/python/nav/web/templates/foundation-5/field.html b/python/nav/web/templates/foundation-5/field.html index 15a37ccf60..b10cc62ea5 100644 --- a/python/nav/web/templates/foundation-5/field.html +++ b/python/nav/web/templates/foundation-5/field.html @@ -1,24 +1,22 @@ -{% load crispy_forms_field %} - {% if field.is_hidden %} {{ field }} {% else %}
+ class="ctrlHolder{% if field.errors %} error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}" + > {% spaceless %} {% if field.label %} - {% if field|is_checkbox %} - {% crispy_field field %} + {% if field.field.widget.input_type == 'checkbox' %} + {{ field }} {% endif %}
From 550de5677a39e8fc537d3bbc0a50e20f0a64130e Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 20 Sep 2024 14:32:49 +0200 Subject: [PATCH 2/4] Use generic field in _form_fields.html --- .../nav/web/templates/seeddb/_form_fields.html | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/python/nav/web/templates/seeddb/_form_fields.html b/python/nav/web/templates/seeddb/_form_fields.html index 582491b806..a7f47e9f4a 100644 --- a/python/nav/web/templates/seeddb/_form_fields.html +++ b/python/nav/web/templates/seeddb/_form_fields.html @@ -1,18 +1,3 @@ {% for field in form %} -
- - {{ field }} - {% for error in field.errors %} - - {{ error }} - - {% endfor %} -
+ {% include "foundation-5/field.html" %} {% endfor %} From 1b216cf9e711a7bbea382200d8eff84fbcd12782 Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Mon, 23 Sep 2024 12:32:44 +0200 Subject: [PATCH 3/4] Add template tag for checking if input field is checkbox --- python/nav/django/templatetags/forms.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 python/nav/django/templatetags/forms.py diff --git a/python/nav/django/templatetags/forms.py b/python/nav/django/templatetags/forms.py new file mode 100644 index 0000000000..255300d1df --- /dev/null +++ b/python/nav/django/templatetags/forms.py @@ -0,0 +1,12 @@ +"""Template filters for forms""" + +from django import forms, template + +register = template.Library() + + +# Copied from +# https://github.com/django-crispy-forms/django-crispy-forms/blob/1.8.1/crispy_forms/templatetags/crispy_forms_field.py +@register.filter +def is_checkbox(field): + return isinstance(field.field.widget, forms.CheckboxInput) From e07a0a017915a645b0e7467ed03105696ef72bbf Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Mon, 23 Sep 2024 12:34:13 +0200 Subject: [PATCH 4/4] Use our own is_checkbox tag --- python/nav/web/templates/foundation-5/field.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/nav/web/templates/foundation-5/field.html b/python/nav/web/templates/foundation-5/field.html index b10cc62ea5..279b5ccde5 100644 --- a/python/nav/web/templates/foundation-5/field.html +++ b/python/nav/web/templates/foundation-5/field.html @@ -1,3 +1,5 @@ +{% load forms %} + {% if field.is_hidden %} {{ field }} {% else %} @@ -7,7 +9,7 @@ {% spaceless %} {% if field.label %} - {% if field.field.widget.input_type == 'checkbox' %} + {% if field|is_checkbox %} {{ field }} {% endif %} @@ -27,7 +29,7 @@ {% endif %} - {% if not field.field.widget.input_type == 'checkbox' %} + {% if not field|is_checkbox %} {{ field }} {% endif %}