summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-08-20 01:48:50 +0000
committerubq323 <ubq323>2021-08-20 01:48:50 +0000
commitd7db0af8f7ce9e608180047bbbdc4fe9dd624f50 (patch)
tree69a88b6be664382d5710ab84ca49980807e0a9d7
parentaf27d6578a0dd75229f89b9c64992aec0cd19b4c (diff)
pagination and links and things (probably not complete)
-rw-r--r--apioforum/__init__.py1
-rw-r--r--apioforum/templates/view_forum.html4
-rw-r--r--apioforum/templates/view_post.html2
-rw-r--r--apioforum/thread.py24
4 files changed, 20 insertions, 11 deletions
diff --git a/apioforum/__init__.py b/apioforum/__init__.py
index 087df81..60777fb 100644
--- a/apioforum/__init__.py
+++ b/apioforum/__init__.py
@@ -54,6 +54,7 @@ def create_app():
return dict(path_for_next=p)
app.jinja_env.globals.update(forum_path=forum.forum_path)
+ app.jinja_env.globals.update(post_jump=thread.post_jump)
from .roles import has_permission, is_bureaucrat, get_user_role
app.jinja_env.globals.update(
has_permission=has_permission,
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index dec9234..a5e444e 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -112,7 +112,7 @@ you do not have permission to create threads in this forum
{{ ts(thread.mrp_created) }}
</span>
<span class="thread-preview-post">
- <a href="{{url_for('thread.view_thread',thread_id=thread.id)}}#post_{{thread.mrp_id}}">
+ <a href="{{post_jump(thread.mrp_id)}}">
{{ thread.mrp_content[:500]|e }}
</a>
</span>
@@ -120,7 +120,7 @@ you do not have permission to create threads in this forum
{% else %}
<div class="listing-caption">
<a class="thread-preview-post"
- href="{{url_for('thread.view_thread',thread_id=thread.id)}}#post_{{thread.mrp_id}}">
+ href="{{post_jump(thread.mrp_id)}}">
latest post
</a>
</div>
diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html
index 993c005..fcaf29b 100644
--- a/apioforum/templates/view_post.html
+++ b/apioforum/templates/view_post.html
@@ -8,5 +8,5 @@
{{disp_post(post,False)}}
<p>post source:</p>
<textarea readonly class="new-post-box" name="newcontent">{{post.content}}</textarea>
-<a href="{{url_for('thread.view_thread',thread_id=post.thread)}}">i am satisfied</a>
+<a href="{{post_jump(post.id)}}">i am satisfied</a>
{% endblock %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index 0b12141..f3bcc59 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -14,7 +14,7 @@ bp = Blueprint("thread", __name__, url_prefix="/thread")
POSTS_PER_PAGE = 20
-def which_page(post_id):
+def which_page(post_id,return_thread_id=False):
# on which page lieth the post in question?
# forget not that page numbers employeth a system that has a base of 1.
# the
@@ -25,14 +25,22 @@ def which_page(post_id):
db = get_db()
# ASSUMES THAT post ids are consecutive and things
- # this is probably a reasonable assumption
- number_of_things_before_the_thing = db.execute('select count(*) as c from posts where thread = (select thread from posts where id = ?) and id < ?;',(post_id,post_id)).fetchone()['c']
+ # this is probably a reasonable assumption
+
+ thread_id = db.execute('select thread from posts where id = ?',(post_id,)).fetchone()['thread']
- return 1+math.floor(number_of_things_before_the_thing/POSTS_PER_PAGE)
+ number_of_things_before_the_thing = db.execute('select count(*) as c, thread as t from posts where thread = ? and id < ?;',(thread_id,post_id)).fetchone()['c']
+
+ page = 1+math.floor(number_of_things_before_the_thing/POSTS_PER_PAGE)
+ if return_thread_id:
+ return page, thread_id
+ else:
+ return page
-def post_jump(thread_id, post_id):
- return url_for("thread.view_thread",thread_id=thread_id)+"#post_"+str(post_id)
+def post_jump(post_id):
+ page,thread_id=which_page(post_id,True)
+ return url_for("thread.view_thread",thread_id=thread_id,page=page)+"#post_"+str(post_id)
@bp.route("/<int:thread_id>")
@bp.route("/<int:thread_id>/page/<int:page>")
@@ -248,7 +256,7 @@ def create_post(thread_id):
)
db.commit()
flash("post posted postfully")
- return redirect(post_jump(thread_id, post_id))
+ return redirect(post_jump(post_id))
return redirect(url_for('thread.view_thread',thread_id=thread_id))
@bp.route("/delete_post/<int:post_id>", methods=["GET","POST"])
@@ -320,7 +328,7 @@ def edit_post(post_id):
"UPDATE posts SET content = ?, edited = 1, updated = current_timestamp WHERE id = ?",(newcontent,post_id))
db.commit()
flash("post edited editiously")
- return redirect(post_jump(post['thread'],post_id))
+ return redirect(post_jump(post_id))
else:
flash(err)
return render_template("edit_post.html",post=post)