From c7fd91d11c56df6c53b3edbac7c52af91a538aa3 Mon Sep 17 00:00:00 2001 From: eclipse Date: Thu, 8 May 2025 08:24:12 +0200 Subject: [PATCH] switched from modal to dedicated page for creating/editing Text entries --- the_works/templates/views/text.html | 135 +++------------------ the_works/templates/views/text_detail.html | 83 +++++++++++++ the_works/views/text.py | 23 ++-- 3 files changed, 112 insertions(+), 129 deletions(-) create mode 100644 the_works/templates/views/text_detail.html diff --git a/the_works/templates/views/text.html b/the_works/templates/views/text.html index 9c0fb15..7da855d 100644 --- a/the_works/templates/views/text.html +++ b/the_works/templates/views/text.html @@ -5,47 +5,6 @@ {% block script %} {% endblock script %} @@ -91,77 +45,16 @@ {% for text in texte %} - {{ text["Titel"] }} - {{ text["Untertitel"] }} - {{ text["Reihe"] }} - {{ text["Textform"] }} - {{ text["Sprache"] }} - {{ text["Genre_list"] | join(SPLIT_CHARACTER) }} - + {{ text["Titel"] }} + {{ text["Untertitel"] }} + {{ text["Reihe"] }} + {{ text["Textform"] }} + {{ text["Sprache"] }} + {{ text["Genre_list"] | join(SPLIT_CHARACTER) }} + {% endfor %} - - -
-
-
- -

#

-
- -
-
- - - - - - -
-
- -
- - -
-
-
-
{% endblock content %} \ No newline at end of file diff --git a/the_works/templates/views/text_detail.html b/the_works/templates/views/text_detail.html new file mode 100644 index 0000000..f4480a1 --- /dev/null +++ b/the_works/templates/views/text_detail.html @@ -0,0 +1,83 @@ +{% extends 'base.html' %} +{% set create_mode = (text['ID'] == 0) %} + +{% block title %} +{% if create_mode %} +Neuen Text erstellen +{% else %} +Text bearbeiten +{% endif %} +{% endblock title %} + +{% block script %} + +{% endblock script %} + +{% block heading %} +{% if create_mode %} +Neuen Text erstellen +{% else %} +Text bearbeiten +{% endif %} +{% endblock heading %} + +{% block content %} +
+
+
+ + + + + +
+
+
+ Genre(s) +
+ {% for g in genres %} +
+ {{ loop.cycle('', '
' | safe) }} + {% endfor %} +
+
+
+
+ +
+ + + Abbrechen (nicht speichern) +
+
+{% endblock content %} \ No newline at end of file diff --git a/the_works/views/text.py b/the_works/views/text.py index da7731a..1c92724 100644 --- a/the_works/views/text.py +++ b/the_works/views/text.py @@ -27,18 +27,25 @@ def all(): "Genre_list": map(lambda tg: tg.genre.Genre, row.Text.text_genre) if row.Text.text_genre else [], "g_id_list": map(lambda tg: tg.Genre, row.Text.text_genre) if row.Text.text_genre else [] }) - 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)), genres=db.session.scalars(select(Genre))) + return render_template("views/text.html", texte=texte) @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 + # id of zero -> create new entry + if id == 0: + return render_template("views/text_detail.html", text={"ID": 0}, reihen=db.session.scalars(select(Reihe)), textformen=db.session.scalars(select(Textform)), sprachen=db.session.scalars(select(Sprache)), genres=db.session.scalars(select(Genre))) + # all other ids -> update existing entry + t = db.session.get(Text, id) + text = { + "ID": t.ID, + "Titel": t.Titel, + "Untertitel": t.Untertitel or "", + "Reihe": t.Reihe or "", + "Textform": t.Textform, + "Sprache": t.Sprache, + "Genres": t.genres or [] } + return render_template("views/text_detail.html", text=text, reihen=db.session.scalars(select(Reihe)), textformen=db.session.scalars(select(Textform)), sprachen=db.session.scalars(select(Sprache)), genres=db.session.scalars(select(Genre))) @bp.route("/text/create", methods=["POST"]) def create():