@view_config(renderer='follow.mak', route_name='follow')
def follow(request):
    s = request.session
    p = request.session['safe_params']
    message = ''

    if 'logged_in' not in s:
        s['message'] = 'Sorry, you must be logged in to use the follow feature.'
        return {'success': False, 'code': 'ENOLOGIN'}

    if 'follow_id' in p and 'logged_in' in s:
        dbsession = DBSession()
        #@TODO: replace with model-wide method to get logged-in user object
        u = users.get_user_by_id(s['users.id'])
        to_follow = users.get_user_by_id(p['follow_id'])
        op = 'add'
        if 'op' in p:
            op = p['op']
        if to_follow not in u.follows and op == 'add':
            u.follows.append(to_follow)
            del(s['followed_users'])
            dbsession.add(u)
            message = 'Successfully following {0}'.format(to_follow.display_name())
        elif to_follow in u.follows and op == 'del':
            u.follows.remove(to_follow)
            del(s['followed_users'])
            dbsession.add(u)
            message = 'Successfully unfollowed {0}'.format(to_follow.display_name())
    elif 'logged_in' in s:
        u = users.get_user_by_id(s['users.id'])

    vds = []
    vote_dict = {}

    if u:
       for i in u.follows:
           for story in i.submissions:
               #@FIXME: this is probably quite slow
               vds.append(users.get_user_votes(u.id, "on_submission", story.id))
       for vd in vds:
           if type(vd) == dict:
               vote_dict.update(vd)

    s['message'] = message
    return {'follows': u.follows, 'vote_dict': vote_dict}
dataset/ETHPy150Open sjuxax/raggregate/raggregate/views/user.py/follow/original