From 055cbf207b21fae3cf4298dfbc2707d70d11b3a1 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 11 Sep 2017 15:00:04 +0200 Subject: [PATCH] Fix bugs in Dispositivo --- server.py | 35 +++++++++++++++++++++++++++---- templates/dispositivo/details.htm | 15 +++++++++++++ templates/dispositivo/list.htm | 5 ++--- templates/impiegato/list.htm | 4 ++-- 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 templates/dispositivo/details.htm diff --git a/server.py b/server.py index 0df84ff..7a1592a 100644 --- a/server.py +++ b/server.py @@ -1,6 +1,7 @@ from flask import Flask, session, url_for, redirect, request, render_template, abort from flask_sqlalchemy import SQLAlchemy import bcrypt +import os app = Flask(__name__) app.secret_key = "pepsecret" @@ -106,6 +107,16 @@ class Accesso(db.Model): return "".format(self.iid, self.did) +class FakeAccesso: + def __init__(self, dispositivo): + self.did = dispositivo.did + self.iid = None + self.dispositivo = dispositivo + + def __getitem__(self, key): + if key == 0: + return self.dispositivo + # Funzioni del sito def login(username, password): user = User.query.filter_by(username=username).first() @@ -246,6 +257,15 @@ def page_serv_list(): return render_template("servizio/list.htm", css=css, serv=serv, type="serv", user=session["username"]) +@app.route('/serv_list/') +def page_serv_list_plus(eid): + if 'username' not in session: + return redirect(url_for('page_login')) + serv = Servizio.query.join(Ente).filter_by(eid=eid).all() + css = url_for("static", filename="style.css") + return render_template("servizio/list.htm", css=css, serv=serv, type="serv", user=session["username"]) + + @app.route('/serv_show/', methods=['GET', 'POST']) def page_serv_show(sid): if 'username' not in session: @@ -377,14 +397,21 @@ def page_disp_list(): dispositivi = Dispositivo.query.all() for dispositivo in dispositivi: accesso = Accesso.query.join(Dispositivo).filter_by(did=dispositivo.did).join(Impiegato).all() - accessi.append(accesso) + if not accesso: + accessi.append([FakeAccesso(dispositivo)]) + else: + accessi.append(accesso) css = url_for("static", filename="style.css") return render_template("dispositivo/list.htm", css=css, accessi=accessi, type="disp", user=session["username"]) -@app.route('/disp_details') -def page_details_host(): - raise NotImplementedError() +@app.route('/disp_details/') +def page_details_host(did): + if 'username' not in session: + return redirect(url_for('page_login')) + disp = Dispositivo.query.get(did) + css = url_for("static", filename="style.css") + return render_template("dispositivo/details.htm", css=css, disp=disp, type="disp", user=session["username"]) if __name__ == "__main__": diff --git a/templates/dispositivo/details.htm b/templates/dispositivo/details.htm new file mode 100644 index 0000000..1c70c5b --- /dev/null +++ b/templates/dispositivo/details.htm @@ -0,0 +1,15 @@ +{% extends "base.htm" %} +{% block content %} +
    + {% for ente in conteggioservizi %} +
  • +
    + Sassi +
    +
    + 10 +
    +
  • + {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/templates/dispositivo/list.htm b/templates/dispositivo/list.htm index ae21d33..3d994a7 100644 --- a/templates/dispositivo/list.htm +++ b/templates/dispositivo/list.htm @@ -1,5 +1,4 @@ {% extends "base.htm" %} -{% block title %}Elenco dispositivi{% endblock %} {% block content %}

Dispositivi esistenti @@ -27,8 +26,8 @@ {{ d[0].dispositivo.marca }} {{ d[0].dispositivo.modello }} {{ d[0].dispositivo.fornitore }} - - + + {% endfor %} diff --git a/templates/impiegato/list.htm b/templates/impiegato/list.htm index 9fedb2b..e5147ea 100644 --- a/templates/impiegato/list.htm +++ b/templates/impiegato/list.htm @@ -21,8 +21,8 @@ {{ imp.servizio.ente.nomeente }} {{ imp.servizio.nomeservizio }} {{ imp.nomeimpiegato }} - {{ imp.username }} - {{ imp.passwd }} + {{ imp.username }} + {{ imp.passwd }}