Skip to content

Commit

Permalink
Uncrispify SearchForm in ipdevinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Oct 8, 2024
1 parent 1f657b1 commit b3aba5e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
41 changes: 25 additions & 16 deletions python/nav/web/ipdevinfo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Row, Column, Field, Submit
from crispy_forms_foundation.layout import Layout, Row, Column
from nav.models.manage import Sensor
from nav.web.crispyforms import LabelSubmit
from nav.web.crispyforms import (
FormColumn,
FormRow,
LabelSubmit,
SubmitField,
set_flat_form_attributes,
)


class SearchForm(forms.Form):
Expand All @@ -29,21 +35,24 @@ class SearchForm(forms.Form):

def __init__(self, *args, **kwargs):
super(SearchForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_action = 'ipdevinfo-search'
self.helper.form_method = 'GET'
self.helper.layout = Layout(
Row(
Column(
Field('query', placeholder='IP or hostname'), css_class='medium-9'
),
Column(
Submit('submit', 'Search', css_class='postfix'),
css_class='medium-3',
),
css_class='collapse',
)

self.attrs = set_flat_form_attributes(
form_action="ipdevinfo-search",
form_method="get",
form_fields=[
FormRow(
fields=[
FormColumn(fields=[self["query"]], css_classes="medium-9"),
FormColumn(
fields=[SubmitField(value="Search", css_classes="postfix")],
css_classes="medium-3",
),
],
css_classes="collapse",
)
],
)
self.fields['query'].widget.attrs.update({"placeholder": "IP or hostname"})


class ActivityIntervalForm(forms.Form):
Expand Down
7 changes: 5 additions & 2 deletions python/nav/web/templates/ipdevinfo/search.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{% extends "info/base.html" %}
{% load crispy_forms_tags %}

{% block content %}

<h4>IP Device search</h4>

<div class="row">
<div class="column medium-6">
{% crispy search_form %}
{% if search_form.attrs %}
{% include 'custom_crispy_templates/flat_form.html' with form=search_form %}
{% else %}
{{ search_form }}
{% endif %}
</div>
</div>

Expand Down

0 comments on commit b3aba5e

Please sign in to comment.