예제 #1
0
def new_notebook():
    data = request.json
    notebook = Notebook(title=data['title'],
                        userId=data['userId'],
                        isDefault=data['isDefault'])
    db.session.add(notebook)
    db.session.commit()
    return notebook.to_dict()
def add_notebook(user_id):
    notebook_data = json.loads(request.data.decode("utf-8"))

    notebook = Notebook(name=notebook_data, user_id=current_user.id)

    db.session.add(notebook)
    db.session.commit()
    return jsonify(notebook.to_dict())
예제 #3
0
def create_notebook(userid):
    data_title = json.loads(request.data)
    title = data_title["title"]
    user_id = userid
    new_notebook = Notebook(title=title, user_id=user_id)
    db.session.add(new_notebook)
    db.session.commit()

    return new_notebook.to_dict()
예제 #4
0
def new_notebook():
    data=request.json
    notebook= Notebook(**data)
    notebook.updated_at=datetime.datetime.now()
    db.session.add(notebook)
    db.session.commit()
    first_note = Note(owner_id = notebook.user_id,
                      notebook_id= notebook.id,
                      title="",
                      content= "",
                      shortcut = False,
                      updated_at = datetime.datetime.now())
    db.session.add(first_note)
    db.session.commit()
    return notebook.to_dict(), 200
예제 #5
0
def new_notebook():
    # 1. Get user from session
    user = current_user
    # 2. Prepare form data for validation
    form = NotebookForm()
    form['csrf_token'].data = request.cookies['csrf_token']

    # 3. Validate form data; if invalid return 400 bad request to user
    if not form.validate_on_submit():
        return {"message": "validation_errors", "data": form.errors}, 400

    # 4. If valid then extract useful data from form
    title = form.data['title']

    # 5. Create the notebook
    notebook = Notebook(user_id=user.id, title=title)

    # 6. Add and commit the notebook
    db.session.add(notebook)
    db.session.commit()

    # 7. Send 201 response to the user
    return {"message": "success", "data": notebook.to_dict()}, 201