From f9256b70dbf735bebb0dc19a0db7fbbd5e6679ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Tue, 1 Jul 2025 19:02:47 +0300 Subject: [PATCH] fix pager --- app/routes/threads.py | 2 +- app/templates/common/macros.html | 8 ++++---- app/templates/topics/topic.html | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/routes/threads.py b/app/routes/threads.py index 0b39aef..06f0fe8 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -31,7 +31,7 @@ def thread(slug): ("id", "<=", after_id), ]) print(post_position) - page = math.floor((post_position + 1) / POSTS_PER_PAGE) + 1 + page = math.ceil((post_position) / POSTS_PER_PAGE) else: page = max(1, min(page_count, int(request.args.get("page", default = 1)))) diff --git a/app/templates/common/macros.html b/app/templates/common/macros.html index cb859ea..50b7d3f 100644 --- a/app/templates/common/macros.html +++ b/app/templates/common/macros.html @@ -1,6 +1,6 @@ {% macro pager(current_page, page_count) %} -{% set left_start = (1, current_page - 5) | max %} -{% set right_end = (page_count, current_page + 5) | min %} +{% set left_start = [1, current_page - 5] | max %} +{% set right_end = [page_count, current_page + 5] | min %}
Page: {% if current_page > 5 %} @@ -9,13 +9,13 @@ {% endif %} {% endif %} - {% for i in range(left_start, current_page - 1) %} + {% for i in range(left_start, current_page) %} {{i}} {% endfor %} {% if page_count > 0 %} {{current_page}} {% endif %} - {% for i in range(current_page + 1, right_end) %} + {% for i in range(current_page + 1, right_end + 1) %} {{i}} {% endfor %} {% if right_end < page_count %} diff --git a/app/templates/topics/topic.html b/app/templates/topics/topic.html index 7887a85..a312c79 100644 --- a/app/templates/topics/topic.html +++ b/app/templates/topics/topic.html @@ -45,7 +45,7 @@ Latest post by {{ thread['latest_post_username'] }} - on on {{ timestamp(thread['latest_post_created_at'] )}}: + on on {{ timestamp(thread['latest_post_created_at']) }}: {{ thread['latest_post_content'] | safe }}