From 15221db62fd31fd71eeeb3159d8dbc198b9f3d1d Mon Sep 17 00:00:00 2001 From: Med Date: Mon, 3 Jul 2017 20:59:50 +0200 Subject: [PATCH] Fonction de recherche --- search/forms.py | 1 + search/templates/search/index.html | 6 +++++- search/views.py | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/search/forms.py b/search/forms.py index aa79180..18f8ffe 100644 --- a/search/forms.py +++ b/search/forms.py @@ -35,6 +35,7 @@ CHOICES2 = ( ('0', 'Utilisateurs'), ('1', 'Media'), ('2', 'Emprunts'), + ('3', 'Jeu'), ) diff --git a/search/templates/search/index.html b/search/templates/search/index.html index 5433210..74c4479 100644 --- a/search/templates/search/index.html +++ b/search/templates/search/index.html @@ -40,7 +40,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,

Résultats dans les media :

{% 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 %} +

Résultats dans les jeux :

+ {% 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 %}

Aucun résultat

{% endif %}
(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)
diff --git a/search/views.py b/search/views.py index 7ae64ec..d73bf9d 100644 --- a/search/views.py +++ b/search/views.py @@ -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: