From 1e761cdbf48e5e08163bf1533e0725abbd99dc4a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 1 Feb 2017 10:37:53 +0100 Subject: [PATCH] =?UTF-8?q?Ora=20vanno=20un=20po'=20di=20cose=20in=20pi?= =?UTF-8?q?=C3=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per la precisione: enti servizi impiegati --- dbgen.py | 8 +- server.py | 167 ++++++++++++++++++++++++++----- static/style.css | 22 +--- templates/ente/add.html.j2 | 19 ++++ templates/ente/list.html.j2 | 37 +++++++ templates/ente/show.html.j2 | 19 ++++ templates/ente_add.html.j2 | 19 ---- templates/ente_list.html.j2 | 24 ----- templates/ente_show.html.j2 | 19 ---- templates/impiegato/add.html.j2 | 25 +++++ templates/impiegato/list.html.j2 | 39 ++++++++ templates/impiegato/show.html.j2 | 25 +++++ templates/login.html.j2 | 14 +-- templates/servizio/add.html.j2 | 23 +++++ templates/servizio/list.html.j2 | 35 +++++++ templates/servizio/show.html.j2 | 23 +++++ templates/user_add.html.j2 | 20 ---- 17 files changed, 401 insertions(+), 137 deletions(-) create mode 100644 templates/ente/add.html.j2 create mode 100644 templates/ente/list.html.j2 create mode 100644 templates/ente/show.html.j2 delete mode 100644 templates/ente_add.html.j2 delete mode 100644 templates/ente_list.html.j2 delete mode 100644 templates/ente_show.html.j2 create mode 100644 templates/impiegato/add.html.j2 create mode 100644 templates/impiegato/list.html.j2 create mode 100644 templates/impiegato/show.html.j2 create mode 100644 templates/servizio/add.html.j2 create mode 100644 templates/servizio/list.html.j2 create mode 100644 templates/servizio/show.html.j2 delete mode 100644 templates/user_add.html.j2 diff --git a/dbgen.py b/dbgen.py index 93f3ee5..799146a 100644 --- a/dbgen.py +++ b/dbgen.py @@ -23,8 +23,8 @@ class User(db.Model): # Ente (Unione Terre di Castelli, Comune di Vignola...) class Ente(db.Model): eid = db.Column(db.Integer, primary_key=True) - nome = db.Column(db.String(64)) - nomebreve = db.Column(db.String(16)) + nomeente = db.Column(db.String(64)) + nomebreveente = db.Column(db.String(16)) servizi = db.relationship("Servizio", backref='ente', lazy='dynamic') def __init__(self, nome, nomebreve): @@ -39,7 +39,7 @@ class Ente(db.Model): class Servizio(db.Model): sid = db.Column(db.Integer, primary_key=True) eid = db.Column(db.Integer, db.ForeignKey('ente.eid')) - nome = db.Column(db.String(128)) + nomeservizio = db.Column(db.String(128)) impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic') def __init__(self, eid, nome): @@ -53,7 +53,7 @@ class Servizio(db.Model): class Impiegato(db.Model): iid = db.Column(db.Integer, primary_key=True) sid = db.Column(db.Integer, db.ForeignKey('servizio.sid')) - nome = db.Column(db.String(128)) + nomeimpiegato = db.Column(db.String(128)) username = db.Column(db.String(32), unique=True) passwd = db.Column(db.String(32)) diff --git a/server.py b/server.py index ceb393c..345f956 100644 --- a/server.py +++ b/server.py @@ -1,8 +1,8 @@ -from flask import Flask, render_template, request, url_for, session, redirect, jsonify +from flask import Flask, session, url_for, redirect, request, render_template from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) -app.secret_key = 'itsapepperonisecret' +app.secret_key = "pepsecret" # SQL app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' @@ -24,48 +24,48 @@ class User(db.Model): # Ente (Unione Terre di Castelli, Comune di Vignola...) class Ente(db.Model): eid = db.Column(db.Integer, primary_key=True) - nome = db.Column(db.String(64)) - nomebreve = db.Column(db.String(16)) + nomeente = db.Column(db.String(64)) + nomebreveente = db.Column(db.String(16)) servizi = db.relationship("Servizio", backref='ente', lazy='dynamic') - def __init__(self, nome, nomebreve): - self.nome = nome - self.nomebreve = nomebreve + def __init__(self, nomeente, nomebreveente): + self.nomeente = nomeente + self.nomebreveente = nomebreveente def __repr__(self): - return "".format(self.nomebreve) + return "".format(self.nomebreveente) # Servizio di un ente class Servizio(db.Model): sid = db.Column(db.Integer, primary_key=True) eid = db.Column(db.Integer, db.ForeignKey('ente.eid')) - nome = db.Column(db.String(128)) + nomeservizio = db.Column(db.String(128)) impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic') - def __init__(self, eid, nome): + def __init__(self, eid, nomeservizio): self.eid = eid - self.nome = nome + self.nomeservizio = nomeservizio def __repr__(self): - return "".format(self.nome) + return "".format(self.nomeservizio) class Impiegato(db.Model): iid = db.Column(db.Integer, primary_key=True) sid = db.Column(db.Integer, db.ForeignKey('servizio.sid')) - nome = db.Column(db.String(128)) + nomeimpiegato = db.Column(db.String(128)) username = db.Column(db.String(32), unique=True) passwd = db.Column(db.String(32)) - def __init__(self, sid, nome, username, passwd): + def __init__(self, sid, nomeimpiegato, username, passwd): self.sid = sid - self.nome = nome + self.nomeimpiegato = nomeimpiegato self.username = username self.passwd = passwd def __repr__(self): - return "".format(self.nome) + return "".format(self.nomeimpiegato) # Funzioni del sito def login(username, password): @@ -103,12 +103,10 @@ def page_ente_add(): if 'username' not in session: return redirect(url_for('page_login')) if request.method == 'GET': - # Visualizza la pagina di creazione ente css = url_for("static", filename="style.css") - return render_template("ente_add.html.j2", css=css) + return render_template("ente/add.html.j2", css=css) else: - # Crea un nuovo ente - nuovoent = Ente(request.form['nome'], request.form['nomebreve']) + nuovoent = Ente(request.form['nomeente'], request.form['nomebreveente']) db.session.add(nuovoent) db.session.commit() return redirect(url_for('page_ente_list')) @@ -118,6 +116,12 @@ def page_ente_del(eid): if 'username' not in session: return redirect(url_for('page_login')) ente = Ente.query.get(eid) + servizi = Servizio.query.filter_by(eid=ente.eid).all() + for serv in servizi: + impiegati = Impiegato.query.filter_by(sid=serv.sid).all() + for imp in impiegati: + db.session.delete(imp) + db.session.delete(serv) db.session.delete(ente) db.session.commit() return redirect(url_for('page_ente_list')) @@ -128,7 +132,7 @@ def page_ente_list(): return redirect(url_for('page_login')) enti = Ente.query.all() css = url_for("static", filename="style.css") - return render_template("ente_list.html.j2", css=css, enti=enti) + return render_template("ente/list.html.j2", css=css, enti=enti) @app.route('/ente_show/', methods=['GET', 'POST']) def page_ente_show(eid): @@ -137,10 +141,125 @@ def page_ente_show(eid): if request.method == "GET": ente = Ente.query.get(eid) css = url_for("static", filename="style.css") - return render_template("ente_show.html.j2", css=css, ente=ente) + return render_template("ente/show.html.j2", css=css, ente=ente) else: ente = Ente.query.get(eid) - ente.nome = request.form["nome"] - ente.nomebreve = request.form["nomebreve"] + ente.nomeente = request.form["nomeente"] + ente.nomebreveente = request.form["nomebreveente"] db.session.commit() return redirect(url_for('page_ente_list')) + +@app.route('/serv_add', methods=['GET', 'POST']) +def page_serv_add(): + if 'username' not in session: + return redirect(url_for('page_login')) + if request.method == 'GET': + enti = Ente.query.all() + css = url_for("static", filename="style.css") + return render_template("servizio/add.html.j2", css=css, enti=enti) + else: + nuovoserv = Servizio(request.form['eid'], request.form['nomeservizio']) + db.session.add(nuovoserv) + db.session.commit() + return redirect(url_for('page_serv_list')) + +@app.route('/serv_del/') +def page_serv_del(sid): + if 'username' not in session: + return redirect(url_for('page_login')) + serv = Servizio.query.get(sid) + impiegati = Impiegato.query.filter_by(sid=serv.sid).all() + for imp in impiegati: + db.session.delete(imp) + db.session.delete(serv) + db.session.commit() + return redirect(url_for('page_serv_list')) + +@app.route('/serv_list') +def page_serv_list(): + if 'username' not in session: + return redirect(url_for('page_login')) + serv = Servizio.query.join(Ente).all() + css = url_for("static", filename="style.css") + return render_template("servizio/list.html.j2", css=css, serv=serv) + +@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.html.j2", css=css, serv=serv) + +@app.route('/serv_show/', methods=['GET', 'POST']) +def page_serv_show(sid): + if 'username' not in session: + return redirect(url_for('page_login')) + if request.method == "GET": + serv = Servizio.query.get(sid) + enti = Ente.query.all() + css = url_for("static", filename="style.css") + return render_template("servizio/show.html.j2", css=css, serv=serv, enti=enti) + else: + serv = Servizio.query.get(sid) + serv.eid = request.form["eid"] + serv.nomeservizio = request.form["nomeservizio"] + db.session.commit() + return redirect(url_for('page_serv_list')) + +@app.route('/imp_add', methods=['GET', 'POST']) +def page_imp_add(): + if 'username' not in session: + return redirect(url_for('page_login')) + if request.method == 'GET': + servizi = Servizio.query.all() + css = url_for("static", filename="style.css") + return render_template("impiegato/add.html.j2", css=css, servizi=servizi) + else: + nuovoimp = Impiegato(request.form['sid'], request.form['nomeimpiegato'], request.form['username'], request.form['passwd'],) + db.session.add(nuovoimp) + db.session.commit() + return redirect(url_for('page_imp_list')) + +@app.route('/imp_del/') +def page_imp_del(iid): + if 'username' not in session: + return redirect(url_for('page_login')) + imp = Impiegato.query.get(iid) + db.session.delete(imp) + db.session.commit() + return redirect(url_for('page_imp_list')) + +@app.route('/imp_list') +def page_imp_list(): + if 'username' not in session: + return redirect(url_for('page_login')) + impiegati = Impiegato.query.join(Servizio).join(Ente).all() + css = url_for("static", filename="style.css") + return render_template("impiegato/list.html.j2", css=css, impiegati=impiegati) + +@app.route('/imp_list/') +def page_imp_list_plus(sid): + if 'username' not in session: + return redirect(url_for('page_login')) + impiegati = Impiegato.query.join(Servizio).filter_by(sid=sid).join(Ente).all() + css = url_for("static", filename="style.css") + return render_template("impiegato/list.html.j2", css=css, impiegati=impiegati) + +@app.route('/imp_show/', methods=['GET', 'POST']) +def page_imp_show(iid): + if 'username' not in session: + return redirect(url_for('page_login')) + if request.method == "GET": + imp = Impiegato.query.get(iid) + servizi = Servizio.query.all() + css = url_for("static", filename="style.css") + return render_template("impiegato/show.html.j2", css=css, imp=imp, servizi=servizi) + else: + imp = Impiegato.query.get(iid) + imp.sid = request.form["sid"] + imp.nomeimpiegato = request.form["nomeimpiegato"] + imp.username = request.form["username"] + imp.passwd = request.form["passwd"] + db.session.commit() + return redirect(url_for('page_imp_list')) diff --git a/static/style.css b/static/style.css index ff0b827..c17f331 100644 --- a/static/style.css +++ b/static/style.css @@ -3,25 +3,7 @@ width: 25vh; } -.container +.monospace { - text-align: center; - border-radius: 8px; -} - -body -{ - background-color: black; - font-family: "Calibri", sans-serif; - color: white; -} - -table -{ - border-collapse: collapse; -} - -table, td, tr, th -{ - border: 1px solid white; + font-family: "Consolas", monospace; } diff --git a/templates/ente/add.html.j2 b/templates/ente/add.html.j2 new file mode 100644 index 0000000..c214d18 --- /dev/null +++ b/templates/ente/add.html.j2 @@ -0,0 +1,19 @@ + + + Aggiunta ente - Inventario + + + + +
+

+ Aggiunta nuovo ente +

+
+ + + +
+
+ + diff --git a/templates/ente/list.html.j2 b/templates/ente/list.html.j2 new file mode 100644 index 0000000..fdbe50c --- /dev/null +++ b/templates/ente/list.html.j2 @@ -0,0 +1,37 @@ + + + Elenco enti - Inventario + + + + +
+

+ Enti esistenti +

+ + + + + + + + + + + + {% for ente in enti %} + + + + + + + + {% endfor %} + +
Nome enteNome breveIspezionaModificaElimina
{{ ente.nomeente }}{{ ente.nomebreveente }}
+ Aggiungi +
+ + diff --git a/templates/ente/show.html.j2 b/templates/ente/show.html.j2 new file mode 100644 index 0000000..2f375e7 --- /dev/null +++ b/templates/ente/show.html.j2 @@ -0,0 +1,19 @@ + + + Modifica ente - Inventario + + + + +
+

+ Modifica ente +

+
+ + + +
+
+ + diff --git a/templates/ente_add.html.j2 b/templates/ente_add.html.j2 deleted file mode 100644 index be1c2ef..0000000 --- a/templates/ente_add.html.j2 +++ /dev/null @@ -1,19 +0,0 @@ - - - Aggiungi un pesce rosso - - - -
Ciao Ciao
-
-

- Aggiunta nuovo ente -

-
- - - -
-
- - diff --git a/templates/ente_list.html.j2 b/templates/ente_list.html.j2 deleted file mode 100644 index 0f77151..0000000 --- a/templates/ente_list.html.j2 +++ /dev/null @@ -1,24 +0,0 @@ - - - Visualizza un pesce rosso - - - -
Ciao pesce
-
-

- Enti esistenti -

- - {% for ente in enti %} - - - - - - - {% endfor %} -
{{ ente.nome }}{{ ente.nomebreve }}ModificaElimina
-
- - diff --git a/templates/ente_show.html.j2 b/templates/ente_show.html.j2 deleted file mode 100644 index dd8ef01..0000000 --- a/templates/ente_show.html.j2 +++ /dev/null @@ -1,19 +0,0 @@ - - - Aggiungi un pesce rosso - - - -
Risio e le risiaie
-
-

- Aggiunta nuovo ente -

-
- - - -
-
- - diff --git a/templates/impiegato/add.html.j2 b/templates/impiegato/add.html.j2 new file mode 100644 index 0000000..8a1a32f --- /dev/null +++ b/templates/impiegato/add.html.j2 @@ -0,0 +1,25 @@ + + + Aggiunta impiegato - Inventario + + + + +
+

+ Aggiunta nuovo impiegato +

+
+ + + + + +
+
+ + diff --git a/templates/impiegato/list.html.j2 b/templates/impiegato/list.html.j2 new file mode 100644 index 0000000..0eaa399 --- /dev/null +++ b/templates/impiegato/list.html.j2 @@ -0,0 +1,39 @@ + + + Elenco impiegati - Inventario + + + + +
+

+ Impiegati esistenti +

+ + + + + + + + + + + + + {% for imp in impiegati %} + + + + + + + + + {% endfor %} +
Nome enteNome servizioNome impiegatoNome utentePasswordModificaElimina
{{ imp.servizio.ente.nomeente }}{{ imp.servizio.nomeservizio }} + {{ imp.nomeimpiegato }}{{ imp.username }}{{ imp.passwd }}
+ Aggiungi +
+ + diff --git a/templates/impiegato/show.html.j2 b/templates/impiegato/show.html.j2 new file mode 100644 index 0000000..bb61e6d --- /dev/null +++ b/templates/impiegato/show.html.j2 @@ -0,0 +1,25 @@ + + + Modifica impiegato - Inventario + + + + +
+

+ Modifica impiegato +

+
+ + + + + +
+
+ + diff --git a/templates/login.html.j2 b/templates/login.html.j2 index 200d583..944480b 100644 --- a/templates/login.html.j2 +++ b/templates/login.html.j2 @@ -1,22 +1,22 @@ - Pesci rossi nel login + Login - Acquario + -
Ciao Ruozi!

Login

-
- - - + + + +
-
+ diff --git a/templates/servizio/add.html.j2 b/templates/servizio/add.html.j2 new file mode 100644 index 0000000..1e072fe --- /dev/null +++ b/templates/servizio/add.html.j2 @@ -0,0 +1,23 @@ + + + Aggiunta servizio - Inventario + + + + +
+

+ Aggiunta nuovo servizio +

+
+ + + +
+
+ + diff --git a/templates/servizio/list.html.j2 b/templates/servizio/list.html.j2 new file mode 100644 index 0000000..9e08062 --- /dev/null +++ b/templates/servizio/list.html.j2 @@ -0,0 +1,35 @@ + + + Elenco servizi - Inventario + + + + +
+

+ Servizi esistenti +

+ + + + + + + + + + + {% for servizio in serv %} + + + + + + + + {% endfor %} +
Nome enteNome servizioIspezionaModificaElimina
{{ servizio.ente.nomeente }}{{ servizio.nomeservizio }}
+ Aggiungi +
+ + diff --git a/templates/servizio/show.html.j2 b/templates/servizio/show.html.j2 new file mode 100644 index 0000000..e32977b --- /dev/null +++ b/templates/servizio/show.html.j2 @@ -0,0 +1,23 @@ + + + Modifica servizio - Inventario + + + + +
+

+ Modifica servizio +

+
+ + + +
+
+ + diff --git a/templates/user_add.html.j2 b/templates/user_add.html.j2 deleted file mode 100644 index af898e4..0000000 --- a/templates/user_add.html.j2 +++ /dev/null @@ -1,20 +0,0 @@ - - - Aggiungi un pesce rosso - - - -
Ciao Ciao
-
-

- Login -

-
- - - - -
-
- -