1
Fork 0
mirror of https://github.com/Steffo99/estus.git synced 2024-11-21 23:24:18 +00:00

Improved error handling and solved a small bug

This commit is contained in:
Steffo 2017-09-12 12:04:45 +02:00
parent 762d8f4eeb
commit 80822469e4
2 changed files with 31 additions and 1 deletions

View file

@ -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'))

18
templates/error.htm Normal file
View file

@ -0,0 +1,18 @@
{% extends 'base.htm' %}
{% block extrahead %}
<script>
window.onload = function() {
setTimeout(function() {
window.history.back();
}, 7000)
}
</script>
{% endblock %}
{% block content %}
<div class="alert alert-danger" role="alert">
<b>ERRORE:</b> {{ error }}
</div>
<div>
Sarai reindirizzato alla pagina precedente entro 7 secondi.
</div>
{% endblock %}