From 9dac45d7121ccffe3a6575655b2aed1c16900317 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 30 Oct 2026 20:16:15 -0500 Subject: thread_info function --- apioforum/thread.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apioforum/thread.py b/apioforum/thread.py index 98a4206..7723a79 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -44,11 +44,15 @@ def post_jump(post_id,*,external=False): page,thread_id=which_page(post_id,True) return url_for("thread.view_thread",thread_id=thread_id,page=page,_external=external)+"#post_"+str(post_id) +def thread_info(thread_id): + db = get_db() + return db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone() + @bp.route("/") @bp.route("//page/") def view_thread(thread_id,page=1): db = get_db() - thread = db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone() + thread = thread_info(thread_id) if thread is None: abort(404) if not has_permission(thread['forum'], g.user, "p_view_threads", False): @@ -157,7 +161,7 @@ def create_poll(thread_id): success = redirect(url_for('thread.view_thread',thread_id=thread_id)) err = None db = get_db() - thread = db.execute('select * from threads where id = ?',(thread_id,)).fetchone() + thread = thread_info(thread_id) polltitle = request.form.get('polltitle','').strip() polloptions = [q.strip() for q in request.form.get('polloptions','').split("\n") if len(q.strip()) > 0] @@ -200,7 +204,7 @@ def delete_poll(thread_id): success = redirect(url_for('thread.view_thread',thread_id=thread_id)) err = None db = get_db() - thread = db.execute('select * from threads where id = ?',(thread_id,)).fetchone() + thread = thread_info(thread_id) if thread is None: err = "that thread does not exist" @@ -232,7 +236,7 @@ def create_post(thread_id): flash("you need to log in before you can post") db = get_db() content = request.form['content'] - thread = db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone() + thread = thread_info(thread_id) if len(content.strip()) == 0: flash("you cannot post an empty message") elif not thread: @@ -276,7 +280,6 @@ def create_post(thread_id): def delete_post(post_id): db = get_db() post = db.execute("SELECT * FROM posts WHERE id = ?",(post_id,)).fetchone() - thread = db.execute("SELECT * FROM threads WHERE id = ?",(post['thread'],)).fetchone() if post is None: flash("that post doesn't exist") return redirect("/") -- cgit v1.2.3