@view_config(renderer='save.mak', route_name='save')
def save(request):
    s = request.session
    p = request.session['safe_params']
    u = None
    op = 'add'
    vote_dict = {}

    if 'story_id' in p and 'logged_in' in s:
        dbsession = DBSession()
        u = users.get_user_by_id(s['users.id'])
        to_save = submission.get_story_by_id(p['story_id'])
        if 'op' in p:
            op = p['op']
        if op == 'add':
            if to_save not in u.saved:
                u.saved.append(to_save)
                dbsession.add(u)
            s['message'] = 'Successfully saved {0}'.format(to_save.title)
        elif op == 'del':
            if to_save in u.saved:
                u.saved.remove(to_save)
                dbsession.add(u)
            s['message'] = 'Successfully unsaved {0}'.format(to_save.title)
    elif 'logged_in' in s:
        u = users.get_user_by_id(s['users.id'])

    if u:
        vds = []
        for i in u.saved:
            vds.append(users.get_user_votes(s['users.id'], "on_submission", i.id))
        for vd in vds:
            if type(vd) == dict:
                vote_dict.update(vd)

    return {'saved': u.saved, 'vote_dict': vote_dict, }
dataset/ETHPy150Open sjuxax/raggregate/raggregate/views/user.py/save/original