49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
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 Reihe, Verlag
|
|
|
|
bp = Blueprint("reihe", __name__)
|
|
|
|
@bp.route("/reihe")
|
|
@bp.route("/reihe/all")
|
|
def all():
|
|
rows = db.session.execute(select(Reihe, Verlag).join(Reihe.verlag, isouter=True))
|
|
reihen = []
|
|
for row in rows:
|
|
reihen.append({
|
|
"id": row.Reihe.ID,
|
|
"Titel": row.Reihe.Titel,
|
|
"Verlag": row.Verlag.Verlag if row.Verlag else "",
|
|
"v_id": row.Reihe.Verlag or ""
|
|
})
|
|
return render_template("views/reihe.html", reihen=reihen, verlage=db.session.scalars(select(Verlag)))
|
|
|
|
@bp.route("/reihe/create", methods=["POST"])
|
|
def create():
|
|
db.session.add(Reihe(
|
|
Titel = request.form["form_Titel"],
|
|
Verlag = request.form["form_Verlag"]
|
|
))
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich hinzugefügt")
|
|
return redirect(url_for("reihe.all"), code=303)
|
|
|
|
@bp.route("/reihe/update/<int:id>", methods=["POST"])
|
|
def update(id):
|
|
reihe = db.session.get(Reihe, id)
|
|
reihe.Titel = request.form["form_Titel"]
|
|
reihe.Verlag = request.form["form_Verlag"]
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich geändert")
|
|
return redirect(url_for("reihe.all"), code=303)
|
|
|
|
@bp.route("/reihe/delete/<int:id>")
|
|
def delete(id):
|
|
reihe = db.session.get(Reihe, id)
|
|
db.session.delete(reihe)
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich gelöscht")
|
|
return redirect(url_for("reihe.all"))
|
|
|