serve.py
def review():
    """ user wants to toggle a paper in his library """

    # make sure user is logged in
    if not g.user:
        # fail... (not logged in). JS should prevent from us getting here.
        return "NO"

    idvv = request.form["pid"]  # includes version
    if not isvalidid(idvv):
        print("paper id: " + idvv)
        print("bad paper")
        return "NO"  # fail, malformed id. weird.
    pid = strip_version(idvv)
    if not pid in db:
        return "NO"  # we don't know this paper. wat

    uid = session["user_id"]  # id of logged in user

    # check this user already has this paper in library
    record = query_db(
        """select * from library where
          user_id = ? and paper_id = ?""",
        [uid, pid],
        one=True,
    )

    ret = "NO"
    if record:
        # record exists, erase it.
        g.db.execute(
            """delete from library where user_id = ? and paper_id = ?""", [uid, pid]
        )
        g.db.commit()
        # print('removed %s for %s' % (pid, uid))
        ret = "OFF"
    else:
        # record does not exist, add it.
        rawpid = strip_version(pid)
        g.db.execute(
            """insert into library (paper_id, user_id, update_time) values (?, ?, ?)""",
            [rawpid, uid, int(time.time())],
        )
        g.db.commit()
        # print('added %s for %s' % (pid, uid))
        ret = "ON"

    return ret
 user wants to toggle a paper in his library 
user wants to toggle a paper in his library
user wants to toggle a paper in his library
def review():
    if not g.user:
        return "NO"
    idvv = request.form["pid"]  
    if not isvalidid(idvv):
        print("paper id: " + idvv)
        print("bad paper")
        return "NO"  
    pid = strip_version(idvv)
    if not pid in db:
        return "NO"  
    uid = session["user_id"]  
    record = query_db(
        """select * from library where
          user_id = ? and paper_id = ?""",
        [uid, pid],
        one=True,
    )
    ret = "NO"
    if record:
        g.db.execute(
            """delete from library where user_id = ? and paper_id = ?""", [uid, pid]
        )
        g.db.commit()
        ret = "OFF"
    else:
        rawpid = strip_version(pid)
        g.db.execute(
            """insert into library (paper_id, user_id, update_time) values (?, ?, ?)""",
            [rawpid, uid, int(time.time())],
        )
        g.db.commit()
        ret = "ON"
    return ret
def review ( ) : if not g . user : return "NO" idvv = request . form [ "pid" ] if not isvalidid ( idvv ) : print ( "paper id: " + idvv ) print ( "bad paper" ) return "NO" pid = strip_version ( idvv ) if not pid in db : return "NO" uid = session [ "user_id" ] record = query_db ( """select * from library where
          user_id = ? and paper_id = ?""" , [ uid , pid ] , one = True , ) ret = "NO" if record : g . db . execute ( """delete from library where user_id = ? and paper_id = ?""" , [ uid , pid ] ) g . db . commit ( ) ret = "OFF" else : rawpid = strip_version ( pid ) g . db . execute ( """insert into library (paper_id, user_id, update_time) values (?, ?, ?)""" , [ rawpid , uid , int ( time . time ( ) ) ] , ) g . db . commit ( ) ret = "ON" return ret
user wants to toggle a paper in his library
user wants to toggle a paper in his library
""" user wants to toggle a paper in his library """ # make sure user is logged in # fail... (not logged in). JS should prevent from us getting here. # includes version # fail, malformed id. weird. # we don't know this paper. wat # id of logged in user # check this user already has this paper in library # record exists, erase it. # print('removed %s for %s' % (pid, uid)) # record does not exist, add it. # print('added %s for %s' % (pid, uid))