summaryrefslogtreecommitdiffhomepage
path: root/apioforum/thread.py
blob: 24b77663840b9a7fcad5a39b07ab0761a5db63cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# view posts in thread

from flask import (
    Blueprint, render_template
)
from .db import get_db

bp = Blueprint("thread", __name__, url_prefix="/thread")

@bp.route("/view/<int:thread_id>")
def view_thread(thread_id):
    db = get_db()
    thread = db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone()
    if thread is None:
        abort(404)
    else:
        posts = db.execute("SELECT * FROM posts WHERE thread = ? ORDER BY idx;",(thread_id,)).fetchall()
        return render_template("view_thread.html",posts=posts,thread=thread)