summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-08-19 02:13:36 +0000
committerubq323 <ubq323>2021-08-19 02:13:36 +0000
commitaf27d6578a0dd75229f89b9c64992aec0cd19b4c (patch)
treeeff4fc5e1dd1767a78ef008c373b045a898bf2b5
parentd2e51e7b8bb2f765e79c98f13165b0faf59a302c (diff)
navbar
-rw-r--r--apioforum/templates/view_thread.html11
-rw-r--r--apioforum/thread.py6
2 files changed, 17 insertions, 0 deletions
diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html
index 132fd44..11d21e4 100644
--- a/apioforum/templates/view_thread.html
+++ b/apioforum/templates/view_thread.html
@@ -69,6 +69,17 @@
{% endif %}
{% endfor %}
</div>
+<nav aria-label="pagination" id="pages">
+ {% if page > 1 %}
+ <a href="{{url_for('thread.view_thread',thread_id=thread.id)}}" aria-label="first page">&lt;&lt;</a>
+ <a href="{{url_for('thread.view_thread',thread_id=thread.id,page=page-1)}}" aria-label="previous page">&lt;</a>
+ {% endif %}
+ page {{page}} of {{max_pageno}}
+ {% if page < max_pageno %} {# > #}
+ <a href="{{url_for('thread.view_thread',thread_id=thread.id,page=page+1)}}" aria-label="next page">&gt;</a>
+ <a href="{{url_for('thread.view_thread',thread_id=thread.id,page=max_pageno)}}" aria-label="last page">&gt;&gt;</a>
+ {% endif %}
+</nav>
{% if g.user and has_permission(thread.forum, g.user, "p_reply_threads") %}
<form class="new-post" action="{{url_for('thread.create_post',thread_id=thread.id)}}" method="POST">
<textarea class="new-post-box" placeholder="your post here..." name="content"></textarea>
diff --git a/apioforum/thread.py b/apioforum/thread.py
index b281d0a..0b12141 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -55,6 +55,10 @@ def view_thread(thread_id,page=1):
POSTS_PER_PAGE,
(page-1)*POSTS_PER_PAGE,
)).fetchall()
+
+ num_posts = db.execute("SELECT count(*) as count FROM posts WHERE posts.thread = ?",(thread_id,)).fetchone()['count']
+ max_pageno = math.ceil(num_posts/POSTS_PER_PAGE)
+
tags = db.execute(
"""SELECT tags.* FROM tags
INNER JOIN thread_tags ON thread_tags.tag = tags.id
@@ -99,6 +103,8 @@ def view_thread(thread_id,page=1):
poll=poll,
votes=votes,
has_voted=has_voted,
+ page=page,
+ max_pageno=max_pageno,
)
def register_vote(thread,pollval):