Commit 0e9baa60 authored by root's avatar root

Merge branch 'master' of https://gitlab.rezometz.org/rezo/re2o

parents 7935b653 8599cfd7
...@@ -36,7 +36,9 @@ def url_insert_param(url="", **kwargs): ...@@ -36,7 +36,9 @@ def url_insert_param(url="", **kwargs):
Return the URL with some specific parameters inserted into the query Return the URL with some specific parameters inserted into the query
part. If a URL has already some parameters, those requested will be part. If a URL has already some parameters, those requested will be
modified if already exisiting or will be added and the other parameters modified if already exisiting or will be added and the other parameters
will stay unmodified. will stay unmodified. If parameters with the same name are already in the
URL and a value is specified for this parameter, it will replace all
existing parameters.
**Tag name**:: **Tag name**::
...@@ -82,19 +84,22 @@ def url_insert_param(url="", **kwargs): ...@@ -82,19 +84,22 @@ def url_insert_param(url="", **kwargs):
# Get existing parameters in the url # Get existing parameters in the url
params = {} params = {}
if '?' in url: if '?' in url:
url, params = url.split('?', maxsplit=1) url, parameters = url.split('?', maxsplit=1)
params = { for parameter in parameters.split('&'):
p[:p.find('=')]: p[p.find('=')+1:] for p in params.split('&') p_name, p_value = parameter.split('=', maxsplit=1)
} if p_name not in params:
params[p_name] = []
params[p_name].append(p_value)
# Add the request parameters to the list of parameters # Add the request parameters to the list of parameters
for key, value in kwargs.items(): for key, value in kwargs.items():
params[key] = value params[key] = [value]
# Write the url # Write the url
url += '?' url += '?'
for param, value in params.items(): for param, value_list in params.items():
url += str(param) + '=' + str(value) + '&' for value in value_list:
url += str(param) + '=' + str(value) + '&'
# Remove the last '&' (or '?' if no parameters) # Remove the last '&' (or '?' if no parameters)
return url[:-1] return url[:-1]
...@@ -248,7 +248,7 @@ class SortTable: ...@@ -248,7 +248,7 @@ class SortTable:
if not fields: if not fields:
fields = values.get('default', []) fields = values.get('default', [])
request = request.order_by(*fields) request = request.order_by(*fields)
if order == 'desc': if values.get(col, None) and order == 'desc':
return request.reverse() return request.reverse()
else: else:
return request return request
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from __future__ import unicode_literals """The field used in the admin view for the search app"""
from django.contrib import admin from __future__ import unicode_literals
# Register your models here. # Register your models here.
...@@ -20,21 +20,72 @@ ...@@ -20,21 +20,72 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""The forms used by the search app"""
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db.models import Q from django import forms
from simple_search import BaseSearchForm from django.forms import Form
CHOICES_USER = (
('0', 'Actifs'),
('1', 'Désactivés'),
('2', 'Archivés'),
)
CHOICES_AFF = (
('0', 'Utilisateurs'),
('1', 'Machines'),
('2', 'Factures'),
('3', 'Bannissements'),
('4', 'Accès à titre gracieux'),
('5', 'Chambres'),
('6', 'Ports'),
('7', 'Switchs'),
)
def initial_choices(c):
"""Return the choices that should be activated by default for a
given set of choices"""
return [i[0] for i in c]
from users.models import User, School class SearchForm(Form):
"""The form for a simple search"""
q = forms.CharField(label='Search', max_length=100)
class UserSearchForm(BaseSearchForm):
class Meta:
base_qs = User.objects
search_fields = ('^name', 'description', 'specifications', '=id')
# assumes a fulltext index has been defined on the fields class SearchFormPlus(Form):
# 'name,description,specifications,id' """The form for an advanced search (with filters)"""
fulltext_indexes = ( q = forms.CharField(
('name', 2), # name matches are weighted higher label='Search',
('name,description,specifications,id', 1), max_length=100,
) required=False
)
u = forms.MultipleChoiceField(
label="Filtre utilisateurs",
required=False,
widget=forms.CheckboxSelectMultiple,
choices=CHOICES_USER,
initial=initial_choices(CHOICES_USER)
)
a = forms.MultipleChoiceField(
label="Filtre affichage",
required=False,
widget=forms.CheckboxSelectMultiple,
choices=CHOICES_AFF,
initial=initial_choices(CHOICES_AFF)
)
s = forms.DateField(
required=False,
label="Date de début",
help_text='DD/MM/YYYY',
input_formats=['%d/%m/%Y']
)
e = forms.DateField(
required=False,
help_text='DD/MM/YYYY',
input_formats=['%d/%m/%Y'],
label="Date de fin"
)
# -*- mode: python; coding: utf-8 -*-
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from __future__ import unicode_literals
from django.db import models
from django import forms
from django.forms import Form
from django.forms import ModelForm
CHOICES = (
('0', 'Actifs'),
('1', 'Désactivés'),
('2', 'Archivés'),
)
CHOICES2 = (
(1, 'Active'),
("", 'Désactivée'),
)
CHOICES3 = (
('0', 'Utilisateurs'),
('1', 'Machines'),
('2', 'Factures'),
('3', 'Bannissements'),
('4', 'Accès à titre gracieux'),
('6', 'Switchs'),
('5', 'Ports'),
)
class SearchForm(Form):
search_field = forms.CharField(label = 'Search', max_length = 100)
class SearchFormPlus(Form):
search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
filtre = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
connexion = forms.MultipleChoiceField(label="Filtre connexion", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES2)
affichage = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES3)
date_deb = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'])
date_fin = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
...@@ -36,30 +36,35 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -36,30 +36,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h2>Résultats dans les machines : </h2> <h2>Résultats dans les machines : </h2>
{% include "machines/aff_machines.html" with machines_list=machines_list %} {% include "machines/aff_machines.html" with machines_list=machines_list %}
{% endif %} {% endif %}
{% if facture_list %} {% if factures_list %}
<h2>Résultats dans les factures : </h2> <h2>Résultats dans les factures : </h2>
{% include "cotisations/aff_cotisations.html" with facture_list=facture_list %} {% include "cotisations/aff_cotisations.html" with facture_list=factures_list %}
{% endif %} {% endif %}
{% if white_list %} {% if whitelists_list %}
<h2>Résultats dans les accès à titre gracieux : </h2> <h2>Résultats dans les accès à titre gracieux : </h2>
{% include "users/aff_whitelists.html" with white_list=white_list %} {% include "users/aff_whitelists.html" with white_list=whitelists_list %}
{% endif %} {% endif %}
{% if ban_list %} {% if bans_list %}
<h2>Résultats dans les banissements : </h2> <h2>Résultats dans les banissements : </h2>
{% include "users/aff_bans.html" with ban_list=ban_list %} {% include "users/aff_bans.html" with ban_list=bans_list %}
{% endif %} {% endif %}
{% if switch_list %} {% if rooms_list %}
<h2>Résultats dans les switchs : </h2> <h2>Résultats dans les chambres : </h2>
{% include "topologie/aff_switch.html" with switch_list=switch_list %} {% include "topologie/aff_chambres.html" with room_list=rooms_list %}
{% endif %} {% endif %}
{% if port_list %} {% if switch_ports_list %}
<h2>Résultats dans les ports : </h2> <h2>Résultats dans les ports : </h2>
{% include "topologie/aff_port.html" with port_list=port_list %} {% include "topologie/aff_port.html" with port_list=switch_ports_list %}
{% endif %}
{% if switches_list %}
<h2>Résultats dans les switchs : </h2>
{% include "topologie/aff_switch.html" with switch_list=switches_list %}
{% endif %} {% endif %}
{% if not ban_list and not interfaces_list and not users_list and not facture_list and not white_list and not port_list and not switch_list%} {% if not users_list and not machines_list and not factures_list and not whitelists_list and not bans_list and not rooms_list and not switch_ports_list and not switches_list %}
<h3>Aucun résultat</h3> <h3>Aucun résultat</h3>
{% else %}
<h6>(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)</h6>
{% endif %} {% endif %}
<h6>(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)</h6>
<br /> <br />
<br /> <br />
<br /> <br />
......
...@@ -28,11 +28,14 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -28,11 +28,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}Recherche{% endblock %} {% block title %}Recherche{% endblock %}
{% block content %} {% block content %}
{% bootstrap_form_errors searchform %} {% bootstrap_form_errors search_form %}
<form class="form" method="post"> <form class="form">
{% csrf_token %} {% bootstrap_field search_form.q %}
{% bootstrap_form searchform %} {% include "buttons/multiple_checkbox_alt.html" with field=search_form.u %}
{% include "buttons/multiple_checkbox_alt.html" with field=search_form.a %}
{% bootstrap_field search_form.s %}
{% bootstrap_field search_form.e %}
{% bootstrap_button "Search" button_type="submit" icon="search" %} {% bootstrap_button "Search" button_type="submit" icon="search" %}
</form> </form>
<br /> <br />
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""The urls used by the search app"""
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
...@@ -28,5 +30,5 @@ from . import views ...@@ -28,5 +30,5 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.search, name='search'), url(r'^$', views.search, name='search'),
url(r'^avance/$', views.searchp, name='searchp'), url(r'^advanced/$', views.searchp, name='searchp'),
] ]
This diff is collapsed.
...@@ -73,10 +73,9 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -73,10 +73,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %} {% endif %}
</ul> </ul>
<div class="col-sm-3 col-md-3 navbar-right"> <div class="col-sm-3 col-md-3 navbar-right">
<form action="{% url "search:search"%}" method="POST" class="navbar-form" role="search"> <form action="{% url "search:search"%}" class="navbar-form" role="search">
{% csrf_token %}
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term"> <input type="text" class="form-control" placeholder="Search" name="q" id="search-term" {% if search_term %}value="{{ search_term }}"{% endif %}>
<div class="input-group-btn"> <div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button> <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="glyphicon glyphicon-plus"></i></a> <a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="glyphicon glyphicon-plus"></i></a>
......
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<div class="form-group {% if field.form.errors %}{% if field.errors %}has-error{% else %}has-success{% endif %}{% endif %}">
<label class="control-label" for="{{ field.id_for_label }}">
{{ field.label }}
</label>
<div id="{{ field.auto_id }}" data-toggle="buttons">
{% for val in field.field.choices %}
<label for="id_u_{{ val.0 }}" class="btn btn-default{% if val.0 in field.initial %} active{% endif %}">
<input {% if val.0 in field.initial %}checked="checked" {% endif %}class="" id="id_u_{{ val.0 }}" name="{{ field.name }}" title="" type="checkbox" value="{{ val.0 }}" /> {{ val.1 }}
</label>
{% endfor %}
</div>
{% for error in field.errors %}
<div class="help-block">{{ error }}</div>
{% endfor %}
<div class="help-block">{{ field.help_text }}</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment