From 7aab6df74f98c16e4c3186b7b2e0daa5a78e4d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Tue, 1 Jul 2025 18:32:49 +0300 Subject: [PATCH] add responding to thread --- app/models.py | 6 ++++++ app/routes/threads.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/models.py b/app/models.py index 3ef4bf1..e1ecce0 100644 --- a/app/models.py +++ b/app/models.py @@ -167,6 +167,12 @@ class Threads(Model): q = Posts.FULL_POSTS_QUERY + " WHERE posts.thread_id = ? ORDER BY posts.created_at ASC LIMIT ? OFFSET ?" return db.query(q, self.id, limit, offset) + def locked(self): + return bool(self.is_locked) + + def stickied(self): + return bool(self.is_stickied) + class Posts(Model): FULL_POSTS_QUERY = """ SELECT diff --git a/app/routes/threads.py b/app/routes/threads.py index 7421ac9..0b39aef 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -52,6 +52,24 @@ def thread(slug): ) +@bp.post("/") +@login_required +def reply(slug): + thread = Threads.find({"slug": slug}) + if not thread: + return "no" + user = get_active_user() + if user.is_guest(): + return "no" + if thread.locked() and not user.is_mod(): + return "no" + + post_content = request.form['post_content'] + post = create_post(thread.id, user.id, post_content) + + return redirect(url_for(".thread", slug=slug, after=post.id, _anchor="latest-post")) + + @bp.get("/create") @login_required def create():