From 02f9d7e61494e600dbbd7f4c35b7b81e1d7faae7 Mon Sep 17 00:00:00 2001 From: eclipse Date: Fri, 16 May 2025 16:11:28 +0200 Subject: [PATCH] added template and routes for DB table Veroeffentlichung --- the_works/__init__.py | 3 +- the_works/templates/_nav.html | 1 + .../templates/views/veroeffentlichung.html | 102 ++++++++++++++++++ the_works/views/veroeffentlichung.py | 59 ++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 the_works/templates/views/veroeffentlichung.html create mode 100644 the_works/views/veroeffentlichung.py diff --git a/the_works/__init__.py b/the_works/__init__.py index 5fb1b6f..f03e660 100644 --- a/the_works/__init__.py +++ b/the_works/__init__.py @@ -19,7 +19,7 @@ def create_app(): init_db(app) # register blueprints - from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe, herausgeber + from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe, herausgeber, veroeffentlichung app.register_blueprint(home.bp) app.register_blueprint(text.bp) app.register_blueprint(werk.bp) @@ -31,6 +31,7 @@ def create_app(): app.register_blueprint(pseudonym.bp) app.register_blueprint(reihe.bp) app.register_blueprint(herausgeber.bp) + app.register_blueprint(veroeffentlichung.bp) ### DEBUG toolbar = DebugToolbarExtension(app) diff --git a/the_works/templates/_nav.html b/the_works/templates/_nav.html index e7ff65c..779d0f9 100644 --- a/the_works/templates/_nav.html +++ b/the_works/templates/_nav.html @@ -1,6 +1,7 @@ {% set menu = ( ("Texte", url_for("text.all")), ("Werke", url_for("werk.all")), + ("Veröffentlichungen", url_for("veroeffentlichung.all")), ("Basisdaten", ( ("Genres", url_for("genre.all")), ("Herausgeber:innen", url_for("herausgeber.all")), diff --git a/the_works/templates/views/veroeffentlichung.html b/the_works/templates/views/veroeffentlichung.html new file mode 100644 index 0000000..36afce1 --- /dev/null +++ b/the_works/templates/views/veroeffentlichung.html @@ -0,0 +1,102 @@ +{% extends 'base.html' %} + +{% block title %}Veröffentlichungen{% endblock title %} + +{% block head %} + +{% endblock head %} + +{% block heading %}Veröffentlichungen{% endblock heading %} + +{% block content %} + +{% include "_icons.svg" %} + + + + + + + + + + + + + + {% for veroeffentlichung in veroeffentlichungen %} + + + + + + + + + + {% endfor %} + +
TextWerkAlt. TitelAlt. UntertitelPseudonymAktionen
{{ veroeffentlichung["Text"] }}{{ veroeffentlichung["Werk"] }}{{ veroeffentlichung["AltTitel"] }}{{ veroeffentlichung["AltUntertitel"] }}{{ veroeffentlichung["Pseudonym"] }}
+ + +
+
+
+ +

#

+
+ +
+
+ + + + + +
+
+ +
+ + +
+
+
+
+{% endblock content %} + +{% block script %} + + + +{% endblock script %} \ No newline at end of file diff --git a/the_works/views/veroeffentlichung.py b/the_works/views/veroeffentlichung.py new file mode 100644 index 0000000..6e8a22b --- /dev/null +++ b/the_works/views/veroeffentlichung.py @@ -0,0 +1,59 @@ +from flask import Blueprint, render_template, request, redirect, flash, url_for +from sqlalchemy import select, insert, update, delete +from the_works.database import db +from the_works.models import Veroeffentlichung, Text, Werk, Werksform, Pseudonym + +bp = Blueprint("veroeffentlichung", __name__) + +@bp.route("/veroeffentlichung") +@bp.route("/veroeffentlichung/all") +def all(): + rows = db.session.execute(select(Veroeffentlichung, Text, Werk, Werksform, Pseudonym).join(Veroeffentlichung.text, isouter=True).join(Veroeffentlichung.werk, isouter=True).join(Veroeffentlichung.pseudonym, isouter=True).join(Werk.werksform)) + veroeffentlichungen = [] + for row in rows: + veroeffentlichungen.append({ + "id": row.Veroeffentlichung.ID, + "Text": row.Text.Titel, + "t_id": row.Veroeffentlichung.Text, + "Werk": row.Werk.Titel + " [" + row.Werksform.Werksform + "]", + "w_id": row.Veroeffentlichung.Werk, + "AltTitel": row.Veroeffentlichung.AltTitel or "", + "AltUntertitel": row.Veroeffentlichung.AltUntertitel or "", + "Pseudonym": row.Pseudonym.Pseudonym, + "p_id": row.Veroeffentlichung.Pseudonym, + }) + return render_template("views/veroeffentlichung.html", veroeffentlichungen=veroeffentlichungen, texte=db.session.scalars(select(Text)), werke=db.session.scalars(select(Werk)), pseudonyme=db.session.scalars(select(Pseudonym))) + +@bp.route("/veroeffentlichung/create", methods=["POST"]) +def create(): + db.session.add(Veroeffentlichung( + Text = request.form["form_Text"], + Werk = request.form["form_Werk"], + AltTitel = request.form["form_AltTitel"], + AltUntertitel = request.form["form_AltUntertitel"], + Pseudonym = request.form["form_Pseudonym"], + )) + db.session.commit() + flash("Eintrag erfolgreich hinzugefügt") + return redirect(url_for("veroeffentlichung.all"), code=303) + +@bp.route("/veroeffentlichung/update/", methods=["POST"]) +def update(id): + veroeffentlichung = db.session.get(Veroeffentlichung, id) + veroeffentlichung.Text = request.form["form_Text"] + veroeffentlichung.Werk = request.form["form_Werk"] + veroeffentlichung.AltTitel = request.form["form_AltTitel"] + veroeffentlichung.AltUntertitel = request.form["form_AltUntertitel"] + veroeffentlichung.Pseudonym = request.form["form_Pseudonym"] + db.session.commit() + flash("Eintrag erfolgreich geändert") + return redirect(url_for("veroeffentlichung.all"), code=303) + +@bp.route("/veroeffentlichung/delete/") +def delete(id): + veroeffentlichung = db.session.get(Veroeffentlichung, id) + db.session.delete(veroeffentlichung) + db.session.commit() + flash("Eintrag erfolgreich gelöscht") + return redirect(url_for("veroeffentlichung.all")) +