Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncrispyfy DeviceHistoryViewFilter form in devicehistory #3041

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions python/nav/web/devicehistory/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import logging

from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Fieldset, Row, Column, Field
from nav.web.crispyforms import (
set_flat_form_attributes,
FlatFieldset,
FormRow,
FormColumn,
)
from nav.web.devicehistory.utils import get_event_and_alert_types

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -57,7 +61,9 @@ class DeviceHistoryViewFilter(forms.Form):
from_date = MyDateField(required=False)
to_date = MyDateField(required=False)
eventtype = forms.ChoiceField(required=False, label='Type')
eventtype.widget.attrs.update({"class": "select2"})
group_by = forms.ChoiceField(choices=groupings, initial='netbox', required=False)
group_by.widget.attrs.update({"class": "select2"})

def __init__(self, *args, **kwargs):
super(DeviceHistoryViewFilter, self).__init__(*args, **kwargs)
Expand All @@ -68,22 +74,30 @@ def __init__(self, *args, **kwargs):

common_class = 'medium-3'

self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Fieldset(
'Filters',
Row(
Column('from_date', css_class=common_class),
Column('to_date', css_class=common_class),
Column(
Field('eventtype', css_class='select2'), css_class=common_class
),
Column(
Field('group_by', css_class='select2'), css_class=common_class
),
),
)
self.attrs = set_flat_form_attributes(
form_fields=[
FlatFieldset(
"Filters",
fields=[
FormRow(
fields=[
FormColumn(
fields=[self['from_date']], css_classes=common_class
),
FormColumn(
fields=[self['to_date']], css_classes=common_class
),
FormColumn(
fields=[self['eventtype']], css_classes=common_class
),
FormColumn(
fields=[self['group_by']], css_classes=common_class
),
]
)
],
)
]
)

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

{% block tabcontent %}
<p class="panel">
Expand All @@ -11,7 +10,11 @@
<form action="{% url 'devicehistory-search' %}" method="get">
<div class="row">
<div class="large-8 column">
{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/_form_content.html' %}
{% else %}
{{ form }}
{% endif %}
</div>
</div>
<div class="row">
Expand Down
7 changes: 5 additions & 2 deletions python/nav/web/templates/devicehistory/history_view.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "devicehistory/base.html" %}
{% load crispy_forms_tags %}

{% block tabcontent %}
<a href="{% url 'devicehistory-search' %}" class="button small secondary">New search</a>
Expand All @@ -12,7 +11,11 @@
<input type="hidden" name="{{ type }}" value="{{ id }}" />
{% endfor %}
{% endfor %}
{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/_form_content.html' %}
{% else %}
{{ form }}
{% endif %}
<input type="submit" class="button small" value="Filter">
</form>
</div>
Expand Down
Loading