diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-07-28 15:30:59 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-07-28 15:30:59 +0100 |
commit | e82166f87e89f329e9fd94a26dfc8651c69deb91 (patch) | |
tree | 43fc3c193295dba4d6c235d0910b8999ae85a93b /app/views/threads.py | |
parent | 909a2b4ce9ffd325fff06cc26d996c19ca117aa6 (diff) | |
download | cheatdb-e82166f87e89f329e9fd94a26dfc8651c69deb91.tar.xz |
Add subscribe/unsubscribe button
Diffstat (limited to 'app/views/threads.py')
-rw-r--r-- | app/views/threads.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/views/threads.py b/app/views/threads.py index 316ca4d..37ac3d1 100644 --- a/app/views/threads.py +++ b/app/views/threads.py @@ -32,6 +32,41 @@ def threads_page(): query = query.filter_by(private=False) return render_template("threads/list.html", threads=query.all()) + +@app.route("/threads/<int:id>/subscribe/", methods=["POST"]) +@login_required +def thread_subscribe_page(id): + thread = Thread.query.get(id) + if thread is None or not thread.checkPerm(current_user, Permission.SEE_THREAD): + abort(404) + + if current_user in thread.watchers: + flash("Already subscribed!", "success") + else: + flash("Subscribed to thread", "success") + thread.watchers.append(current_user) + db.session.commit() + + return redirect(url_for("thread_page", id=id)) + + +@app.route("/threads/<int:id>/unsubscribe/", methods=["POST"]) +@login_required +def thread_unsubscribe_page(id): + thread = Thread.query.get(id) + if thread is None or not thread.checkPerm(current_user, Permission.SEE_THREAD): + abort(404) + + if current_user in thread.watchers: + flash("Unsubscribed!", "success") + thread.watchers.remove(current_user) + db.session.commit() + else: + flash("Not subscribed to thread", "success") + + return redirect(url_for("thread_page", id=id)) + + @app.route("/threads/<int:id>/", methods=["GET", "POST"]) def thread_page(id): clearNotifications(url_for("thread_page", id=id)) |