def new_note(db):    
    session = bottle.request.environ.get('beaker.session')
    user_id = session.get('user_id')    
    data = bottle.request.json
    try:
        notebook_id = data['notebook_id']
    except KeyError:
        bottle.abort(400,"not enough parameters")
    try:
        notebook = db.query(Notebook).filter_by(user_id = user_id, id = notebook_id).one()
        try:
            new_note = Note(title=data['title'], text=data['text'], notebook_id=notebook.id)
        except KeyError:
            bottle.abort(400,"not enough parameters")
        db.add(new_note)
        db.commit()
        #notes = db.query(Note).filter_by(notebook_id = notebook_id).all()
        return json.dumps(new_note.to_dict(), ensure_ascii=False)
    except NoResultFound:
        bottle.abort(406,"error")
Пример #2
0
def create_note():
	body = json.loads(request.data)
	created_notes += 1
	new_note = Note(created_notes, body["title"])
	notes.append(new_note)
	return json.dumps(new_note.to_dict()), 201