def upload(stylesheet_id: int): style: Stylesheet = get_or_404( db.session.query(Stylesheet).filter_by(id=stylesheet_id)) schema = StylesheetSchema(unknown=EXCLUDE, session=db.session, instance=style, partial=True) data = dict(request.form.copy()) if request.json is not None: data.update(request.json) if request.files.get("source", None) is not None: file: FileStorage = request.files.get("source") data["source"] = file.read() file.close() try: stylesheet = schema.load(data) except ValidationError as e: return jsonify(e.messages), BadRequest.code db.session.commit() result = schema.dump(stylesheet) return jsonify(result)
def index(template_id: int): template: Template = get_or_404( db.session.query(Template).filter_by(id=template_id)) template_schema = TemplateSchema(session=db.session) stylesheet_schemas = StylesheetSchema(session=db.session, many=True) return render_template( "sites/edit_template.html", template_json=template_schema.dumps(template), stylesheets_json=stylesheet_schemas.dumps(template.styles), )
def index(document_id: int): document: Document = get_or_404( db.session.query(Document).filter_by(id=document_id) ) doc_schema = DocumentSchema(session=db.session, instance=document) var_schemas = VariableSchema(session=db.session, many=True) template_schema = TemplateSchema(session=db.session) stylesheet_schemas = StylesheetSchema(session=db.session, many=True) return render_template( "sites/edit.html", document_id=document_id, document_json=doc_schema.dumps(document), variable_json=var_schemas.dumps(document.variables, many=True), template_json=template_schema.dumps(document.template), stylesheets_json=stylesheet_schemas.dumps(document.template.styles), )
def delete(template_id: int): return StylesheetSchema.delete(template_id)
def get(template_id: int): return StylesheetSchema.get(template_id)
def get_all(): return StylesheetSchema.get_all()
def create(): return StylesheetSchema.create()
def update(): return StylesheetSchema.update()