def pages_preview(): # We only care about content. # Loading other attributes improperly will cause Marshmallow to incorrectly return a dict data = {"content": request.form.get("content")} schema = PageSchema() page = schema.load(data) return render_template("page.html", content=page.data.html)
def post(self): req = request.get_json() schema = PageSchema() response = schema.load(req) if response.errors: return {'success': False, 'errors': response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() return {'success': True, 'data': response.data}
def patch(self, page_id): page = Pages.query.filter_by(id=page_id).first_or_404() req = request.get_json() schema = PageSchema(partial=True) response = schema.load(req, instance=page, partial=True) if response.errors: return {'success': False, 'errors': response.errors}, 400 db.session.commit() response = schema.dump(response.data) db.session.close() return {'success': True, 'data': response.data}
def post(self, json_args): req = json_args schema = PageSchema() response = schema.load(req) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() clear_pages() return {"success": True, "data": response.data}
def pages_preview(): data = request.form.to_dict() schema = PageSchema() page = schema.load(data) return render_template('page.html', content=markdown(page.data.content))
def pages_preview(): data = request.form.to_dict() schema = PageSchema() page = schema.load(data) return render_template("page.html", content=build_html(page.data.content))