From 9960239de2011dc286190a851a3dc035963b109a Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 19:14:04 +0000 Subject: add first parts of config thread page --- apioforum/templates/view_thread.html | 1 + apioforum/thread.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index f38cf34..ddc45b8 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -5,6 +5,7 @@ {% endblock %} {%block content%} +configure
{% for post in posts %} {% call disp_post(post, True) %} diff --git a/apioforum/thread.py b/apioforum/thread.py index 630cb33..f520d8e 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -105,4 +105,12 @@ def edit_post(post_id): flash(err) return render_template("edit_post.html",post=post) +@bp.route("//config",methods=["GET","POST"]) +def config_thread(thread_id): + db = get_db() + thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone() + if request.method == "POST": + abort(418) + return render_template("config_thread.html", thread=thread) + -- cgit v1.2.3 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 From 93d9da49abfb980951265aeaee9a2cf251bc1044 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:22:50 +0000 Subject: hide config thread button if you wouldn't be able to access it anyway --- apioforum/templates/view_thread.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index ddc45b8..eaaf581 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -5,7 +5,9 @@ {% endblock %} {%block content%} -configure +{% if g.user == thread.creator %} +configure thread +{% endif %}
{% for post in posts %} {% call disp_post(post, True) %} -- cgit v1.2.3