mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 15:07:35 +01:00
Add subscribe/unsubscribe button
This commit is contained in:
parent
909a2b4ce9
commit
e82166f87e
@ -731,6 +731,15 @@ class Thread(db.Model):
|
|||||||
watchers = db.relationship("User", secondary=watchers, lazy="subquery", \
|
watchers = db.relationship("User", secondary=watchers, lazy="subquery", \
|
||||||
backref=db.backref("watching", lazy=True))
|
backref=db.backref("watching", lazy=True))
|
||||||
|
|
||||||
|
|
||||||
|
def getSubscribeURL(self):
|
||||||
|
return url_for("thread_subscribe_page",
|
||||||
|
id=self.id)
|
||||||
|
|
||||||
|
def getUnsubscribeURL(self):
|
||||||
|
return url_for("thread_unsubscribe_page",
|
||||||
|
id=self.id)
|
||||||
|
|
||||||
def checkPerm(self, user, perm):
|
def checkPerm(self, user, perm):
|
||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return not self.private
|
return not self.private
|
||||||
|
@ -6,11 +6,24 @@ Threads
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{% if thread.private %}🔒 {% endif %}{{ thread.title }}</h1>
|
<h1>{% if thread.private %}🔒 {% endif %}{{ thread.title }}</h1>
|
||||||
|
{% if thread.package or current_user.is_authenticated %}
|
||||||
|
{% if thread.package %}
|
||||||
|
<p>Package: <a href="{{ thread.package.getDetailsURL() }}">{{ thread.package.title }}</a></p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if thread.package %}
|
{% if current_user.is_authenticated %}
|
||||||
<p>
|
{% if current_user in thread.watchers %}
|
||||||
Package: <a href="{{ thread.package.getDetailsURL() }}">{{ thread.package.title }}</a>
|
<form method="post" action="{{ thread.getUnsubscribeURL() }}">
|
||||||
</p>
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<input type="submit" value="Unsubscribe" />
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<form method="post" action="{{ thread.getSubscribeURL() }}">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<input type="submit" value="Subscribe" />
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if thread.private %}
|
{% if thread.private %}
|
||||||
|
@ -32,6 +32,41 @@ def threads_page():
|
|||||||
query = query.filter_by(private=False)
|
query = query.filter_by(private=False)
|
||||||
return render_template("threads/list.html", threads=query.all())
|
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"])
|
@app.route("/threads/<int:id>/", methods=["GET", "POST"])
|
||||||
def thread_page(id):
|
def thread_page(id):
|
||||||
clearNotifications(url_for("thread_page", id=id))
|
clearNotifications(url_for("thread_page", id=id))
|
||||||
|
Loading…
Reference in New Issue
Block a user