1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-24 17:42:23 +00:00

Fonction de recherche

This commit is contained in:
Med 2017-07-03 20:59:50 +02:00
parent 0738b143b7
commit 15221db62f
3 changed files with 12 additions and 4 deletions

View File

@ -35,6 +35,7 @@ CHOICES2 = (
('0', 'Utilisateurs'),
('1', 'Media'),
('2', 'Emprunts'),
('3', 'Jeu'),
)

View File

@ -40,7 +40,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h2>Résultats dans les media : </h2>
{% include "media/aff_medias.html" with medias_list=medias_list %}
{% endif %}
{% if not users_list and not emprunts_list and not medias_list %}
{% if jeux_list %}
<h2>Résultats dans les jeux : </h2>
{% include "media/aff_jeux.html" with jeux_list=jeux_list %}
{% endif %}
{% if not users_list and not emprunts_list and not medias_list and not jeux_list %}
<h3>Aucun résultat</h3>
{% endif %}
<h6>(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)</h6>

View File

@ -35,7 +35,7 @@ from search.forms import SearchForm, SearchFormPlus
from med.settings import SEARCH_DISPLAY_PAGE
from media.models import Media, Emprunt
from media.models import Media, Jeu, Emprunt
def form(ctx, template, request):
c = ctx
@ -54,7 +54,7 @@ def search_result(search, type, request):
date_fin = search.cleaned_data['date_fin']
date_query = Q()
if aff==[]:
aff = ['0','1','2']
aff = ['0','1','2','3']
if date_deb != None:
date_query = date_query & Q(date_emprunt__gte=date_deb)
if date_fin != None:
@ -66,7 +66,7 @@ def search_result(search, type, request):
connexion = []
recherche = {'users_list': None, 'emprunts_list' : None, 'medias_list' : None}
recherche = {'users_list': None, 'emprunts_list' : None, 'medias_list' : None, 'jeux_list': None}
if request.user.has_perms(('perm',)):
query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)
@ -85,6 +85,9 @@ def search_result(search, type, request):
recherche['emprunts_list'] = Emprunt.objects.filter(query & date_query).order_by('date_emprunt').reverse()
if i == '2':
recherche['medias_list'] = Media.objects.filter(Q(auteur__nom__icontains = search) | Q(titre__icontains = search))
if i == '3':
recherche['jeux_list'] = Jeu.objects.filter(Q(nom__icontains = search) | Q(proprietaire__pseudo__icontains = search) | Q(proprietaire__name__icontains = search) | Q(proprietaire__surname__icontains = search))
for r in recherche:
if recherche[r] != None: