add responding to thread

This commit is contained in:
Lera Elvoé 2025-07-01 18:32:49 +03:00
parent e0d1abc1e9
commit 7aab6df74f
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
2 changed files with 24 additions and 0 deletions

View File

@ -167,6 +167,12 @@ class Threads(Model):
q = Posts.FULL_POSTS_QUERY + " WHERE posts.thread_id = ? ORDER BY posts.created_at ASC LIMIT ? OFFSET ?" 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) 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): class Posts(Model):
FULL_POSTS_QUERY = """ FULL_POSTS_QUERY = """
SELECT SELECT

View File

@ -52,6 +52,24 @@ def thread(slug):
) )
@bp.post("/<slug>")
@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") @bp.get("/create")
@login_required @login_required
def create(): def create():