Exemple #1
0
def edit_page(id):
    """

    Returns:

    """
    form = PageEditorForm()
    form.id = id
    page = Page()
    page_element = PageElement()
    form.parent_id.choices = page.get_id_label_list()
    page_elements = list()

    if id > 0:
        page.set_id(id)
        page.load()
        page_elements = page_element.get_list_for_page(page.get_id())

    if request.method == "POST":
        if form.validate_on_submit():
            page.prepare_form_input(request.form)
            page.save()
            page.load()
        else:
            form.get_error_messages()

    form.init_values(page)

    return render_template("content/pages/edit_page.html",
                           form=form,
                           page_elements=page_elements)
Exemple #2
0
def create_page(bookId):
    errors = ["An error occurred while creating a new page."]
    form = PageForm()
    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():
        new_page = Page(title=form.data['title'],
                        text=form.data["text"],
                        book_id=bookId)
        db.session.add(new_page)
        db.session.commit()
        return {new_page.get_id(): new_page.to_dict()}

    return {"errors": errors}