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( ...@@ -19,7 +19,7 @@ bp = Blueprint(
def schild_html(ident): def schild_html(ident):
schild = db.get_or_404(Schild, ident) schild = db.get_or_404(Schild, ident)
# raise Exception # raise Exception
return bp.render_template("schild.html.j2", schild=schild) return bp.render_template(schild.template, schild=schild)
@bp.route('/schild/<ident>.pdf') @bp.route('/schild/<ident>.pdf')
......
import json
from pathlib import Path
from uuid import UUID from uuid import UUID
from uuid_extensions import uuid7 from uuid_extensions import uuid7
...@@ -11,20 +9,8 @@ from . import db ...@@ -11,20 +9,8 @@ from . import db
class Schild(db.Model): class Schild(db.Model):
ident: Mapped[UUID] = mapped_column(primary_key=True, ident: Mapped[UUID] = mapped_column(primary_key=True, default=uuid7)
default=uuid7)
title: Mapped[str] = mapped_column(String(31)) title: Mapped[str] = mapped_column(String(31))
text: Mapped[str] = mapped_column(Text) text: Mapped[str] = mapped_column(Text)
image: Mapped[str] = mapped_column(String(255), nullable=True) image: Mapped[str] = mapped_column(String(255), nullable=True)
template: Mapped[str] = mapped_column(String(255))
@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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment