Follow users
This commit is contained in:
		@@ -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__)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user