def remove_stylesheet(template_id: int): template: Template = get_or_404( db.session.query(Template).filter_by(id=template_id)) data = TemplateSchema.all_request_data() if isinstance(data, list): for entry in data: if not hasattr(entry, "id"): raise BadRequest("Required property: id") delete_relation = template_stylesheet_relation.delete().where( and_( template_stylesheet_relation.c.template_id == template.id, template_stylesheet_relation.c.style_id == entry.get("id"), )) db.session.execute(delete_relation) elif isinstance(data, dict): delete_relation = template_stylesheet_relation.delete().where( and_( template_stylesheet_relation.c.template_id == template.id, template_stylesheet_relation.c.style_id == data.get("id"), )) db.session.execute(delete_relation) db.session.commit() template_schema = TemplateSchema(include=("styles", ), instance=template, session=db.session) return jsonify(template_schema.dump(template))
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 add_stylesheet(template_id: int): template: Template = get_or_404( db.session.query(Template).filter_by(id=template_id)) template_schema = TemplateSchema(include=("styles", )) data = TemplateSchema.all_request_data() if isinstance(data, list): for entry in data: style: Stylesheet = get_or_404( db.session.query(Stylesheet).filter_by(**entry)) template.styles.append(style) else: style: Stylesheet = get_or_404( db.session.query(Stylesheet).filter_by(**data)) template.styles.append(style) db.session.commit() return jsonify(template_schema.dump(template))
def delete(template_id: int): return TemplateSchema.delete(template_id)
def get(template_id: int): return TemplateSchema.get(template_id)
def get_all(): return TemplateSchema.get_all()
def create(): return TemplateSchema.create()
def update(): return TemplateSchema.update()