Skip to content

Commit

Permalink
[#3017] Review corrections + add search pagination config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jiromaykin committed Feb 18, 2025
1 parent 9eedab5 commit 4f3bab8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/open_inwoner/search/tests/test_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.test import override_settings, tag
from django.urls import reverse_lazy

Expand Down Expand Up @@ -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()

Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/open_inwoner/search/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="utrecht-heading-2">{% trans "Zoekfilters" %}</h2>
<div class="search-results__list">
{% render_grid %}
{% for hit in page_obj %}
<div class="column column--start-0 {% if search_filter_categories or search_filter_tags or search_filter_organizations %}column--span-12{% else %}column--span-8{% endif %}">
<div class="column column--start-0 column--span-{% if search_filter_categories or search_filter_tags or search_filter_organizations %}12{% else %}8{% endif %}">
<a href="{% url 'products:product_detail' hit.slug %}" class="card card__description-card search-results__item">
<div class="card__body card__body--tabled">
<h3 class="utrecht-heading-3 search-results__item-title">{{ hit.name }}</h3>
Expand Down

0 comments on commit 4f3bab8

Please sign in to comment.