@app.route('/libtoggle', methods=['POST'])
def review():
 if (not g.user):
  return 'NO'
 idvv = request.form['pid']
 if (not isvalidid(idvv)):
  return 'NO'
 pid = strip_version(idvv)
 if (not (pid in db)):
  return 'NO'
 uid = session['user_id']
 record = query_db('select * from library where\n          user_id = ? and paper_id = ?', [uid, pid], one=True)
 print record
 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

@ app . route ( '/libtoggle' , methods = [ 'POST' ] ) def review ( ) : if ( not g . user ) : return 'NO' idvv = request . form [ 'pid' ] if ( not isvalidid ( idvv ) ) : return 'NO' pid = strip_version ( idvv ) if ( not ( pid in db ) ) : return 'NO' uid = session [ 'user_id' ] record = query_db ( 'select * from library where\n          user_id = ? and paper_id = ?' , [ uid , pid ] , one = True ) print record 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 .