From 4f3bab81686ac85488c6891b56956bb9b98e9ac3 Mon Sep 17 00:00:00 2001 From: jiroghianni Date: Mon, 17 Feb 2025 17:09:12 +0100 Subject: [PATCH] [#3017] Review corrections + add search pagination config setting --- src/open_inwoner/conf/base.py | 2 ++ .../scss/components/Pagination/Pagination.scss | 2 +- src/open_inwoner/search/tests/test_page.py | 7 +++++-- src/open_inwoner/search/views.py | 3 ++- src/open_inwoner/templates/pages/search.html | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/open_inwoner/conf/base.py b/src/open_inwoner/conf/base.py index 49e664f9ec..a7b8295b26 100644 --- a/src/open_inwoner/conf/base.py +++ b/src/open_inwoner/conf/base.py @@ -891,6 +891,8 @@ ES_MAX_SIZE = 10000 ES_SUGGEST_SIZE = 5 +# Search page pagination trigger +RESULTS_PER_PAGE = config("RESULTS_PER_PAGE", default=9) # django import-export IMPORT_EXPORT_USE_TRANSACTIONS = True diff --git a/src/open_inwoner/scss/components/Pagination/Pagination.scss b/src/open_inwoner/scss/components/Pagination/Pagination.scss index c35ff7915d..481c56b0f2 100644 --- a/src/open_inwoner/scss/components/Pagination/Pagination.scss +++ b/src/open_inwoner/scss/components/Pagination/Pagination.scss @@ -28,7 +28,7 @@ &--active { color: var(--color-white); background-color: var(--color-primary); - border-radius: 100px; + border-radius: var(--border-radius-rounded); &:hover { background-color: var(--color-body); diff --git a/src/open_inwoner/search/tests/test_page.py b/src/open_inwoner/search/tests/test_page.py index ca6d466556..aedd443f45 100644 --- a/src/open_inwoner/search/tests/test_page.py +++ b/src/open_inwoner/search/tests/test_page.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.test import override_settings, tag from django.urls import reverse_lazy @@ -110,7 +111,9 @@ def test_search_with_filter(self): self.assertEqual(results[0].slug, self.product1.slug) def test_pagination_links(self): - products = ProductFactory.create_batch(9, content="content") + products = ProductFactory.create_batch( + settings.RESULTS_PER_PAGE, content="content" + ) self.tag.products.add(*products) self.update_index() @@ -119,7 +122,7 @@ def test_pagination_links(self): self.assertEqual(response.status_code, 200) results = response.context["paginator"].object_list - self.assertEqual(len(results), 10) + self.assertEqual(len(results), settings.RESULTS_PER_PAGE + 1) pagination_div = response.html.find("div", {"class": "pagination"}) pagination_links = pagination_div.find_all("a") diff --git a/src/open_inwoner/search/views.py b/src/open_inwoner/search/views.py index 5d9be640c2..342ce50deb 100644 --- a/src/open_inwoner/search/views.py +++ b/src/open_inwoner/search/views.py @@ -1,5 +1,6 @@ import logging +from django.conf import settings from django.contrib import messages from django.core.paginator import InvalidPage, Paginator from django.http import Http404 @@ -28,7 +29,7 @@ class SearchView( ): form_class = SearchForm template_name = "pages/search.html" - paginate_by = 9 + paginate_by = settings.RESULTS_PER_PAGE paginator_class = Paginator page_kwarg = "page" success_url = reverse_lazy("search:search") diff --git a/src/open_inwoner/templates/pages/search.html b/src/open_inwoner/templates/pages/search.html index 69e4178e89..bd10d12e3e 100644 --- a/src/open_inwoner/templates/pages/search.html +++ b/src/open_inwoner/templates/pages/search.html @@ -36,7 +36,7 @@

{% trans "Zoekfilters" %}

{% render_grid %} {% for hit in page_obj %} -