From 2ae2a2c158c94a97e28c81ad8eb6e4a296197a66 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 29 Jul 2022 22:34:48 +0100 Subject: [PATCH] Show message when there's no search terms --- website/search/models.py | 5 ++++- website/search/templates/search/search_page.html | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/website/search/models.py b/website/search/models.py index 5255cbc..406b06d 100644 --- a/website/search/models.py +++ b/website/search/models.py @@ -70,6 +70,9 @@ class SearchPage(BaseContentMixin, BasePage): # type: ignore[misc] context["results"] = results else: - context["invalid_search"] = True + if "q" in request.GET: + context["invalid_search"] = True + else: + context["initial"] = True return context diff --git a/website/search/templates/search/search_page.html b/website/search/templates/search/search_page.html index 44a3fd1..e64576c 100644 --- a/website/search/templates/search/search_page.html +++ b/website/search/templates/search/search_page.html @@ -11,7 +11,9 @@ {% endif %}
- {% if invalid_search %} + {% if initial %} +

Enter search terms

+ {% elif invalid_search %}

Invalid search

{% elif results|length == 0 %} {% if page_num > paginator.num_pages %}