From 347caa3b6ab6915c2fdd940918168ef72f50e2e5 Mon Sep 17 00:00:00 2001 From: Bartuccio Antoine Date: Fri, 7 Dec 2018 13:34:46 +0100 Subject: [PATCH] forum and core: fix error 500 when query is empty on search --- core/views/site.py | 2 ++ forum/templates/forum/search.jinja | 2 +- forum/views.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/views/site.py b/core/views/site.py index 8eedcf67..3b75cdde 100644 --- a/core/views/site.py +++ b/core/views/site.py @@ -71,6 +71,8 @@ def notification(request, notif_id): def search_user(query, as_json=False): + if query == "": + return [] res = SearchQuerySet().models(User).autocomplete(auto=query)[:20] return [r.object for r in res] diff --git a/forum/templates/forum/search.jinja b/forum/templates/forum/search.jinja index 4d15714a..fed3803e 100644 --- a/forum/templates/forum/search.jinja +++ b/forum/templates/forum/search.jinja @@ -4,9 +4,9 @@ {% block content %}
+ {{ display_search_bar() }} {% if object_list|length != 0 %}
- {{ display_search_bar() }}
{% for m in object_list %} {{ display_message(m, user) }} diff --git a/forum/views.py b/forum/views.py index 56245752..32dab177 100644 --- a/forum/views.py +++ b/forum/views.py @@ -54,6 +54,8 @@ class ForumSearchView(ListView): def get_queryset(self): query = self.request.GET.get("query", "") + if query == "": + return [] queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)[:100] return [ r.object for r in queryset if can_view(r.object.topic, self.request.user)