예제 #1
0
파일: views.py 프로젝트: mabasic/flasknotes
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 
예제 #2
0
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
예제 #3
0
파일: views.py 프로젝트: mabasic/flasknotes
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 
예제 #4
0
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
예제 #5
0
파일: views.py 프로젝트: mabasic/flasknotes
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 
예제 #6
0
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
예제 #7
0
파일: views.py 프로젝트: mabasic/flasknotes
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
예제 #8
0
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
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
파일: views.py 프로젝트: mabasic/flasknotes
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 
예제 #12
0
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