Follow users

This commit is contained in:
2018-07-09 08:33:04 +02:00
parent 4cbebb9c5a
commit ba1a660b1a
3 changed files with 41 additions and 0 deletions

View File

@@ -266,5 +266,26 @@ class CalendarSocialApp(Flask):
return render_template('profile-details.html', profile=profile)
@staticmethod
@route('/profile/@<string:username>/follow')
def follow_user(username):
"""View for following a user
"""
from .models import db, Profile, User, UserFollow
profile = current_user.profile
if profile is None:
abort(404)
if profile.user != current_user:
follow = UserFollow(follower_id=current_user.profile,
followed_id=profile,
accepted_at=datetime.utcnow())
db.session.add(follow)
db.session.commit()
return redirect(url_for('display_profile', username=username))
app = CalendarSocialApp(__name__)