From 32a04c5aea0e4f1ee84dc48f6df29c05168850be Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Wed, 10 Jan 2024 18:41:38 +0000 Subject: [PATCH] Add more search results scenarios --- app/__init__.py | 2 ++ app/lib/pagination.py | 2 ++ app/lib/template_filters.py | 4 ++++ app/templates/search/catalogue.html | 18 ++++++++++++++++-- app/templates/search/elements/sort-view.html | 4 ++-- app/templates/search/website.html | 11 ++++++++++- 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index d9261147..7f3769d5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -14,6 +14,7 @@ brand_icon_from_url, headings_list, pretty_date, + pretty_number, slugify, tna_html, ) @@ -44,6 +45,7 @@ def create_app(config_class=Config): app.add_template_filter(tna_html) app.add_template_filter(slugify) app.add_template_filter(pretty_date) + app.add_template_filter(pretty_number) app.add_template_filter(article_supertitle) app.add_template_filter(article_type) app.add_template_filter(brand_icon_from_url) diff --git a/app/lib/pagination.py b/app/lib/pagination.py index ee5ebf8f..9616cb0e 100644 --- a/app/lib/pagination.py +++ b/app/lib/pagination.py @@ -62,6 +62,8 @@ def generate_new_page_query_string(args, page): def pagination_object( current_page, total_pages, current_args, boundaries=1, around=1 ): + if total_pages == 0: + return {} current_page = int(current_page) pagination_object = {} pagination_object["items"] = [ diff --git a/app/lib/template_filters.py b/app/lib/template_filters.py index 8f63d941..0d5668db 100644 --- a/app/lib/template_filters.py +++ b/app/lib/template_filters.py @@ -22,6 +22,10 @@ def pretty_date(s): return new_date +def pretty_number(s): + return f"{s:,}" + + def article_supertitle(s): if s == "articles.ArticlePage": return "The story of" diff --git a/app/templates/search/catalogue.html b/app/templates/search/catalogue.html index ab3c05ab..0d32fb39 100644 --- a/app/templates/search/catalogue.html +++ b/app/templates/search/catalogue.html @@ -9,7 +9,7 @@ {%- from 'macros/feedback.html' import feedback -%} {%- from 'search/elements/sort-view.html' import sortView -%} -{% block pageTitle %}Search our catalogue - {{ super() }}{% endblock %} +{% block pageTitle %}{% if results %}{{ results.count }} results - {% endif %}{{ super() }}{% endblock %} {% block skipLink %} {{ tnaSkipLink({ @@ -22,12 +22,13 @@ {% block content %} {% set show_tabs = True %} {% include 'search/elements/header.html' %} +{% if results.count %}

Catalogue results for records held at The National Archives that match your search term.

{% include 'search/elements/buckets.html' %}
- {{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our website') }} + {{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our records') }}
@@ -327,6 +328,19 @@

{% endif %}

+{% else %} +
+
+

We did not find any results for your search

+

Some record descriptions are much less detailed than others, so you may not find what you are looking for using a simple keyword search.

+
    +
  • Try different spellings or search terms
  • +
  • Use the advanced search options such as the "AND", "OR" and "NOT" operators
  • +
  • Look at our research guides for search tips
  • +
+
+
+{% endif %} {{ feedback() }} {% endblock %} diff --git a/app/templates/search/elements/sort-view.html b/app/templates/search/elements/sort-view.html index 0114e54a..bc5b4d7f 100644 --- a/app/templates/search/elements/sort-view.html +++ b/app/templates/search/elements/sort-view.html @@ -4,9 +4,9 @@ {% macro sortView(query, results_count, result_range_min, result_range_max, bucket_name) %}
{% if query %} -

Showing {{ result_range_min }}–{{ result_range_max }} of {{ results_count }} results for "{{ query or '' }}" in {{ bucket_name }}

+

Showing {{ result_range_min }}–{{ result_range_max }} of {{ results_count | pretty_number }} results for "{{ query or '' }}" in {{ bucket_name }}

{% else %} -

Showing {{ result_range_min }}–{{ result_range_max }} of {{ results_count }} results in {{ bucket_name }}

+

Showing {{ result_range_min }}–{{ result_range_max }} of {{ results_count | pretty_number }} results in {{ bucket_name }}

{% endif %}
diff --git a/app/templates/search/website.html b/app/templates/search/website.html index 65e92e6c..4cc10ff2 100644 --- a/app/templates/search/website.html +++ b/app/templates/search/website.html @@ -8,11 +8,12 @@ {%- from 'macros/feedback.html' import feedback -%} {%- from 'search/elements/sort-view.html' import sortView -%} -{% block pageTitle %}Search our website - {{ super() }}{% endblock %} +{% block pageTitle %}{% if results %}{{ results.count }} results - {% endif %}{{ super() }}{% endblock %} {% block content %} {% set show_tabs = True %} {% include 'search/elements/header.html' %} +{% if results.count %}
{{ sortView(query, results.count, results.result_range_min, results.result_range_max, 'our website') }} {% set selected_filters = [] %} @@ -146,6 +147,14 @@

{% endif %}

+{% else %} +
+
+

We did not find any results for your search

+

Try again with different spellings or search terms or view all website results.

+
+
+{% endif %} {{ feedback() }} {% endblock %}