From 1eac044e4b1b3c54022086e5adc90e34b4432ae7 Mon Sep 17 00:00:00 2001 From: eclipse Date: Mon, 28 Apr 2025 10:29:24 +0200 Subject: [PATCH] applied latest improvements (fetch API, dedicated "read" endpoint, DataTables) from werk.py|html to corresponding text.* --- the_works/templates/views/_text.js | 23 ---- the_works/templates/views/text.html | 194 +++++++++++++++++----------- the_works/views/text.py | 32 +++-- 3 files changed, 141 insertions(+), 108 deletions(-) delete mode 100644 the_works/templates/views/_text.js diff --git a/the_works/templates/views/_text.js b/the_works/templates/views/_text.js deleted file mode 100644 index db0a41f..0000000 --- a/the_works/templates/views/_text.js +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/the_works/templates/views/text.html b/the_works/templates/views/text.html index c912d3c..8e64e4c 100644 --- a/the_works/templates/views/text.html +++ b/the_works/templates/views/text.html @@ -2,53 +2,115 @@ {% block title %}Texte{% endblock title %} +{% block script %}{% endblock script %} + {% block heading %}Texte{% endblock heading %} {% block content %} {% include "_icons.svg" %} -{% include "views/_text.js" %} +
+ +
-
- -
- - - - - - - - - - - - - - {% for text in texte %} - - - - - - - - - - {% endfor %} - -
TitelUntertitelReiheTextformSpracheAktionen
{{ text["Titel"] }}{{ text["Untertitel"] }}{{ text["Reihe"] }}{{ text["Textform"] }}{{ text["Sprache"] }}
+ + + + + + + + + + + + + {% for text in texte %} + + + + + + + + + + {% endfor %} + +
TitelUntertitelReiheTextformSpracheAktionen
{{ text["Titel"] }}{{ text["Untertitel"] }}{{ text["Reihe"] }}{{ text["Textform"] }}{{ text["Sprache"] }}
-
+
-

Neuer Text

+

#

@@ -57,43 +119,31 @@ Titel (erforderlich) -
- -
-
- Untertitel und Reihe - - -
-
- -
-
- Textform und Sprache - - -
+ + + +
diff --git a/the_works/views/text.py b/the_works/views/text.py index 91d8da7..370d2e8 100644 --- a/the_works/views/text.py +++ b/the_works/views/text.py @@ -8,30 +8,36 @@ bp = Blueprint("text", __name__) @bp.route("/text") @bp.route("/text/all") def all(): - # build ORM equivalent of SELECT statement - stmt = ( - select(Text, Reihe, Textform, Sprache) - .join(Text.reihe, isouter=True) - .join(Text.textform, isouter=True) - .join(Text.sprache, isouter=True) - ) + # select all rows from table "Text", ORM style + rows = db.session.execute(select(Text, Reihe, Textform, Sprache).join(Text.reihe, isouter=True).join(Text.textform, isouter=True).join(Text.sprache, isouter=True)) # condense result into list of dicts texte = [] - for row in db.session.execute(stmt): + for row in rows: texte.append({ "id": row.Text.ID, "Titel": row.Text.Titel, "Untertitel": row.Text.Untertitel or "", "Reihe": row.Reihe.Titel if row.Reihe else "", - "r_id": str(row.Reihe.ID) if row.Reihe else "", - "Textform": row.Textform.Textform if row.Textform else "", - "tf_id": str(row.Textform.ID) if row.Textform else "", + "r_id": row.Text.Reihe or "", + "Textform": row.Textform.Textform, + "tf_id": row.Text.Textform, "Sprache": row.Sprache.Sprache, - "s_id": str(row.Sprache.ID) if row.Sprache else "" + "s_id": row.Text.Sprache }) return render_template("views/text.html", texte=texte, reihen=db.session.scalars(select(Reihe)), textformen=db.session.scalars(select(Textform)), sprachen=db.session.scalars(select(Sprache))) -@bp.route("/text", methods=["POST"]) +@bp.route("/text/read/") +def read(id): + text = db.session.get(Text, id) + return { + "Titel": text.Titel, + "Untertitel": text.Untertitel or "", + "Reihe": text.Reihe or "", + "Textform": text.Textform, + "Sprache": text.Sprache + } + +@bp.route("/text/create", methods=["POST"]) def create(): db.session.add(Text( Titel = request.form["form_Titel"],