forked from gergely/calendar-social
Make it possible to accept follow requests
This commit is contained in:
@@ -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__)
|
||||
|
Reference in New Issue
Block a user