Skip to content
Snippets Groups Projects
Commit 2ad0c556 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Add instance.list_templates and template selection in the schild view

parent 0d8546d6
Branches
No related tags found
No related merge requests found
from . import db from . import db
from .models import Schild from .models import Schild
from .helpers import Blueprint from .helpers import Blueprint, get_template_attribute
from flask import url_for from flask import url_for
...@@ -25,3 +25,20 @@ def schild_html(ident): ...@@ -25,3 +25,20 @@ def schild_html(ident):
@bp.route("/schild/<ident>.pdf") @bp.route("/schild/<ident>.pdf")
def schild_pdf(ident): def schild_pdf(ident):
return render_pdf(url_for(".schild_html", ident=ident)) return render_pdf(url_for(".schild_html", ident=ident))
def list_templates():
schild = Schild()
loader = bp.jinja_loader
for t in loader.list_templates():
if t.startswith("_"):
continue
yield dict(
name=t,
description=get_template_attribute(
bp.real_template_name(t),
"description",
vars=dict(schild=schild),
default=None,
),
)
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
{%- for field in form -%} {%- for field in form -%}
{{ render_field(field) }} {{ render_field(field) }}
{%- endfor -%} {%- endfor -%}
<select name="template">
{%- for t in templates -%}
<option value="{{ t.name }}">
{{ t.description or t.name }}
</option>
{% endfor %}
</select>
<div class="box"> <div class="box">
<input type="submit" value="Schild erstellen" /> <input type="submit" value="Schild erstellen" />
</div> </div>
......
from . import db from . import db
from .instance import list_templates
from .models import Schild from .models import Schild
from flask import Blueprint, render_template, request, redirect, url_for from flask import Blueprint, render_template, request, redirect, url_for
...@@ -30,7 +31,7 @@ def schild(ident): ...@@ -30,7 +31,7 @@ def schild(ident):
db.session.commit() db.session.commit()
else: else:
form = SchildForm(obj=schild) form = SchildForm(obj=schild)
return render_template("schild.html.j2", schild=schild, form=form) return render_template("schild.html.j2", schild=schild, form=form, templates=list_templates())
@bp.route("/create", methods=["GET", "POST"]) @bp.route("/create", methods=["GET", "POST"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment