mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Correction de la recherche des machines et filtrage des résultats selon les droits
This commit is contained in:
parent
29936f2a70
commit
3685396c4a
2 changed files with 39 additions and 27 deletions
|
@ -8,9 +8,9 @@
|
||||||
<h2>Résultats dans les utilisateurs</h2>
|
<h2>Résultats dans les utilisateurs</h2>
|
||||||
{% include "users/aff_users.html" with users_list=users_list %}
|
{% include "users/aff_users.html" with users_list=users_list %}
|
||||||
{% endif%}
|
{% endif%}
|
||||||
{% if interfaces_list %}
|
{% if machines_list %}
|
||||||
<h2>Résultats dans les machines : </h2>
|
<h2>Résultats dans les machines : </h2>
|
||||||
{% include "machines/aff_machines.html" with interfaces_list=interfaces_list %}
|
{% include "machines/aff_machines.html" with machines_list=machines_list %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if facture_list %}
|
{% if facture_list %}
|
||||||
<h2>Résultats dans les factures : </h2>
|
<h2>Résultats dans les factures : </h2>
|
||||||
|
@ -40,4 +40,3 @@
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ def form(ctx, template, request):
|
||||||
|
|
||||||
def search_result(search, type, request):
|
def search_result(search, type, request):
|
||||||
date_deb = None
|
date_deb = None
|
||||||
date_fin = None
|
date_fin = None
|
||||||
states=[]
|
states=[]
|
||||||
co=[]
|
co=[]
|
||||||
aff=[]
|
aff=[]
|
||||||
|
@ -41,36 +41,49 @@ def search_result(search, type, request):
|
||||||
if date_fin != None:
|
if date_fin != None:
|
||||||
date_query = date_query & Q(date__lte=date_fin)
|
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
|
|
||||||
switchlist = None
|
|
||||||
portlist = None
|
|
||||||
connexion = []
|
connexion = []
|
||||||
|
|
||||||
|
recherche = {'users_list': None, 'machines_list' : None, 'facture_list' : None, 'ban_list' : None, 'white_list': None, 'port_list': None, 'switch_list': None}
|
||||||
|
|
||||||
|
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
||||||
|
|
||||||
for i in aff:
|
for i in aff:
|
||||||
if i == '0':
|
if i == '0':
|
||||||
users = User.objects.filter((Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search)) & query)[:SEARCH_RESULT]
|
recherche['users_list'] = User.objects.filter(Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search))
|
||||||
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
|
|
||||||
if i == '1':
|
if i == '1':
|
||||||
machines = Machine.objects.filter(query)[:SEARCH_RESULT]
|
recherche['machines_list'] = Machine.objects.filter(query | Q(interface__dns__icontains = search) | Q(interface__mac_address__icontains = search))
|
||||||
if i == '2':
|
if i == '2':
|
||||||
factures = Facture.objects.filter(query & date_query)[:SEARCH_RESULT]
|
recherche['facture_list'] = Facture.objects.filter(query & date_query)
|
||||||
if i == '3':
|
if i == '3':
|
||||||
bans = Ban.objects.filter(query)[:SEARCH_RESULT]
|
recherche['ban_list'] = Ban.objects.filter(query)
|
||||||
if i == '4':
|
if i == '4':
|
||||||
whitelists = Whitelist.objects.filter(query)[:SEARCH_RESULT]
|
recherche['white_list'] = Whitelist.objects.filter(query)
|
||||||
if i == '5':
|
if i == '5':
|
||||||
portlist = Port.objects.filter(details__icontains = search)[:SEARCH_RESULT]
|
recherche['port_list'] = Port.objects.filter(details__icontains = search)
|
||||||
if i == '6':
|
if i == '6':
|
||||||
switchlist = Switch.objects.filter(details__icontains = search)[:SEARCH_RESULT]
|
recherche['switch_list'] = Switch.objects.filter(details__icontains = search)
|
||||||
return {'users_list': users, 'machines_list' : machines, 'facture_list' : factures, 'ban_list' : bans, 'white_list': whitelists, 'port_list':portlist, 'switch_list':switchlist, 'max_result' : SEARCH_RESULT}
|
|
||||||
|
if not request.user.has_perms(('cableur',)):
|
||||||
|
for r in recherche:
|
||||||
|
if r == 'users_list':
|
||||||
|
recherche[r] = recherche[r].filter(id=request.user.id)
|
||||||
|
elif r in ('switch_list','port_list'):
|
||||||
|
recherche[r] = None
|
||||||
|
elif recherche[r]:
|
||||||
|
recherche[r] = recherche[r].filter(user = request.user)
|
||||||
|
|
||||||
|
for r in recherche:
|
||||||
|
if recherche[r] != None:
|
||||||
|
recherche[r] = recherche[r][:SEARCH_RESULT]
|
||||||
|
|
||||||
|
recherche.update({'max_result': SEARCH_RESULT})
|
||||||
|
|
||||||
|
return recherche
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search(request):
|
def search(request):
|
||||||
|
|
Loading…
Reference in a new issue