summaryrefslogtreecommitdiffhomepage
path: root/apioforum/forum.py
diff options
context:
space:
mode:
Diffstat (limited to 'apioforum/forum.py')
-rw-r--r--apioforum/forum.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index fa6fcc8..09d3166 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -11,20 +11,27 @@ from .mdrender import render
from sqlite3 import OperationalError
-bp = Blueprint("forum", __name__, url_prefix="/")
+from sqlite3 import OperationalError
+bp = Blueprint("forum", __name__, url_prefix="/")
@bp.route("/")
-def view_forum():
+def not_actual_index():
+ return redirect("/1")
+
+@bp.route("/<int:forum_id>")
+def view_forum(forum_id):
db = get_db()
+ forum = db.execute("SELECT * FROM forums WHERE id = ?",(forum_id,)).fetchone()
threads = db.execute(
"""SELECT threads.id, threads.title, threads.creator, threads.created,
threads.updated, count(posts.id) as num_replies, max(posts.id), posts.author as last_user
FROM threads
INNER JOIN posts ON posts.thread = threads.id
+ WHERE threads.forum = ?
GROUP BY threads.id
ORDER BY threads.updated DESC;
- """).fetchall()
+ """,(forum_id,)).fetchall()
thread_tags = {}
preview_post = {}
#todo: somehow optimise this
@@ -40,14 +47,19 @@ def view_forum():
ORDER BY created DESC;
""",(thread['id'],)).fetchone()
return render_template("view_forum.html",
+ forum=forum,
threads=threads,
thread_tags=thread_tags,
preview_post=preview_post
)
-@bp.route("/create_thread",methods=("GET","POST"))
-def create_thread():
+@bp.route("/<int:forum_id>/create_thread",methods=("GET","POST"))
+def create_thread(forum_id):
db = get_db()
+ forum = db.execute("SELECT * FROM forums WHERE id = ?",(forum_id,)).fetchone()
+ if forum is None:
+ flash("that forum doesn't exist")
+ return redirect(url_for('index'))
if g.user is None:
flash("you need to be logged in to create a thread")
@@ -63,8 +75,8 @@ def create_thread():
if err is None:
cur = db.cursor()
cur.execute(
- "INSERT INTO threads (title,creator,created,updated) VALUES (?,?,current_timestamp,current_timestamp);",
- (title,g.user)
+ "INSERT INTO threads (title,creator,created,updated,forum) VALUES (?,?,current_timestamp,current_timestamp,?);",
+ (title,g.user,forum_id)
)
thread_id = cur.lastrowid
cur.execute(