From a3b9a43a626966ec0885a0882a4d7f5ee3221803 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:20:29 +0000 Subject: finish all config thread things, currently only changing thread title is supported --- apioforum/templates/config_thread.html | 15 +++++++++++++++ apioforum/thread.py | 27 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 apioforum/templates/config_thread.html 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 %}

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

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

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

+ +
+ + +
+

confirm changes?

+ +cancel +
+{% 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) -- cgit v1.2.3