Skip to content

Commit

Permalink
Merge pull request #1290 from nationalarchives/fix/date-bugs
Browse files Browse the repository at this point in the history
Fix bugs with minimum date: total was a string and logic was inverted
  • Loading branch information
dragon-dxw authored Jun 28, 2024
2 parents 84116f8 + e0715d3 commit b5dcafe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions judgments/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions judgments/views/advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
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.
"""
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},
Expand Down Expand Up @@ -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 | {
Expand All @@ -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,
Expand Down

0 comments on commit b5dcafe

Please sign in to comment.