From 75984984dd7ff1e1b55eb250d69463fbad20d3e1 Mon Sep 17 00:00:00 2001 From: eclipse Date: Mon, 28 Apr 2025 10:29:43 +0200 Subject: [PATCH] minor code cleanup and improvements --- the_works/templates/views/werk.html | 13 ++++++++++--- the_works/views/werk.py | 4 ---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/the_works/templates/views/werk.html b/the_works/templates/views/werk.html index f2e6bbf..630207b 100644 --- a/the_works/templates/views/werk.html +++ b/the_works/templates/views/werk.html @@ -27,7 +27,14 @@ let id = this.dataset.id; let url = `${SCRIPT_ROOT}/werk/read/${id}`; 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( function (response) { // set modal heading @@ -44,7 +51,7 @@ document.getElementById("werkmodal").showModal(); } ) - .catch(console.log("all is lost :-(")); + .catch((error) => console.log(error)); } window.onload = function () { @@ -107,7 +114,7 @@
-

Detailansicht (Werk)

+

#

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