From a687076b40b34b51467f50bf992165d3f73e02eb Mon Sep 17 00:00:00 2001
From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de>
Date: Thu, 5 Sep 2024 15:16:31 +0200
Subject: [PATCH] models: Add template field to Schild model

Also, remove obsolete methods.
---
 schilder2000/instance.py |  2 +-
 schilder2000/models.py   | 18 ++----------------
 2 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/schilder2000/instance.py b/schilder2000/instance.py
index be9d332..5f77d66 100644
--- a/schilder2000/instance.py
+++ b/schilder2000/instance.py
@@ -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')
diff --git a/schilder2000/models.py b/schilder2000/models.py
index d095df0..0935671 100644
--- a/schilder2000/models.py
+++ b/schilder2000/models.py
@@ -1,5 +1,3 @@
-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))
-- 
GitLab