Commit 347caa3b authored by Sli's avatar Sli Committed by Skia

forum and core: fix error 500 when query is empty on search

parent 65a0b7b2
...@@ -71,6 +71,8 @@ def notification(request, notif_id): ...@@ -71,6 +71,8 @@ def notification(request, notif_id):
def search_user(query, as_json=False): def search_user(query, as_json=False):
if query == "":
return []
res = SearchQuerySet().models(User).autocomplete(auto=query)[:20] res = SearchQuerySet().models(User).autocomplete(auto=query)[:20]
return [r.object for r in res] return [r.object for r in res]
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
{% block content %} {% block content %}
<div id="forum"> <div id="forum">
{{ display_search_bar() }}
{% if object_list|length != 0 %} {% if object_list|length != 0 %}
<br> <br>
{{ display_search_bar() }}
<div class="search-results"> <div class="search-results">
{% for m in object_list %} {% for m in object_list %}
{{ display_message(m, user) }} {{ display_message(m, user) }}
......
...@@ -54,6 +54,8 @@ class ForumSearchView(ListView): ...@@ -54,6 +54,8 @@ class ForumSearchView(ListView):
def get_queryset(self): def get_queryset(self):
query = self.request.GET.get("query", "") query = self.request.GET.get("query", "")
if query == "":
return []
queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)[:100] queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)[:100]
return [ return [
r.object for r in queryset if can_view(r.object.topic, self.request.user) r.object for r in queryset if can_view(r.object.topic, self.request.user)
......
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