From 17264907d35cfe1f0fc36963fbbc465f2afb1341 Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Thu, 26 Sep 2024 14:40:16 +0200 Subject: [PATCH 1/2] Uncrispyfy AlertWidgetForm in navlets --- python/nav/web/navlets/forms.py | 24 ++++++++++--------- .../nav/web/templates/navlets/alert_edit.html | 6 ++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/python/nav/web/navlets/forms.py b/python/nav/web/navlets/forms.py index ee8cb3ac76..82482e3089 100644 --- a/python/nav/web/navlets/forms.py +++ b/python/nav/web/navlets/forms.py @@ -2,11 +2,10 @@ from django import forms -from crispy_forms.helper import FormHelper -from crispy_forms_foundation import layout - from nav.models.manage import Sensor, Room +from nav.web.crispyforms import set_flat_form_attributes, FlatFieldset + class AlertWidgetForm(forms.Form): """Form for the alert widget""" @@ -42,14 +41,17 @@ def __init__(self, *args, **kwargs): ) ] - self.helper = FormHelper() - self.helper.form_tag = False - self.helper.layout = layout.Layout( - 'on_message', - 'off_message', - layout.Fieldset('Choose sensor or fill in metric', 'sensor', 'metric'), - 'on_state', - 'alert_type', + self.attrs = set_flat_form_attributes( + form_fields=[ + self['on_message'], + self['off_message'], + FlatFieldset( + legend='Choose sensor or fill in metric', + fields=[self['sensor'], self['metric']], + ), + self['on_state'], + self['alert_type'], + ] ) def clean(self): diff --git a/python/nav/web/templates/navlets/alert_edit.html b/python/nav/web/templates/navlets/alert_edit.html index eacb8029a3..62c1ce7cce 100644 --- a/python/nav/web/templates/navlets/alert_edit.html +++ b/python/nav/web/templates/navlets/alert_edit.html @@ -13,7 +13,11 @@

- {% crispy form %} + {% if form.attrs %} + {% include 'custom_crispy_templates/_form_content.html' %} + {% else %} + {% crispy form %} + {% endif %} Cancel
From e52b577d21e7e8ace5e17e043262e0dbd198115f Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Thu, 26 Sep 2024 14:41:26 +0200 Subject: [PATCH 2/2] Remove crispy logic completely from alert widget form --- python/nav/web/templates/navlets/alert_edit.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/nav/web/templates/navlets/alert_edit.html b/python/nav/web/templates/navlets/alert_edit.html index 62c1ce7cce..d48f09112d 100644 --- a/python/nav/web/templates/navlets/alert_edit.html +++ b/python/nav/web/templates/navlets/alert_edit.html @@ -1,5 +1,4 @@ {% extends 'navlets/base.html' %} -{% load crispy_forms_tags %} {% block navlet-content %} @@ -16,7 +15,7 @@ {% if form.attrs %} {% include 'custom_crispy_templates/_form_content.html' %} {% else %} - {% crispy form %} + {{ form }} {% endif %} Cancel