summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-14 20:20:29 +0000
committerubq323 <ubq323>2021-06-14 20:20:29 +0000
commita3b9a43a626966ec0885a0882a4d7f5ee3221803 (patch)
treed049d915c89ecfce74a1952cc3c7fc6ecd67b9f6
parent9960239de2011dc286190a851a3dc035963b109a (diff)
finish all config thread things, currently only changing thread title is supported
-rw-r--r--apioforum/templates/config_thread.html15
-rw-r--r--apioforum/thread.py27
2 files changed, 41 insertions, 1 deletions
diff --git a/apioforum/templates/config_thread.html b/apioforum/templates/config_thread.html
new file mode 100644
index 0000000..b0dd5f0
--- /dev/null
+++ b/apioforum/templates/config_thread.html
@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+{% block header %}<h1>{% block title %}configure thread '{{thread.title}}'{% endblock %}</h1>{% endblock %}
+{% block content %}
+<form method="post">
+<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>
+<label for="title">thread title</label>
+<input type="text" id="title" name="title" value="{{thread.title}}">
+<br>
+<p>confirm changes?</p>
+<input type="submit" value="confirm">
+<a href="{{url_for('thread.view_thread',thread_id=thread.id)}}">cancel</a>
+</form>
+{% endblock %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index f520d8e..12ced72 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -109,8 +109,33 @@ def edit_post(post_id):
def config_thread(thread_id):
db = get_db()
thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone()
+ err = None
+ if g.user is None:
+ err = "you need to be logged in to do that"
+ elif g.user != thread['creator']:
+ err = "you can only configure threads that you own"
+
+ if err is not None:
+ flash(err)
+ return redirect(url_for("thread.view_thread",thread_id=thread_id))
+
if request.method == "POST":
- abort(418)
+ err = []
+ if 'do_title' in request.form:
+ title = request.form['title']
+ if len(title.strip()) == 0:
+ err.append("title can't be empty")
+ else:
+ db.execute("update threads set title = ? where id = ?;",(title,thread_id))
+ flash("title updated successfully")
+ db.commit()
+
+ if len(err) > 0:
+ for e in err:
+ flash(e)
+ else:
+ return redirect(url_for("thread.view_thread",thread_id=thread_id))
+
return render_template("config_thread.html", thread=thread)