diff --git a/python/nav/web/alertprofiles/forms.py b/python/nav/web/alertprofiles/forms.py index a5a689bf49..3c8090eace 100644 --- a/python/nav/web/alertprofiles/forms.py +++ b/python/nav/web/alertprofiles/forms.py @@ -23,9 +23,6 @@ from django import forms from django.db.models import Q -from crispy_forms.helper import FormHelper -from crispy_forms_foundation.layout import Layout, Row, Column, Field, Submit - from nav.alertengine.dispatchers.email_dispatcher import Email from nav.alertengine.dispatchers.slack_dispatcher import Slack from nav.alertengine.dispatchers.sms_dispatcher import Sms @@ -38,6 +35,7 @@ FormRow, FormColumn, HelpFormField, + SubmitField, ) _ = lambda a: a # gettext variable (for future implementations) @@ -174,24 +172,31 @@ class TimePeriodForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(TimePeriodForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() submit_text = 'Add' if self.instance and self.instance.id: self.fields['valid_during'].widget.attrs['disabled'] = 'disabled' submit_text = 'Save' - self.helper.form_tag = False - self.helper.layout = Layout( - 'id', - 'profile', - Row( - Column('start', css_class='medium-6'), - Column( - Field('valid_during', css_class='select2'), css_class='medium-6' + self.fields['valid_during'].widget.attrs.update({"class": "select2"}) + self.attrs = set_flat_form_attributes( + form_fields=[ + self['id'], + self['profile'], + FormRow( + fields=[ + FormColumn( + fields=[self['start']], + css_classes='medium-6', + ), + FormColumn( + fields=[self['valid_during']], + css_classes='medium-6', + ), + ] ), - ), - Submit('submit', submit_text, css_class='small'), + SubmitField(value=submit_text, css_classes='small'), + ] ) class Meta(object): diff --git a/python/nav/web/templates/alertprofiles/timeperiod_edit.html b/python/nav/web/templates/alertprofiles/timeperiod_edit.html index 96503758bc..6fc7c471f9 100644 --- a/python/nav/web/templates/alertprofiles/timeperiod_edit.html +++ b/python/nav/web/templates/alertprofiles/timeperiod_edit.html @@ -1,10 +1,13 @@ {% extends "alertprofiles/base.html" %} -{% load crispy_forms_tags %} {% block tabcontent %}
- {% crispy time_period_form %} + {% if time_period_form.attrs %} + {% include 'custom_crispy_templates/_form_content.html' with form=time_period_form %} + {% else %} + {{ time_period_form }} + {% endif %}
{% endblock %} diff --git a/python/nav/web/templates/alertprofiles/timeperiod_form.html b/python/nav/web/templates/alertprofiles/timeperiod_form.html index aef8f59aba..3ce021324b 100644 --- a/python/nav/web/templates/alertprofiles/timeperiod_form.html +++ b/python/nav/web/templates/alertprofiles/timeperiod_form.html @@ -1,10 +1,11 @@ -{% load crispy_forms_tags %} - {% if time_period %}

Edit time period

{% else %}

Add new time period

{% endif %} -{% crispy time_period_form %} - +{% if time_period_form.attrs %} + {% include 'custom_crispy_templates/_form_content.html' with form=time_period_form %} +{% else %} + {{ time_period_form }} +{% endif %}