From 7e69461d84b52be834a3f3a60c5d2c8ca028d644 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Fri, 11 Oct 2024 13:31:26 +0200 Subject: [PATCH] Uncrispify StatusWidgetForm in navlets --- python/nav/web/status2/forms.py | 161 +++++++++++------- .../web/templates/navlets/status2_edit.html | 3 +- 2 files changed, 97 insertions(+), 67 deletions(-) diff --git a/python/nav/web/status2/forms.py b/python/nav/web/status2/forms.py index e41fb8f70c..a180679a19 100644 --- a/python/nav/web/status2/forms.py +++ b/python/nav/web/status2/forms.py @@ -20,14 +20,6 @@ from django import forms from django.forms.utils import pretty_name -from crispy_forms.helper import FormHelper -from crispy_forms_foundation.layout import ( - Layout, - Row, - Column, - Field, - Submit, -) from nav.models.event import EventType, AlertType from nav.models.manage import Organization, Category, NetboxGroup, Location @@ -37,6 +29,7 @@ FormRow, FormColumn, FlatFieldset, + SubmitField, ) from . import STATELESS_THRESHOLD @@ -201,72 +194,110 @@ class StatusWidgetForm(StatusPanelForm): def __init__(self, *args, **kwargs): super(StatusWidgetForm, self).__init__(*args, **kwargs) + for field_name in ( + "event_type", + "not_event_type", + "category", + "not_category", + "alert_type", + "not_alert_type", + "organization", + "not_organization", + "device_group", + "not_device_group", + "location", + "not_location", + "severity", + "not_severity", + ): + self.fields[field_name].widget.attrs.update({'class': 'select2'}) + column_class = 'medium-6' - self.helper = FormHelper() - self.helper.form_tag = False - self.helper.layout = Layout( - Row( - Column( - Field('event_type', css_class='select2'), css_class=column_class - ), - Column( - Field('not_event_type', css_class='select2'), css_class=column_class - ), - ), - Row( - Column(Field('category', css_class='select2'), css_class=column_class), - Column( - Field('not_category', css_class='select2'), css_class=column_class - ), - ), - Row( - Column( - Field('alert_type', css_class='select2'), css_class=column_class - ), - Column( - Field('not_alert_type', css_class='select2'), css_class=column_class + + self.attrs = set_flat_form_attributes( + form_fields=[ + FormRow( + fields=[ + FormColumn( + fields=[self["event_type"]], css_classes=column_class + ), + FormColumn( + fields=[self["not_event_type"]], css_classes=column_class + ), + ] ), - ), - Row( - Column( - Field('organization', css_class='select2'), css_class=column_class + FormRow( + fields=[ + FormColumn(fields=[self["category"]], css_classes=column_class), + FormColumn( + fields=[self["not_category"]], css_classes=column_class + ), + ] ), - Column( - Field('not_organization', css_class='select2'), - css_class=column_class, + FormRow( + fields=[ + FormColumn( + fields=[self["alert_type"]], css_classes=column_class + ), + FormColumn( + fields=[self["not_alert_type"]], css_classes=column_class + ), + ] ), - ), - Row( - Column( - Field('device_group', css_class='select2'), css_class=column_class + FormRow( + fields=[ + FormColumn( + fields=[self["organization"]], css_classes=column_class + ), + FormColumn( + fields=[self["not_organization"]], css_classes=column_class + ), + ] ), - Column( - Field('not_device_group', css_class='select2'), - css_class=column_class, + FormRow( + fields=[ + FormColumn( + fields=[self["device_group"]], css_classes=column_class + ), + FormColumn( + fields=[self["not_device_group"]], css_classes=column_class + ), + ] ), - ), - Row( - Column(Field('location', css_class='select2'), css_class=column_class), - Column( - Field('not_location', css_class='select2'), css_class=column_class + FormRow( + fields=[ + FormColumn(fields=[self["location"]], css_classes=column_class), + FormColumn( + fields=[self["not_location"]], css_classes=column_class + ), + ] ), - ), - Row( - Column(Field('severity', css_class='select2'), css_class=column_class), - Column( - Field('not_severity', css_class='select2'), css_class=column_class + FormRow( + fields=[ + FormColumn(fields=[self["severity"]], css_classes=column_class), + FormColumn( + fields=[self["not_severity"]], css_classes=column_class + ), + ] ), - ), - Row( - Column('stateless', 'stateless_threshold', css_class=column_class), - Column( - 'acknowledged', - 'on_maintenance', - 'extra_columns', - css_class=column_class, + FormRow( + fields=[ + FormColumn( + fields=[self["stateless"], self["stateless_threshold"]], + css_classes=column_class, + ), + FormColumn( + fields=[ + self["acknowledged"], + self["on_maintenance"], + self["extra_columns"], + ], + css_classes=column_class, + ), + ] ), - ), - Submit('submit', 'Save'), + ], + submit_field=SubmitField(value="Save"), ) diff --git a/python/nav/web/templates/navlets/status2_edit.html b/python/nav/web/templates/navlets/status2_edit.html index f6a934cfc1..a2b2efe25a 100644 --- a/python/nav/web/templates/navlets/status2_edit.html +++ b/python/nav/web/templates/navlets/status2_edit.html @@ -1,5 +1,4 @@ {% extends 'navlets/base.html' %} -{% load crispy_forms_tags %} {% block navlet-content %} @@ -8,7 +7,7 @@ Refresh interval (seconds) - {% crispy form %} + {% include 'custom_crispy_templates/_form_content.html' %}