diff options
author | ubq323 <ubq323> | 2021-06-15 23:40:03 +0000 |
---|---|---|
committer | ubq323 <ubq323> | 2021-06-15 23:40:03 +0000 |
commit | 8ec18ae1d985aee2bcf146c1e4f783b91643406a (patch) | |
tree | 2ce44f58bf2be3a2e5ff140f6b1dd9174cb69efe /apioforum/thread.py | |
parent | cdc3350992c11464c61782dd208d7671b56871ac (diff) | |
parent | 6096acce8b922af98e6846a687fcfd19cf0370cc (diff) |
merge tags into trunk
Diffstat (limited to 'apioforum/thread.py')
-rw-r--r-- | apioforum/thread.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/apioforum/thread.py b/apioforum/thread.py index 14450af..292fd21 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -23,8 +23,12 @@ def view_thread(thread_id): "SELECT * FROM posts WHERE thread = ? ORDER BY created ASC;", (thread_id,) ).fetchall() + tags = db.execute( + """SELECT tags.* FROM tags + INNER JOIN thread_tags ON thread_tags.tag = tags.id + WHERE thread_tags.thread = ?""",(thread_id,)).fetchall() rendered_posts = [render(q['content']) for q in posts] - return render_template("view_thread.html",posts=posts,thread=thread,thread_id=thread_id,rendered_posts=rendered_posts) + return render_template("view_thread.html",posts=posts,thread=thread,rendered_posts=rendered_posts,tags=tags) @bp.route("/<int:thread_id>/create_post", methods=("POST",)) def create_post(thread_id): @@ -109,6 +113,8 @@ def edit_post(post_id): def config_thread(thread_id): db = get_db() thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone() + thread_tags = [r['tag'] for r in db.execute("select tag from thread_tags where thread = ?",(thread_id,)).fetchall()] + avail_tags = db.execute("select * from tags order by id").fetchall() err = None if g.user is None: err = "you need to be logged in to do that" @@ -129,6 +135,22 @@ def config_thread(thread_id): db.execute("update threads set title = ? where id = ?;",(title,thread_id)) flash("title updated successfully") db.commit() + if 'do_chtags' in request.form: + changed = False + wanted_tags = [] + for tagid in range(1,len(avail_tags)+1): + current = tagid in thread_tags + wanted = f'tag_{tagid}' in request.form + print(tagid, current, wanted) + if wanted and not current: + db.execute("insert into thread_tags (thread, tag) values (?,?)",(thread_id,tagid)) + changed = True + elif current and not wanted: + db.execute("delete from thread_tags where thread = ? and tag = ?",(thread_id,tagid)) + changed = True + if changed: + db.commit() + flash("tags updated successfully") if len(err) > 0: for e in err: @@ -137,5 +159,5 @@ def config_thread(thread_id): return redirect(url_for("thread.view_thread",thread_id=thread_id)) - return render_template("config_thread.html", thread=thread) + return render_template("config_thread.html", thread=thread,thread_tags=thread_tags,avail_tags=avail_tags) |