예제 #1
0
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)
예제 #2
0
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),
    )
예제 #3
0
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),
    )
예제 #4
0
def delete(template_id: int):
    return StylesheetSchema.delete(template_id)
예제 #5
0
def get(template_id: int):
    return StylesheetSchema.get(template_id)
예제 #6
0
def get_all():
    return StylesheetSchema.get_all()
예제 #7
0
def create():
    return StylesheetSchema.create()
예제 #8
0
def update():
    return StylesheetSchema.update()