Skip to content

Commit

Permalink
Merge pull request Uninett#3052 from Uninett/uncrispify/ThresholdForm
Browse files Browse the repository at this point in the history
Uncrispify ThresholdForm
  • Loading branch information
stveit authored Oct 2, 2024
2 parents a7246a2 + 6c651d8 commit 48aeae6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
7 changes: 5 additions & 2 deletions python/nav/web/templates/threshold/set_threshold.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block base_header_additional_head %}
<script>require(['src/threshold']);</script>
Expand All @@ -21,7 +20,11 @@ <h4>{{ heading }}</h4>
data-url="{% url 'threshold-search' %}"
data-renderurl="{% url 'threshold-graph' %}"
data-metric="{{ metric|default_if_none:'' }}">
{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/flat_form.html' %}
{% else %}
{{ form }}
{% endif %}
</div>
{% if id %}
<a href="#" data-dropdown="confirm-delete" class="button alert">Delete</a>
Expand Down
70 changes: 48 additions & 22 deletions python/nav/web/threshold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

import re

from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Fieldset, Submit, Row, Column
from django import forms

from nav.metrics.thresholds import ThresholdEvaluator, InvalidExpressionError
from nav.models.thresholds import ThresholdRule
from nav.util import parse_interval
from nav.web.crispyforms import HelpField
from nav.web.crispyforms import (
FlatFieldset,
SubmitField,
set_flat_form_attributes,
FormRow,
FormColumn,
HelpFormField,
)


class ThresholdForm(forms.ModelForm):
Expand Down Expand Up @@ -55,25 +60,46 @@ def __init__(self, *args, **kwargs):
action_text = 'Edit rule'

column_class = 'small-4'
self.helper = FormHelper()
self.helper.form_action = ''
self.helper.layout = Layout(
Fieldset(
action_text,
'target',
Row(
Column(HelpField('alert'), css_class=column_class),
Column(HelpField('clear'), css_class=column_class),
Column(HelpField('period'), css_class=column_class),
),
'description',
Row(
Column(
Submit('submit', 'Save', css_class='small'), css_class='small-6'
),
Column(HelpField('raw'), css_class='small-6'),
),
)
self.attrs = set_flat_form_attributes(
form_fields=[
FlatFieldset(
legend=action_text,
fields=[
self['target'],
FormRow(
fields=[
FormColumn(
fields=[HelpFormField(self['alert'])],
css_classes=column_class,
),
FormColumn(
fields=[HelpFormField(self['clear'])],
css_classes=column_class,
),
FormColumn(
fields=[HelpFormField(self['period'])],
css_classes=column_class,
),
]
),
self['description'],
FormRow(
fields=[
FormColumn(
fields=[
SubmitField(value='Save', css_classes='small')
],
css_classes='small-6',
),
FormColumn(
fields=[HelpFormField(self['raw'])],
css_classes='small-6',
),
]
),
],
)
],
)

def clean(self):
Expand Down

0 comments on commit 48aeae6

Please sign in to comment.