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

Uncrispify ViewForm in sortedstats #3077

Merged
merged 2 commits into from
Oct 4, 2024
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
67 changes: 46 additions & 21 deletions python/nav/web/sortedstats/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@
"""Forms for sorted stats"""

from operator import itemgetter

from django import forms
from crispy_forms.helper import FormHelper

from crispy_forms_foundation.layout import Layout, Fieldset, Row, Column
from nav.web.crispyforms import LabelSubmit

from nav.web.crispyforms import (
FlatFieldset,
FormColumn,
FormRow,
LabelSubmit,
SubmitField,
set_flat_form_attributes,
)
from . import CLASSMAP, TIMEFRAMES


Expand Down Expand Up @@ -60,23 +69,39 @@ class ViewForm(forms.Form):

def __init__(self, *args, **kwargs):
super(ViewForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'custom'
self.helper.form_action = ''
self.helper.form_method = 'GET'
self.helper.help_text_inline = True
self.helper.layout = Layout(
Fieldset(
'Choose statistic',
Row(
Column('view', css_class='medium-5'),
Column('timeframe', css_class='medium-3'),
Column('rows', css_class='medium-1'),
Column(
LabelSubmit('submit', 'Show statistics', css_class='postfix'),
css_class='medium-3',
),
Column('use_cache'),
),
)

self.attrs = set_flat_form_attributes(
form_method="get",
form_class="custom",
form_fields=[
FlatFieldset(
"Choose statistic",
fields=[
FormRow(
fields=[
FormColumn(
fields=[self["view"]], css_classes="medium-5"
),
FormColumn(
fields=[self["timeframe"]], css_classes="medium-3"
),
FormColumn(
fields=[self["rows"]], css_classes="medium-1"
),
FormColumn(
fields=[
SubmitField(
value="Show statistics",
css_classes="postfix",
has_empty_label=True,
)
],
css_classes="medium-3",
),
FormColumn(fields=[self["use_cache"]]),
]
)
],
)
],
)
7 changes: 5 additions & 2 deletions python/nav/web/templates/sortedstats/sortedstats.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends "base.html" %} {# Don't need a deeper hierarchy for one template #}
{% load crispy_forms_tags %}
{% load tools %}

{% block base_header_additional_head %}
Expand All @@ -23,7 +22,11 @@
</div>
{% endif %}

{% crispy form %}
{% if form.attrs %}
{% include 'custom_crispy_templates/flat_form.html' %}
{% else %}
{{ form }}
{% endif %}

{# Display view if exists #}
{% if result %}
Expand Down
Loading