Skip to content

Commit

Permalink
Merge pull request #3058 from Uninett/uncrispify/AlertSubscriptionForm
Browse files Browse the repository at this point in the history
Uncrispify AlertSubscriptionForm
  • Loading branch information
stveit authored Oct 2, 2024
2 parents 1de8f59 + 174f143 commit 63d4fd3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
55 changes: 38 additions & 17 deletions python/nav/web/alertprofiles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@
from nav.models.profiles import AlertProfile, TimePeriod, AlertSubscription
from nav.models.profiles import AlertAddress, AlertSender
from nav.util import is_valid_cidr, is_valid_ip
from nav.web.crispyforms import HelpField
from nav.web.crispyforms import (
FlatFieldset,
set_flat_form_attributes,
FormRow,
FormColumn,
HelpFormField,
HelpField,
)

_ = lambda a: a # gettext variable (for future implementations)

Expand Down Expand Up @@ -258,6 +265,7 @@ def __init__(self, *args, **kwargs):
),
},
label='Send alerts to',
widget=forms.Select(attrs={'class': 'select2'}),
)
self.fields['filter_group'] = forms.ModelChoiceField(
queryset=filter_groups,
Expand All @@ -269,8 +277,14 @@ def __init__(self, *args, **kwargs):
),
},
label='Watch',
widget=forms.Select(attrs={'class': 'select2'}),
)
self.fields['ignore_resolved_alerts'] = forms.BooleanField(
required=False,
widget=forms.CheckboxInput(attrs={'class': 'input-align'}),
)
self.fields['type'].label = 'When'
self.fields['type'].widget.attrs.update({"class": "select2"})
self.fields[
'type'
].help_text = """
Expand All @@ -289,23 +303,30 @@ def __init__(self, *args, **kwargs):
over and a new one starts.</dd>
</dl>
"""

self.helper = FormHelper()
self.helper.layout = Layout(
Row(
Column(
Field('filter_group', css_class='select2'), css_class='medium-3'
),
Column(
Field('alert_address', css_class='select2'), css_class='medium-3'
),
Column(HelpField('type', css_class='select2'), css_class='medium-3'),
Column(
Field('ignore_resolved_alerts', css_class='input-align'),
css_class='medium-3',
self.attrs = set_flat_form_attributes(
form_fields=[
FormRow(
fields=[
FormColumn(
fields=[self['filter_group']],
css_classes='medium-3',
),
FormColumn(
fields=[self['alert_address']],
css_classes='medium-3',
),
FormColumn(
fields=[HelpFormField(self['type'])],
css_classes='medium-3',
),
FormColumn(
fields=[self['ignore_resolved_alerts']],
css_classes='medium-3',
),
]
),
),
*hidden_fields,
*[self[field] for field in hidden_fields],
]
)

def clean(self):
Expand Down
7 changes: 5 additions & 2 deletions python/nav/web/templates/alertprofiles/subscription_form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "alertprofiles/base.html" %}
{% load crispy_forms_tags %}

{% block tabcontent %}
<h4>
Expand Down Expand Up @@ -84,7 +83,11 @@ <h5>{{ editing|yesno:"Edit,Add new" }} subscription</h5>
<a href="{% url 'alertprofiles-filter_groups-new' %}">Add your first filter group</a> to fix this problem.
</div>
{% endif %}
{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/_form_content.html' %}
{% else %}
{{ form }}
{% endif %}
<input type="submit" value="{{ editing|yesno:"Save,Add" }}" class="button small"/>
</div>
</form>
Expand Down

0 comments on commit 63d4fd3

Please sign in to comment.