Skip to content

Commit

Permalink
Replace formhelper with set_flat_form_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Sep 30, 2024
1 parent 7752ef8 commit 0a7ee93
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions python/nav/web/threshold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@

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,
)


class ThresholdForm(forms.ModelForm):
Expand Down Expand Up @@ -55,25 +59,40 @@ 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=[self['alert']], css_classes=column_class
),
FormColumn(
fields=[self['clear']], css_classes=column_class
),
FormColumn(
fields=[self['period']], css_classes=column_class
),
]
),
self['description'],
FormRow(
fields=[
FormColumn(
fields=[
SubmitField(value='Save', css_classes='small')
],
css_classes='small-6',
),
FormColumn(fields=[self['raw']], css_classes='small-6'),
]
),
],
)
],
)

def clean(self):
Expand Down

0 comments on commit 0a7ee93

Please sign in to comment.