From 8e860d4f016b2cc05ce49c4f81bbe59a7bceda7a Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 27 Jan 2022 23:39:07 +0700 Subject: [PATCH] fix last page error for more than 10k results, #156 --- tubearchivist/home/src/index/generic.py | 6 ++++++ tubearchivist/home/templates/home/base.html | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tubearchivist/home/src/index/generic.py b/tubearchivist/home/src/index/generic.py index af96abf..054a882 100644 --- a/tubearchivist/home/src/index/generic.py +++ b/tubearchivist/home/src/index/generic.py @@ -122,6 +122,7 @@ class Pagination: "page_from": page_from, "prev_pages": prev_pages, "current_page": page_get, + "max_hits": False, } if self.search_get: pagination.update({"search_get": self.search_get}) @@ -131,6 +132,11 @@ class Pagination: """validate pagination with total_hits after making api call""" page_get = self.page_get max_pages = math.ceil(total_hits / self.page_size) + if total_hits > 10000: + # es returns maximal 10000 results + self.pagination["max_hits"] = True + max_pages = max_pages - 1 + if page_get < max_pages and max_pages > 1: self.pagination["last_page"] = max_pages else: diff --git a/tubearchivist/home/templates/home/base.html b/tubearchivist/home/templates/home/base.html index 3bd4899..da47e17 100644 --- a/tubearchivist/home/templates/home/base.html +++ b/tubearchivist/home/templates/home/base.html @@ -109,9 +109,21 @@ {% endif %} {% if pagination.last_page > 0 %} {% if pagination.search_get %} - Last ({{ pagination.last_page }}) + + {% if pagination.max_hits %} + Max ({{ pagination.last_page }}) + {% else %} + Last ({{ pagination.last_page }}) + {% endif %} + {% else %} - Last ({{ pagination.last_page }}) + + {% if pagination.max_hits %} + Max ({{ pagination.last_page }}) + {% else %} + Last ({{ pagination.last_page }}) + {% endif %} + {% endif %} {% endif %} {% endif %}