mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Ajout de la recherche avancée
This commit is contained in:
parent
6e811ca387
commit
50945f0dfa
7 changed files with 99 additions and 30 deletions
|
@ -12,8 +12,27 @@ CHOICES = (
|
||||||
('2', 'Archivés'),
|
('2', 'Archivés'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CHOICES2 = (
|
||||||
|
(1, 'Active'),
|
||||||
|
("", 'Désactivée'),
|
||||||
|
)
|
||||||
|
|
||||||
|
CHOICES3 = (
|
||||||
|
('0', 'Utilisateurs'),
|
||||||
|
('1', 'Machines'),
|
||||||
|
('2', 'Factures'),
|
||||||
|
('3', 'Bannissements'),
|
||||||
|
('4', 'Accès à titre gracieux'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(Form):
|
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)
|
search_field = forms.CharField(label = 'Search', max_length = 100, required=False)
|
||||||
filtre = forms.MultipleChoiceField(label="Filtre utilisateur", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES)
|
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_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")
|
date_fin = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "users/sidebar.html" %}
|
{% extends "search/sidebar.html" %}
|
||||||
{% load bootstrap3 %}
|
{% load bootstrap3 %}
|
||||||
|
|
||||||
{% block title %}Résultats de la recherche{% endblock %}
|
{% block title %}Résultats de la recherche{% endblock %}
|
||||||
|
@ -16,11 +16,15 @@
|
||||||
<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=facture_list %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if white_list %}
|
||||||
|
<h2>Résultats dans les accès à titre gracieux : </h2>
|
||||||
|
{% include "users/aff_whitelists.html" with white_list=white_list %}
|
||||||
|
{% endif %}
|
||||||
{% if ban_list %}
|
{% if ban_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=ban_list %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not ban_list and not machine_list and not users_list and not facture_list%}
|
{% if not ban_list and not machine_list and not users_list and not facture_list and not white_list%}
|
||||||
<h3>Aucun résultat</h3>
|
<h3>Aucun résultat</h3>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "users/sidebar.html" %}
|
{% extends "search/sidebar.html" %}
|
||||||
{% load bootstrap3 %}
|
{% load bootstrap3 %}
|
||||||
|
|
||||||
{% block title %}Recherche{% endblock %}
|
{% block title %}Recherche{% endblock %}
|
||||||
|
@ -11,4 +11,9 @@
|
||||||
{% bootstrap_form searchform %}
|
{% bootstrap_form searchform %}
|
||||||
{% bootstrap_button "Search" button_type="submit" icon="search" %}
|
{% bootstrap_button "Search" button_type="submit" icon="search" %}
|
||||||
</form>
|
</form>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
<p><a href="{% url "users:new-user" %}">Créer un adhérent</a></p>
|
<p><a href="{% url "search:search" %}">Recherche simple</a></p>
|
||||||
<p><a href="{% url "search:search" %}">Editer un adhérent</a></p>
|
<p><a href="{% url "search:searchp" %}">Recherche avancée</a></p>
|
||||||
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
|
|
||||||
<p><a href="{% url "users:add-right" %}">Ajouter un droit rezo</a></p>
|
|
||||||
<p><a href="{% url "users:del-right" %}">Retirer un droit rezo</a></p>
|
|
||||||
<p><a href="{% url "search:search" %}">Ajouter un bannissement</a></p>
|
|
||||||
<p><a href="{% url "search:search" %}">Gérer les bannissements</a></p>
|
|
||||||
<p><a href="{% url "search:search" %}">Créer une facture</a></p>
|
|
||||||
<p><a href="{% url "search:search" %}">Editer une facture</a></p>
|
|
||||||
<p><a href="{% url "cotisations:index" %}">Liste des factures</a></p>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,4 +4,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'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,10 +7,10 @@ from django.core.context_processors import csrf
|
||||||
from django.template import Context, RequestContext, loader
|
from django.template import Context, RequestContext, loader
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from users.models import User, Ban
|
from users.models import User, Ban, Whitelist
|
||||||
from machines.models import Machine, Interface
|
from machines.models import Machine, Interface
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from search.models import SearchForm
|
from search.models import SearchForm, SearchFormPlus
|
||||||
from users.views import has_access
|
from users.views import has_access
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
|
@ -18,25 +18,72 @@ def form(ctx, template, request):
|
||||||
c.update(csrf(request))
|
c.update(csrf(request))
|
||||||
return render_to_response(template, c, context_instance=RequestContext(request))
|
return render_to_response(template, c, context_instance=RequestContext(request))
|
||||||
|
|
||||||
def search(request):
|
def search_result(search, type):
|
||||||
if request.method == 'POST':
|
date_deb = None
|
||||||
search = SearchForm(request.POST or None)
|
date_fin = None
|
||||||
if search.is_valid():
|
states=[]
|
||||||
|
co=[]
|
||||||
|
aff=[0,1,2,3,4]
|
||||||
|
if(type):
|
||||||
|
aff = search.cleaned_data['affichage']
|
||||||
|
co = search.cleaned_data['connexion']
|
||||||
states = search.cleaned_data['filtre']
|
states = search.cleaned_data['filtre']
|
||||||
|
date_deb = search.cleaned_data['date_deb']
|
||||||
|
date_fin = search.cleaned_data['date_fin']
|
||||||
|
date_query = Q()
|
||||||
|
if aff==[]:
|
||||||
|
aff = [0,1,2,3,4]
|
||||||
|
if date_deb != None:
|
||||||
|
date_query = date_query & Q(date__gte=date_deb)
|
||||||
|
if date_fin != None:
|
||||||
|
date_query = date_query & Q(date__lte=date_fin)
|
||||||
search = search.cleaned_data['search_field']
|
search = search.cleaned_data['search_field']
|
||||||
query = Q()
|
query = Q()
|
||||||
for s in states:
|
for s in states:
|
||||||
query = query | Q(state = s)
|
query = query | Q(state = s)
|
||||||
|
|
||||||
|
users = None
|
||||||
|
machines = None
|
||||||
|
factures = None
|
||||||
|
bans = None
|
||||||
|
whitelists = None
|
||||||
|
connexion = []
|
||||||
|
|
||||||
|
for i in aff:
|
||||||
|
if i == '0':
|
||||||
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
|
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)
|
||||||
connexion = []
|
connexion = []
|
||||||
for user in users:
|
for user in users:
|
||||||
connexion.append([user, has_access(user)])
|
access=has_access(user)
|
||||||
|
if(len(co)==0 or (len(co)==1 and bool(co[0])==access) or (len(co)==2 and (bool(co[0])==access or bool(co[1])==access))):
|
||||||
|
connexion.append([user, access])
|
||||||
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
||||||
|
if i == '1':
|
||||||
machines = Interface.objects.filter(machine=Machine.objects.filter(query)) | Interface.objects.filter(Q(dns__icontains = search))
|
machines = Interface.objects.filter(machine=Machine.objects.filter(query)) | Interface.objects.filter(Q(dns__icontains = search))
|
||||||
factures = Facture.objects.filter(query)
|
if i == '2':
|
||||||
|
factures = Facture.objects.filter(query & date_query)
|
||||||
|
if i == '3':
|
||||||
bans = Ban.objects.filter(query)
|
bans = Ban.objects.filter(query)
|
||||||
return form({'users_list': connexion, 'machine_list' : machines, 'facture_list' : factures, 'ban_list' : bans}, 'search/index.html',request)
|
if i == '4':
|
||||||
|
whitelists = Whitelist.objects.filter(query)
|
||||||
|
return {'users_list': connexion, 'machine_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists}
|
||||||
|
|
||||||
|
def search(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
search = SearchForm(request.POST or None)
|
||||||
|
if search.is_valid():
|
||||||
|
return form(search_result(search, False), 'search/index.html',request)
|
||||||
return form({'searchform' : search}, 'search/search.html', request)
|
return form({'searchform' : search}, 'search/search.html', request)
|
||||||
else:
|
else:
|
||||||
search = SearchForm(request.POST or None)
|
search = SearchForm(request.POST or None)
|
||||||
return form({'searchform': search}, 'search/search.html',request)
|
return form({'searchform': search}, 'search/search.html',request)
|
||||||
|
|
||||||
|
def searchp(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
search = SearchFormPlus(request.POST or None)
|
||||||
|
if search.is_valid():
|
||||||
|
return form(search_result(search, True), 'search/index.html',request)
|
||||||
|
return form({'searchform' : search}, 'search/search.html', request)
|
||||||
|
else:
|
||||||
|
search = SearchFormPlus(request.POST or None)
|
||||||
|
return form({'searchform': search}, 'search/search.html',request)
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term">
|
<input type="text" class="form-control" placeholder="Search" name="search_field" id="search-term">
|
||||||
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue