summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-15 23:01:06 +0000
committerubq323 <ubq323>2021-06-15 23:01:06 +0000
commit2ed3c6588c6463e28a1f7e58a396f2cb590327cd (patch)
treedb8ce44dbe96b20cd17f3a0d79f55c2df3615ea5
parentf2fb2736afac2326a8ed16d702a9a6a2d10101d0 (diff)
allow changing tags on the configure thread page
-rw-r--r--apioforum/templates/config_thread.html21
-rw-r--r--apioforum/thread.py17
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 %}<h1>{% block title %}configure thread '{{thread.title}}'{% endblock %}</h1>{% endblock %}
{% block content %}
<form method="post">
+<fieldset>
+<legend>title</legend>
<p>if you want to change the title of this thread, make sure you check the "change title?" box.</p>
<label for="do_title">change title?</label>
-<input type="checkbox" name="do_title"><br>
+<input type="checkbox" id="do_title" name="do_title"><br>
<label for="title">thread title</label>
<input type="text" id="title" name="title" value="{{thread.title}}">
-<br>
+</fieldset>
+<fieldset>
+<legend>tags</legend>
+<p>if you want to change the tags on this thread, make sure you check the "change tags?" box.</p>
+<label for="do_chtags">change tags?</label>
+<input type="checkbox" name="do_chtags" id="do_chtags"><br>
+<ul>
+ {% for the_tag in avail_tags %}
+ <li>
+ <input type="checkbox" id="tag_{{the_tag.id}}" name="tag_{{the_tag.id}}" {%- if the_tag.id in thread_tags %} checked{% endif %}>
+ <label for="tag_{{the_tag.id}}">#{{the_tag.id}} {{tag(the_tag)}}</label>
+ </li>
+ {% endfor %}
+</ul>
+</fieldset>
<p>confirm changes?</p>
<input type="submit" value="confirm">
<a href="{{url_for('thread.view_thread',thread_id=thread.id)}}">cancel</a>
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)