From 2ed3c6588c6463e28a1f7e58a396f2cb590327cd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 23:01:06 +0000 Subject: allow changing tags on the configure thread page --- apioforum/templates/config_thread.html | 21 +++++++++++++++++++-- apioforum/thread.py | 17 ++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apioforum/templates/config_thread.html b/apioforum/templates/config_thread.html index b0dd5f0..973fbf5 100644 --- a/apioforum/templates/config_thread.html +++ b/apioforum/templates/config_thread.html @@ -1,13 +1,30 @@ {% extends 'base.html' %} +{% from 'common.html' import tag %} {% block header %}

{% block title %}configure thread '{{thread.title}}'{% endblock %}

{% endblock %} {% block content %}
+
+title

if you want to change the title of this thread, make sure you check the "change title?" box.

-
+
-
+
+
+tags +

if you want to change the tags on this thread, make sure you check the "change tags?" box.

+ +
+
    + {% for the_tag in avail_tags %} +
  • + + +
  • + {% endfor %} +
+

confirm changes?

cancel diff --git a/apioforum/thread.py b/apioforum/thread.py index e881a69..fd196c5 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -113,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" @@ -133,6 +135,19 @@ 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: + 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)) + flash(f"added tag {tagid}") + elif current and not wanted: + db.execute("delete from thread_tags where thread = ? and tag = ?",(thread_id,tagid)) + flash(f"removed tag {tagid}") + db.commit() if len(err) > 0: for e in err: @@ -141,5 +156,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) -- cgit v1.2.3