minor code cleanup and improvements

This commit is contained in:
eclipse 2025-04-28 10:29:43 +02:00
parent 1eac044e4b
commit 75984984dd
2 changed files with 10 additions and 7 deletions

View File

@ -27,7 +27,14 @@
let id = this.dataset.id; let id = this.dataset.id;
let url = `${SCRIPT_ROOT}/werk/read/${id}`; let url = `${SCRIPT_ROOT}/werk/read/${id}`;
fetch(url) fetch(url)
.then(response => response.json()) // throw error if network error occurred, get JSON data otherwise
.then((response) => {
if (response.ok) {
return response.json();
}
throw new Error ("There was an error while fetching data for the text with ID " + id);
})
// populate modal with response data and raise modal
.then( .then(
function (response) { function (response) {
// set modal heading // set modal heading
@ -44,7 +51,7 @@
document.getElementById("werkmodal").showModal(); document.getElementById("werkmodal").showModal();
} }
) )
.catch(console.log("all is lost :-(")); .catch((error) => console.log(error));
} }
window.onload = function () { window.onload = function () {
@ -107,7 +114,7 @@
<form id="werk_detail_form" method="post" enctype="multipart/form-data" action="#" readonly> <form id="werk_detail_form" method="post" enctype="multipart/form-data" action="#" readonly>
<header> <header>
<button aria-label="close" rel="prev" onclick="werkmodal.close()"></button> <button aria-label="close" rel="prev" onclick="werkmodal.close()"></button>
<h1 id="dialog-heading">Detailansicht (Werk)</h1> <h1 id="dialog-heading">#</h1>
</header> </header>
<fieldset> <fieldset>

View File

@ -5,8 +5,6 @@ from the_works.models import Werk, Reihe, Verlag, Werksform
bp = Blueprint("werk", __name__) bp = Blueprint("werk", __name__)
@bp.route("/werk") @bp.route("/werk")
@bp.route("/werk/all") @bp.route("/werk/all")
def all(): def all():
@ -74,7 +72,6 @@ def create():
def update(id): def update(id):
# get record # get record
werk = db.session.get(Werk, id) werk = db.session.get(Werk, id)
print(werk)
# update values # update values
werk.Titel = request.form["form_Titel"] werk.Titel = request.form["form_Titel"]
werk.Untertitel = request.form["form_Untertitel"] or None werk.Untertitel = request.form["form_Untertitel"] or None
@ -95,7 +92,6 @@ def update(id):
flash("Eintrag erfolgreich geändert") flash("Eintrag erfolgreich geändert")
return redirect(url_for("werk.all")) return redirect(url_for("werk.all"))
@bp.route("/werk/delete/<int:id>") @bp.route("/werk/delete/<int:id>")
def delete(id): def delete(id):
werk = db.session.get(Werk, id) werk = db.session.get(Werk, id)