From d86043dc5baf2e3d0db3be72e723624461970e9a Mon Sep 17 00:00:00 2001 From: eclipse Date: Fri, 2 May 2025 18:18:12 +0200 Subject: [PATCH] added support for DB table "Herausgeber" --- the_works/__init__.py | 5 +- the_works/models.py | 2 + the_works/templates/_nav.html | 1 + the_works/templates/views/herausgeber.html | 103 +++++++++++++++++++++ the_works/views/herausgeber.py | 39 ++++++++ 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 the_works/templates/views/herausgeber.html create mode 100644 the_works/views/herausgeber.py diff --git a/the_works/__init__.py b/the_works/__init__.py index 7caf733..53d740c 100644 --- a/the_works/__init__.py +++ b/the_works/__init__.py @@ -19,9 +19,9 @@ def create_app(): init_db(app) # register blueprints - from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe - app.register_blueprint(text.bp) + from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe, herausgeber app.register_blueprint(home.bp) + app.register_blueprint(text.bp) app.register_blueprint(werk.bp) app.register_blueprint(verlag.bp) app.register_blueprint(sprache.bp) @@ -30,6 +30,7 @@ def create_app(): app.register_blueprint(genre.bp) app.register_blueprint(pseudonym.bp) app.register_blueprint(reihe.bp) + app.register_blueprint(herausgeber.bp) ### DEBUG toolbar = DebugToolbarExtension(app) diff --git a/the_works/models.py b/the_works/models.py index 4f24982..47ec3c9 100644 --- a/the_works/models.py +++ b/the_works/models.py @@ -48,3 +48,5 @@ class Genre(db.Model): class Pseudonym(db.Model): __table__ = db.Model.metadata.tables['Pseudonym'] +class Herausgeber(db.Model): + __table__ = db.Model.metadata.tables['Herausgeber'] diff --git a/the_works/templates/_nav.html b/the_works/templates/_nav.html index 1f78b13..d533729 100644 --- a/the_works/templates/_nav.html +++ b/the_works/templates/_nav.html @@ -19,5 +19,6 @@
  • Genres
  • Pseudonyme
  • Reihen
  • +
  • Herausgeber:innen
  • diff --git a/the_works/templates/views/herausgeber.html b/the_works/templates/views/herausgeber.html new file mode 100644 index 0000000..031ad3f --- /dev/null +++ b/the_works/templates/views/herausgeber.html @@ -0,0 +1,103 @@ +{% extends 'base.html' %} + +{% block title %}Herausgeber:innen{% endblock title %} + +{% block script %} +{% endblock script %} + +{% block heading %}Herausgeber:innen{% endblock heading %} + +{% block content %} + +{% include "_icons.svg" %} + + + + + + + + + + {% for hrsg in herausgeber %} + + + + + + {% endfor %} + +
    NameAktionen
    {{ hrsg["Name"] }}
    + + +
    +
    +
    + +

    #

    +
    + +
    +
    + +
    +
    + +
    + + +
    +
    +
    +
    +{% endblock content %} \ No newline at end of file diff --git a/the_works/views/herausgeber.py b/the_works/views/herausgeber.py new file mode 100644 index 0000000..a037f63 --- /dev/null +++ b/the_works/views/herausgeber.py @@ -0,0 +1,39 @@ +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 Herausgeber + +bp = Blueprint("herausgeber", __name__) + +@bp.route("/herausgeber") +@bp.route("/herausgeber/all") +def all(): + return render_template("views/herausgeber.html", herausgeber=db.session.scalars(select(Herausgeber))) + +@bp.route("/text/herausgeber/") +def read(id): + return db.session.get(Herausgeber, id) + +@bp.route("/herausgeber/create", methods=["POST"]) +def create(): + db.session.add(Herausgeber(Name = request.form["form_Name"])) + db.session.commit() + flash("Eintrag erfolgreich hinzugefügt") + return redirect(url_for("herausgeber.all"), code=303) + +@bp.route("/herausgeber/update/", methods=["POST"]) +def update(id): + herausgeber = db.session.get(Herausgeber, id) + herausgeber.Name = request.form["form_Name"] + db.session.commit() + flash("Eintrag erfolgreich geändert") + return redirect(url_for("herausgeber.all"), code=303) + +@bp.route("/herausgeber/delete/") +def delete(id): + herausgeber = db.session.get(Herausgeber, id) + db.session.delete(herausgeber) + db.session.commit() + flash("Eintrag erfolgreich gelöscht") + return redirect(url_for("herausgeber.all")) +