def update_page(bookId, pageId): errors = ["An error occurred while updating your page."] the_page = Page.query.get(pageId) form = PageForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): the_page.update_page_data(form.data['title'], form.data["text"]) db.session.add(the_page) db.session.commit() return {the_page.get_id(): the_page.to_dict()} return {"errors": errors}
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}
def submit_page(path): path = decode_path(path) form = PageForm() if form.validate_on_submit(): photo = form.img.data filename = photos.save(photo) if photo else DEFAULT_IMAGE page = Page(path=path, title=form.title.data, text=form.text.data, img=filename, author=current_user) db.session.add(page) db.session.commit() return redirect(url_for('submit')) info = { 'title': 'SUBMIT: PAGE', 'homepage': False, 'banner_img': DEFAULT_IMAGE, 'form': form, 'path': path } return render_template('submit/page.html', info=info)