Skip to content

Commit

Permalink
Uncrispify AlertStatusForm in navlets
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Oct 11, 2024
1 parent cc77c82 commit 5c1d526
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 67 deletions.
161 changes: 96 additions & 65 deletions python/nav/web/status2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +29,7 @@
FormRow,
FormColumn,
FlatFieldset,
SubmitField,
)
from . import STATELESS_THRESHOLD

Expand Down Expand Up @@ -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"),
)


Expand Down
7 changes: 5 additions & 2 deletions python/nav/web/templates/navlets/status2_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends 'navlets/base.html' %}
{% load crispy_forms_tags %}

{% block navlet-content %}

Expand All @@ -8,7 +7,11 @@
Refresh interval (seconds)
<input type="text" name="interval" value="{{ interval }}">
</label>
{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/_form_content.html' %}
{% else %}
{{ form }}
{% endif %}
</form>

<script>
Expand Down

0 comments on commit 5c1d526

Please sign in to comment.