Skip to content

Commit

Permalink
Uncrispify LoggerGroupSearchForm
Browse files Browse the repository at this point in the history
Had to use custom template for the blue info
button embedded in the legend to work properly
  • Loading branch information
stveit committed Nov 13, 2024
1 parent 07822fd commit bc14b4e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 39 deletions.
101 changes: 63 additions & 38 deletions python/nav/web/syslogger/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
"""

from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Fieldset, Row, Column, Field
from nav.models.logger import Priority, LoggerCategory, Origin, LogMessageType
from nav.web.crispyforms import (
FlatFieldset,
FormRow,
FormColumn,
set_flat_form_attributes,
)

DATEFORMAT = ("%Y-%m-%d %H:%M",)

Expand Down Expand Up @@ -48,40 +52,61 @@ def __init__(self, *args, **kwargs):
self.fields['timestamp_from'].widget.format = DATEFORMAT[0]
self.fields['timestamp_to'].widget.format = DATEFORMAT[0]

self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Row(
Column(
Fieldset(
'Filter <a href="http://www.cisco.com/en/US/docs/ios/system/messages/guide/sm_cnovr.html"><i class="fa fa-info-circle"></i></a>',
Row(
Column(
Field('facility', css_class='select2 medium-12'),
css_class='medium-12',
),
Column(
Field('priority', css_class='select2'),
css_class='medium-12',
),
Column(
Field('mnemonic', css_class='select2'),
css_class='medium-12',
),
Column(
Field('origin', css_class='select2'),
css_class='medium-12',
),
Column(
Field('category', css_class='select2'),
css_class='medium-12',
),
Column('timestamp_from', css_class='medium-12'),
Column('timestamp_to', css_class='medium-12'),
Column('show_log', css_class='medium-12'),
),
),
css_class='medium-12',
),
),
for field in ('facility', 'priority', 'mnemonic', 'origin', 'category'):
self.fields[field].widget.attrs.update({"class": "select2"})

self.attrs = set_flat_form_attributes(
form_fields=[
FormRow(
fields=[
FormColumn(
fields=[
FlatFieldset(
legend='Filter',
fields=[
FormRow(
fields=[
FormColumn(
fields=[self['facility']],
css_classes='medium-12',
),
FormColumn(
fields=[self['priority']],
css_classes='medium-12',
),
FormColumn(
fields=[self['mnemonic']],
css_classes='medium-12',
),
FormColumn(
fields=[self['origin']],
css_classes='medium-12',
),
FormColumn(
fields=[self['category']],
css_classes='medium-12',
),
FormColumn(
fields=[self['timestamp_from']],
css_classes='medium-12',
),
FormColumn(
fields=[self['timestamp_to']],
css_classes='medium-12',
),
FormColumn(
fields=[self['show_log']],
css_classes='medium-12',
),
]
)
],
template='syslogger/frag-search-form-fieldset.html',
)
],
css_classes='medium-12',
)
]
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "custom_crispy_templates/flat_fieldset.html" %}

{% block fieldset_legend %}
{{ block.super }}
<a href="http://www.cisco.com/en/US/docs/ios/system/messages/guide/sm_cnovr.html"><i
class="fa fa-info-circle"></i></a>
{% endblock %}
2 changes: 1 addition & 1 deletion python/nav/web/templates/syslogger/frag-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% if form %}
<form id="syslog_search_form" action="{{ form_target }}" method="get">
{% crispy form %}
{% include 'custom_crispy_templates/_form_content.html' %}
<button name="send" data-target="{{ form_target }}" class="button">Search</button>
</form>

Expand Down

0 comments on commit bc14b4e

Please sign in to comment.