def edit_note(note_id): if session.get('active'): noteJSON = json.loads(request.data) # get note with ID from DB note = db_session.query(Note).filter_by(idNote = note_id).first() # update note with new values note.title = noteJSON["title"] note.text = noteJSON["text"] # commit changes to database db_session.commit() js = json.dumps({ "error":"none" , "message":"ok" }) resp = Response(js , status=200, mimetype="application/json") return resp else: js = json.dumps({ "error":"session" , "message":"inactive" }) resp = Response(js , status=406, mimetype="application/json") return resp
def edit_note(note_id): if session.get('active'): noteJSON = json.loads(request.data) # get note with ID from DB note = db_session.query(Note).filter_by(idNote=note_id).first() # update note with new values note.title = noteJSON["title"] note.text = noteJSON["text"] # commit changes to database db_session.commit() js = json.dumps({"error": "none", "message": "ok"}) resp = Response(js, status=200, mimetype="application/json") return resp else: js = json.dumps({"error": "session", "message": "inactive"}) resp = Response(js, status=406, mimetype="application/json") return resp
def get_user(user_id): if session.get('active'): user = db_session.query(User).filter_by(idUser = user_id).first() js = json.dumps(user.toJSON()) resp = Response(js, status=200, mimetype="application/json") else: js = json.dumps({ "error":"session" , "message":"inactive" }) resp = Response(js , status=406, mimetype="application/json") return resp
def get_user(user_id): if session.get('active'): user = db_session.query(User).filter_by(idUser=user_id).first() js = json.dumps(user.toJSON()) resp = Response(js, status=200, mimetype="application/json") else: js = json.dumps({"error": "session", "message": "inactive"}) resp = Response(js, status=406, mimetype="application/json") return resp
def get_notes(): if session.get('active'): notes = db_session.query(Note).filter_by(user_id = session.get("idUser")).all() js = json.dumps([note.toJSON() for note in notes]) resp = Response(js , status=200, mimetype="application/json") else: js = json.dumps({ "error":"session" , "message":"inactive" }) resp = Response(js , status=406, mimetype="application/json") return resp
def get_notes(): if session.get('active'): notes = db_session.query(Note).filter_by( user_id=session.get("idUser")).all() js = json.dumps([note.toJSON() for note in notes]) resp = Response(js, status=200, mimetype="application/json") else: js = json.dumps({"error": "session", "message": "inactive"}) resp = Response(js, status=406, mimetype="application/json") return resp
def check_username(): username = json.loads(request.data)["username"] print username # run tests on username to see if it is taken or free user = db_session.query(User).filter_by(username=username).first() #if there is no user with that username, return good if user == None: js = json.dumps({ "error":"none" , "message":"ok" }) resp = Response(js , status=200, mimetype="application/json") else: js = json.dumps({ "error":"username taken" , "message":"failed" }) resp = Response(js , status=406, mimetype="application/json") return resp
def check_username(): username = json.loads(request.data)["username"] print username # run tests on username to see if it is taken or free user = db_session.query(User).filter_by(username=username).first() #if there is no user with that username, return good if user == None: js = json.dumps({"error": "none", "message": "ok"}) resp = Response(js, status=200, mimetype="application/json") else: js = json.dumps({"error": "username taken", "message": "failed"}) resp = Response(js, status=406, mimetype="application/json") return resp
def recordNoteHistory(mapper, connection, target): # execute a stored procedure upon UPDATE, # apply the value to the row to be inserted # create a target duplicate target_cp = target # remove target changes from current session db_session.expunge(target) # fetch row to be updated note = db_session.query(Note).filter_by(idNote = target_cp.idNote).first() # create history (copy) of that note note_history = NoteHistory(note.title, note.text, note.idNote, session.get("idUser")) # add history to session db_session.add(note_history) # merge target_cp with current session db_session.merge(target_cp)
def recordNoteHistory(mapper, connection, target): # execute a stored procedure upon UPDATE, # apply the value to the row to be inserted # create a target duplicate target_cp = target # remove target changes from current session db_session.expunge(target) # fetch row to be updated note = db_session.query(Note).filter_by(idNote=target_cp.idNote).first() # create history (copy) of that note note_history = NoteHistory(note.title, note.text, note.idNote, session.get("idUser")) # add history to session db_session.add(note_history) # merge target_cp with current session db_session.merge(target_cp)
def create_session(): # provjera username i password # ako je korisnik proden onda se kreira sesija # na serveru i salje se potvrda klijentu za js # uhvati podatke iz jsona userJSON = json.loads(request.data) # pronadi korisnika po username i password user = db_session.query(User).filter_by(username=userJSON["username"], password=userJSON["password"]).first() if user == None: js = json.dumps({ "error":"authentification" , "message":"failed" }) resp = Response(js , status=406, mimetype="application/json") else: session['active'] = True session["idUser"] = user.idUser session["username"] = user.username js = json.dumps({ "error":"none" , "message":"ok" }) resp = Response(js , status=200, mimetype="application/json") return resp
def create_session(): # provjera username i password # ako je korisnik proden onda se kreira sesija # na serveru i salje se potvrda klijentu za js # uhvati podatke iz jsona userJSON = json.loads(request.data) # pronadi korisnika po username i password user = db_session.query(User).filter_by( username=userJSON["username"], password=userJSON["password"]).first() if user == None: js = json.dumps({"error": "authentification", "message": "failed"}) resp = Response(js, status=406, mimetype="application/json") else: session['active'] = True session["idUser"] = user.idUser session["username"] = user.username js = json.dumps({"error": "none", "message": "ok"}) resp = Response(js, status=200, mimetype="application/json") return resp