Fonction de recherche
This commit is contained in:
parent
0738b143b7
commit
15221db62f
|
@ -35,6 +35,7 @@ CHOICES2 = (
|
||||||
('0', 'Utilisateurs'),
|
('0', 'Utilisateurs'),
|
||||||
('1', 'Media'),
|
('1', 'Media'),
|
||||||
('2', 'Emprunts'),
|
('2', 'Emprunts'),
|
||||||
|
('3', 'Jeu'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<h2>Résultats dans les media : </h2>
|
<h2>Résultats dans les media : </h2>
|
||||||
{% include "media/aff_medias.html" with medias_list=medias_list %}
|
{% include "media/aff_medias.html" with medias_list=medias_list %}
|
||||||
{% endif %}
|
{% 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>
|
<h3>Aucun résultat</h3>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h6>(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)</h6>
|
<h6>(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)</h6>
|
||||||
|
|
|
@ -35,7 +35,7 @@ from search.forms import SearchForm, SearchFormPlus
|
||||||
|
|
||||||
from med.settings import SEARCH_DISPLAY_PAGE
|
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):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
c = ctx
|
||||||
|
@ -54,7 +54,7 @@ def search_result(search, type, request):
|
||||||
date_fin = search.cleaned_data['date_fin']
|
date_fin = search.cleaned_data['date_fin']
|
||||||
date_query = Q()
|
date_query = Q()
|
||||||
if aff==[]:
|
if aff==[]:
|
||||||
aff = ['0','1','2']
|
aff = ['0','1','2','3']
|
||||||
if date_deb != None:
|
if date_deb != None:
|
||||||
date_query = date_query & Q(date_emprunt__gte=date_deb)
|
date_query = date_query & Q(date_emprunt__gte=date_deb)
|
||||||
if date_fin != None:
|
if date_fin != None:
|
||||||
|
@ -66,7 +66,7 @@ def search_result(search, type, request):
|
||||||
|
|
||||||
connexion = []
|
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',)):
|
if request.user.has_perms(('perm',)):
|
||||||
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)
|
||||||
|
@ -85,6 +85,9 @@ def search_result(search, type, request):
|
||||||
recherche['emprunts_list'] = Emprunt.objects.filter(query & date_query).order_by('date_emprunt').reverse()
|
recherche['emprunts_list'] = Emprunt.objects.filter(query & date_query).order_by('date_emprunt').reverse()
|
||||||
if i == '2':
|
if i == '2':
|
||||||
recherche['medias_list'] = Media.objects.filter(Q(auteur__nom__icontains = search) | Q(titre__icontains = search))
|
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:
|
for r in recherche:
|
||||||
if recherche[r] != None:
|
if recherche[r] != None:
|
||||||
|
|
Loading…
Reference in New Issue