From 80822469e46a7fdda25bbcbf92fe9ce10ca6cda4 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Tue, 12 Sep 2017 12:04:45 +0200 Subject: [PATCH] Improved error handling and solved a small bug --- server.py | 14 +++++++++++++- templates/error.htm | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 templates/error.htm diff --git a/server.py b/server.py index d42a954..b8568b5 100644 --- a/server.py +++ b/server.py @@ -445,6 +445,16 @@ def page_disp_add(): return render_template("dispositivo/add.htm", impiegati=impiegati, opzioni=opzioni, reti=reti, type="dev", user=session["username"], serial=serial) else: + if request.form["inv_ced"]: + try: + int(request.form["inv_ced"]) + except ValueError: + return render_template("error.htm", error="Il campo Inventario CED deve contenere un numero.") + if request.form["inv_ente"]: + try: + int(request.form["inv_ente"]) + except ValueError: + return render_template("error.htm", error="Il campo Inventario ente deve contenere un numero.") nuovodisp = Dispositivo(request.form['tipo'], request.form['marca'], request.form['modello'], request.form['inv_ced'], request.form['inv_ente'], request.form['fornitore'], request.form['rete'], request.form['seriale']) @@ -473,7 +483,9 @@ def page_disp_del(did): accetta richieste GET per cancellare il dispositivo specificato.""" if 'username' not in session: return redirect(url_for('page_login')) - disp = Dispositivo.query.get_or_404(did) + disp = Dispositivo.query.filter_by(did=did).join(Accesso).first_or_404() + for accesso in disp.accessi: + db.session.delete(accesso) db.session.delete(disp) db.session.commit() return redirect(url_for('page_disp_list')) diff --git a/templates/error.htm b/templates/error.htm new file mode 100644 index 0000000..f77783b --- /dev/null +++ b/templates/error.htm @@ -0,0 +1,18 @@ +{% extends 'base.htm' %} +{% block extrahead %} + +{% endblock %} +{% block content %} + +
+ Sarai reindirizzato alla pagina precedente entro 7 secondi. +
+{% endblock %} \ No newline at end of file