forked from gergely/calendar-social
Make it possible to accept follow requests
This commit is contained in:
parent
61f10f951c
commit
5639c3f578
@ -419,5 +419,45 @@ class CalendarSocialApp(Flask):
|
||||
|
||||
return render_template('index.html', calendar=calendar, user_only=False)
|
||||
|
||||
@staticmethod
|
||||
@route('/follow-requests')
|
||||
@login_required
|
||||
def follow_requests():
|
||||
"""View for listing follow requests
|
||||
"""
|
||||
|
||||
from .models import UserFollow
|
||||
|
||||
requests = UserFollow.query \
|
||||
.filter(UserFollow.followed == current_user.profile) \
|
||||
.filter(UserFollow.accepted_at.is_(None))
|
||||
|
||||
return render_template('follow-requests.html', requests=requests)
|
||||
|
||||
@staticmethod
|
||||
@route('/follow-request/<int:follower_id>/accept')
|
||||
@login_required
|
||||
def accept_follow(follower_id):
|
||||
"""View for accepting a follow request
|
||||
"""
|
||||
|
||||
from .models import db, UserFollow
|
||||
|
||||
try:
|
||||
req = UserFollow.query \
|
||||
.filter(UserFollow.followed == current_user.profile) \
|
||||
.filter(UserFollow.follower_id == follower_id) \
|
||||
.one()
|
||||
except NoResultFound:
|
||||
abort(404)
|
||||
|
||||
if req.accepted_at is None:
|
||||
req.accept()
|
||||
|
||||
db.session.add(req)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('follow_requests'))
|
||||
|
||||
|
||||
app = CalendarSocialApp(__name__)
|
||||
|
@ -604,6 +604,12 @@ class UserFollow(db.Model): # pylint: disable=too-few-public-methods
|
||||
#: The timestamp when the follow was accepted
|
||||
accepted_at = db.Column(db.DateTime(), nullable=True)
|
||||
|
||||
def accept(self):
|
||||
"""Accept this follow request
|
||||
"""
|
||||
|
||||
self.accepted_at = datetime.utcnow()
|
||||
|
||||
|
||||
class Notification(db.Model):
|
||||
"""Database model for notifications
|
||||
|
13
calsocial/templates/follow-requests.html
Normal file
13
calsocial/templates/follow-requests.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans %}Follow requests{% endtrans %}</h2>
|
||||
<ul>
|
||||
{% for req in requests %}
|
||||
<li>
|
||||
{{ req.follower }}
|
||||
<a href="{{ url_for('accept_follow', follower_id=req.follower_id) }}">{% trans %}Accept{% endtrans %}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user