fix last page error for more than 10k results, #156

This commit is contained in:
simon 2022-01-27 23:39:07 +07:00
parent 0749202d5d
commit 8e860d4f01
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 20 additions and 2 deletions

View File

@ -122,6 +122,7 @@ class Pagination:
"page_from": page_from, "page_from": page_from,
"prev_pages": prev_pages, "prev_pages": prev_pages,
"current_page": page_get, "current_page": page_get,
"max_hits": False,
} }
if self.search_get: if self.search_get:
pagination.update({"search_get": 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""" """validate pagination with total_hits after making api call"""
page_get = self.page_get page_get = self.page_get
max_pages = math.ceil(total_hits / self.page_size) 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: if page_get < max_pages and max_pages > 1:
self.pagination["last_page"] = max_pages self.pagination["last_page"] = max_pages
else: else:

View File

@ -109,9 +109,21 @@
{% endif %} {% endif %}
{% if pagination.last_page > 0 %} {% if pagination.last_page > 0 %}
{% if pagination.search_get %} {% if pagination.search_get %}
<a class="pagination-item" href="?page={{ pagination.last_page }}&search={{ pagination.search_get }}">Last ({{ pagination.last_page }})</a> <a class="pagination-item" href="?page={{ pagination.last_page }}&search={{ pagination.search_get }}">
{% if pagination.max_hits %}
Max ({{ pagination.last_page }})
{% else %} {% else %}
<a class="pagination-item" href="?page={{ pagination.last_page }}">Last ({{ pagination.last_page }})</a> Last ({{ pagination.last_page }})
{% endif %}
</a>
{% else %}
<a class="pagination-item" href="?page={{ pagination.last_page }}">
{% if pagination.max_hits %}
Max ({{ pagination.last_page }})
{% else %}
Last ({{ pagination.last_page }})
{% endif %}
</a>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}