From 4f58b076b680d8f68c59e00b8ef0a74f4af58b0c Mon Sep 17 00:00:00 2001 From: eclipse Date: Fri, 2 May 2025 17:22:12 +0200 Subject: [PATCH] added support for DB tables "Genre" and "Pseudonym" --- the_works/__init__.py | 4 +- the_works/models.py | 5 ++ the_works/templates/_nav.html | 2 + the_works/templates/views/genre.html | 103 +++++++++++++++++++++++ the_works/templates/views/pseudonym.html | 103 +++++++++++++++++++++++ the_works/views/genre.py | 39 +++++++++ the_works/views/pseudonym.py | 39 +++++++++ 7 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 the_works/templates/views/genre.html create mode 100644 the_works/templates/views/pseudonym.html create mode 100644 the_works/views/genre.py create mode 100644 the_works/views/pseudonym.py diff --git a/the_works/__init__.py b/the_works/__init__.py index 6650682..969e344 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 + from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym app.register_blueprint(text.bp) app.register_blueprint(home.bp) app.register_blueprint(werk.bp) @@ -27,6 +27,8 @@ def create_app(): app.register_blueprint(sprache.bp) app.register_blueprint(textform.bp) app.register_blueprint(werksform.bp) + app.register_blueprint(genre.bp) + app.register_blueprint(pseudonym.bp) ### DEBUG toolbar = DebugToolbarExtension(app) diff --git a/the_works/models.py b/the_works/models.py index 99c942f..4f24982 100644 --- a/the_works/models.py +++ b/the_works/models.py @@ -42,4 +42,9 @@ class Werksform(db.Model): __table__ = db.Model.metadata.tables['Werksform'] werk = relationship("Werk", back_populates="werksform") +class Genre(db.Model): + __table__ = db.Model.metadata.tables['Genre'] + +class Pseudonym(db.Model): + __table__ = db.Model.metadata.tables['Pseudonym'] diff --git a/the_works/templates/_nav.html b/the_works/templates/_nav.html index 7c60f64..2fee435 100644 --- a/the_works/templates/_nav.html +++ b/the_works/templates/_nav.html @@ -16,5 +16,7 @@
  • Sprachen
  • Textformen
  • Werksformen
  • +
  • Genres
  • +
  • Pseudonyme
  • diff --git a/the_works/templates/views/genre.html b/the_works/templates/views/genre.html new file mode 100644 index 0000000..c33831c --- /dev/null +++ b/the_works/templates/views/genre.html @@ -0,0 +1,103 @@ +{% extends 'base.html' %} + +{% block title %}Genres{% endblock title %} + +{% block script %} +{% endblock script %} + +{% block heading %}Genres{% endblock heading %} + +{% block content %} + +{% include "_icons.svg" %} + + + + + + + + + + {% for genre in genres %} + + + + + + {% endfor %} + +
    GenreAktionen
    {{ genre["Genre"] }}
    + + +
    +
    +
    + +

    #

    +
    + +
    +
    + +
    +
    + +
    + + +
    +
    +
    +
    +{% endblock content %} \ No newline at end of file diff --git a/the_works/templates/views/pseudonym.html b/the_works/templates/views/pseudonym.html new file mode 100644 index 0000000..a8eeab9 --- /dev/null +++ b/the_works/templates/views/pseudonym.html @@ -0,0 +1,103 @@ +{% extends 'base.html' %} + +{% block title %}Pseudonyme{% endblock title %} + +{% block script %} +{% endblock script %} + +{% block heading %}Pseudonyme{% endblock heading %} + +{% block content %} + +{% include "_icons.svg" %} + + + + + + + + + + {% for pseudonym in pseudonyme %} + + + + + + {% endfor %} + +
    PseudonymAktionen
    {{ pseudonym["Pseudonym"] }}
    + + +
    +
    +
    + +

    #

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