1
0
mirror of https://github.com/ae-utbm/sith.git synced 2025-04-03 18:30:26 +00:00

Merge branch 'search' into 'master'

core: fix error 500 on user and forum search

See merge request 
This commit is contained in:
Antoine Bartuccio 2019-05-10 11:06:13 +02:00
commit 827ec63ab3
2 changed files with 13 additions and 8 deletions
core/views
forum

@ -26,6 +26,7 @@ from django.shortcuts import render, redirect
from django.http import JsonResponse from django.http import JsonResponse
from django.core import serializers from django.core import serializers
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.utils import html
from django.views.generic import ListView, TemplateView from django.views.generic import ListView, TemplateView
from django.conf import settings from django.conf import settings
@ -71,10 +72,11 @@ def notification(request, notif_id):
def search_user(query, as_json=False): def search_user(query, as_json=False):
if query == "": try:
res = SearchQuerySet().models(User).autocomplete(auto=html.escape(query))[:20]
return [r.object for r in res]
except TypeError:
return [] return []
res = SearchQuerySet().models(User).autocomplete(auto=query)[:20]
return [r.object for r in res]
def search_club(query, as_json=False): def search_club(query, as_json=False):

@ -29,7 +29,7 @@ from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.utils import timezone from django.utils import timezone, html
from django.conf import settings from django.conf import settings
from django import forms from django import forms
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -56,11 +56,15 @@ class ForumSearchView(ListView):
query = self.request.GET.get("query", "") query = self.request.GET.get("query", "")
order_by = self.request.GET.get("order", "") order_by = self.request.GET.get("order", "")
if query == "": try:
queryset = (
RelatedSearchQuerySet()
.models(ForumMessage)
.autocomplete(auto=html.escape(query))
)
except TypeError:
return [] return []
queryset = RelatedSearchQuerySet().models(ForumMessage).autocomplete(auto=query)
if order_by == "date": if order_by == "date":
queryset = queryset.order_by("-date") queryset = queryset.order_by("-date")
@ -85,7 +89,6 @@ class ForumSearchView(ListView):
): ):
resp.append(r.object) resp.append(r.object)
count += 1 count += 1
return resp return resp