40 lines
1.2 KiB
Python
40 lines
1.2 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 Sprache
|
|
|
|
bp = Blueprint("sprache", __name__)
|
|
|
|
@bp.route("/sprache")
|
|
@bp.route("/sprache/all")
|
|
def all():
|
|
return render_template("views/sprache.html", sprachen=db.session.scalars(select(Sprache)))
|
|
|
|
@bp.route("/sprache/verlag/<int:id>")
|
|
def read(id):
|
|
return db.session.get(Sprache, id)
|
|
|
|
@bp.route("/sprache/create", methods=["POST"])
|
|
def create():
|
|
db.session.add(Sprache(Sprache = request.form["form_Sprache"]))
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich hinzugefügt")
|
|
return redirect(url_for("sprache.all"))
|
|
|
|
@bp.route("/sprache/update/<int:id>", methods=["POST"])
|
|
def update(id):
|
|
sprache = db.session.get(Sprache, id)
|
|
sprache.Sprache = request.form["form_Sprache"]
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich geändert")
|
|
return redirect(url_for("sprache.all"))
|
|
|
|
@bp.route("/sprache/delete/<int:id>")
|
|
def delete(id):
|
|
sprache = db.session.get(Sprache, id)
|
|
db.session.delete(sprache)
|
|
db.session.commit()
|
|
flash("Eintrag erfolgreich gelöscht")
|
|
return redirect(url_for("sprache.all"))
|
|
|