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

Format search code

This commit is contained in:
Alexandre Iooss 2019-08-08 21:54:36 +02:00
parent c225f5045e
commit d0f2140d14
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02

View File

@ -37,33 +37,42 @@ def search_result(search, type, request):
search = search.cleaned_data['search_field']
query1 = Q()
recherche = {'users_list': None, 'emprunts_list': None, 'medias_list': None, 'jeux_list': None}
recherche = {'users_list': None, 'emprunts_list': None, 'medias_list': None,
'jeux_list': None}
if request.user.has_perms(('perm',)):
query = Q(user__username__icontains=search) | Q(user__first_name__icontains=search) | Q(
query = Q(user__username__icontains=search) | Q(
user__first_name__icontains=search) | Q(
user__last_name__icontains=search)
else:
query = (Q(user__username__icontains=search) | Q(user__first_name__icontains=search) | Q(
query = (Q(user__username__icontains=search) | Q(
user__first_name__icontains=search) | Q(
user__last_name__icontains=search)) & Q(user=request.user)
for i in aff:
if i == '0':
query_user_list = Q(username__icontains=search) | Q(first_name__icontains=search) | Q(
query_user_list = Q(username__icontains=search) | Q(
first_name__icontains=search) | Q(
last_name__icontains=search) & query1
if request.user.has_perms(('perm',)):
recherche['users_list'] = User.objects.filter(query_user_list).order_by('last_name')
recherche['users_list'] = User.objects.filter(
query_user_list).order_by('last_name')
else:
recherche['users_list'] = User.objects.filter(query_user_list & Q(id=request.user.id)).order_by(
recherche['users_list'] = User.objects.filter(
query_user_list & Q(id=request.user.id)).order_by(
'last_name')
if i == '1':
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':
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__username__icontains=search) | Q(
proprietaire__first_name__icontains=search) | Q(proprietaire__last_name__icontains=search))
Q(nom__icontains=search) | Q(
proprietaire__username__icontains=search) | Q(
proprietaire__first_name__icontains=search) | Q(
proprietaire__last_name__icontains=search))
for r in recherche:
if recherche[r] is not None:
@ -78,7 +87,8 @@ def search_result(search, type, request):
def search(request):
search = SearchForm(request.POST or None)
if search.is_valid():
return form(search_result(search, False, request), 'search/index.html', request)
return form(search_result(search, False, request), 'search/index.html',
request)
return form({'searchform': search}, 'search/search.html', request)
@ -86,5 +96,6 @@ def search(request):
def searchp(request):
search = SearchFormPlus(request.POST or None)
if search.is_valid():
return form(search_result(search, True, request), 'search/index.html', request)
return form(search_result(search, True, request), 'search/index.html',
request)
return form({'searchform': search}, 'search/search.html', request)