Commit d0f2140d authored by erdnaxe's avatar erdnaxe 🎇

Format search code

parent c225f504
Pipeline #1399 failed with stage
in 3 minutes and 20 seconds
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment