aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-14 20:25:22 +0000
committerubq323 <ubq323>2021-06-14 20:25:22 +0000
commit1da10c6fa2115ca9b9ddcc60894bde49dbe010eb (patch)
treea98dbf3133bc721c7339abe0d5f95f2aa9788e08
parentd020dcd7e87a28d6cc06698929035850ccacb7dc (diff)
parent93d9da49abfb980951265aeaee9a2cf251bc1044 (diff)
merge the config thread things
-rw-r--r--apioforum/templates/config_thread.html15
-rw-r--r--apioforum/templates/view_thread.html3
-rw-r--r--apioforum/thread.py33
3 files changed, 51 insertions, 0 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/templates/view_thread.html b/apioforum/templates/view_thread.html
index f38cf34..eaaf581 100644
--- a/apioforum/templates/view_thread.html
+++ b/apioforum/templates/view_thread.html
@@ -5,6 +5,9 @@
{% endblock %}
{%block content%}
+{% if g.user == thread.creator %}
+<a class="actionbutton" href="{{url_for('thread.config_thread',thread_id=thread_id)}}">configure thread</a>
+{% endif %}
<div class="posts">
{% for post in posts %}
{% call disp_post(post, True) %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index 630cb33..12ced72 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -105,4 +105,37 @@ def edit_post(post_id):
flash(err)
return render_template("edit_post.html",post=post)
+@bp.route("/<int:thread_id>/config",methods=["GET","POST"])
+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":
+ 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)
+