From e0715d3b9c670e88aa444631bbeb18a3a6526c82 Mon Sep 17 00:00:00 2001 From: Dragon Dave McKee Date: Fri, 28 Jun 2024 15:34:03 +0100 Subject: [PATCH] Fix bugs with minimum date: total was a string and logic was inverted --- judgments/tests/test_search.py | 1 + judgments/views/advanced_search.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/judgments/tests/test_search.py b/judgments/tests/test_search.py index 93c4eb308..33d57056f 100644 --- a/judgments/tests/test_search.py +++ b/judgments/tests/test_search.py @@ -134,6 +134,7 @@ def test_judgment_advanced_search_warns_user_with_date_before_minimum_warning_ye GIVEN a client for making HTTP requests WHEN a GET request is made to "/judgments/search?query=waltham+forest" AND the from_date is before `settings.MINIMUM_WARNING_YEAR` + AND there's no search results THEN the response should contain the expected warning The expected applied filters HTML: diff --git a/judgments/views/advanced_search.py b/judgments/views/advanced_search.py index f6a4015f2..edd48a580 100644 --- a/judgments/views/advanced_search.py +++ b/judgments/views/advanced_search.py @@ -29,7 +29,7 @@ from judgments.utils.utils import sanitise_input_to_integer -def _do_dates_require_warnings(from_date, total_results): +def _do_dates_require_warnings(from_date: date, total_results: int): """ Check if users have requested a year before what we technically handle, if it is, then we provide a warning letting them know. @@ -37,7 +37,7 @@ def _do_dates_require_warnings(from_date, total_results): from_warning = False warning = None if from_date: - if from_date.year < settings.MINIMUM_WARNING_YEAR or total_results < 1: + if from_date.year < settings.MINIMUM_WARNING_YEAR and total_results > 0: from_warning = True warning = f""" {from_date.year} is before {settings.MINIMUM_WARNING_YEAR}, @@ -173,7 +173,7 @@ def advanced_search(request): if value is not None and not key == "page" } requires_warning, warning = _do_dates_require_warnings( - from_date, search_response.total + from_date, int(search_response.total) ) # Populate context to provide feedback about filters etc. back to user context = context | { @@ -185,7 +185,7 @@ def advanced_search(request): "tribunal_facets": tribunal_facets, "year_facets": year_facets, "search_results": search_response.results, - "total": search_response.total, + "total": int(search_response.total), "paginator": paginator(page, search_response.total, per_page), "query_string": urllib.parse.urlencode(changed_queries, doseq=True), "order": order,