From 64ec82a6c88bf466224f46d74073425599233c31 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Thu, 7 Nov 2024 14:41:48 +0100 Subject: [PATCH] Add class representing a Div Just a blank div that can be customized with classes and stuff. replaces crispyforms Div. --- python/nav/web/crispyforms.py | 15 +++++++++++++++ .../custom_crispy_templates/form_div.html | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 python/nav/web/templates/custom_crispy_templates/form_div.html diff --git a/python/nav/web/crispyforms.py b/python/nav/web/crispyforms.py index b3e46cd33d..afefa63bfa 100644 --- a/python/nav/web/crispyforms.py +++ b/python/nav/web/crispyforms.py @@ -195,3 +195,18 @@ class and template definitions. form_id=form_id, form_class=form_class, ) + + +class FormDiv: + """A class representing a div in a form layout. + + :param fields: A list of fields to include in the div. + :param css_classes: Additional CSS classes to apply to the div. + """ + + def __init__( + self, fields: Optional[list] = None, css_classes: Optional[str] = None + ): + self.fields = fields + self.css_classes = css_classes + self.template = 'custom_crispy_templates/form_div.html' diff --git a/python/nav/web/templates/custom_crispy_templates/form_div.html b/python/nav/web/templates/custom_crispy_templates/form_div.html new file mode 100644 index 0000000000..73ffea92c8 --- /dev/null +++ b/python/nav/web/templates/custom_crispy_templates/form_div.html @@ -0,0 +1,11 @@ +{# NB! This form div can only render fields that are supported by custom_crispy_templates/_form_field.html #} + +
+ {% block formdiv_content %} + {% for field in field.fields %} + {% include 'custom_crispy_templates/_form_field.html' %} + {% endfor %} + {% endblock %} +