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

models: Add template field to Schild model

Also, remove obsolete methods.
parent fa5364a9
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ bp = Blueprint(
def schild_html(ident):
schild = db.get_or_404(Schild, ident)
# raise Exception
return bp.render_template("schild.html.j2", schild=schild)
return bp.render_template(schild.template, schild=schild)
@bp.route('/schild/<ident>.pdf')
......
import json
from pathlib import Path
from uuid import UUID
from uuid_extensions import uuid7
......@@ -11,20 +9,8 @@ from . import db
class Schild(db.Model):
ident: Mapped[UUID] = mapped_column(primary_key=True,
default=uuid7)
ident: Mapped[UUID] = mapped_column(primary_key=True, default=uuid7)
title: Mapped[str] = mapped_column(String(31))
text: Mapped[str] = mapped_column(Text)
image: Mapped[str] = mapped_column(String(255), nullable=True)
@classmethod
def from_file(cls, path):
path = Path(path)
with path.open() as fp:
content = json.load(fp)
return cls(ident=path.name, **content)
@classmethod
def get_all_schilder(cls, path: Path):
for f in path.glob("*.schild"):
yield cls.from_file(f)
template: Mapped[str] = mapped_column(String(255))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment