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

Add Network Table and Network field in Device table

This commit is contained in:
Lorenzo 2017-09-11 16:55:23 +02:00
parent bcabb2b83c
commit 508b428c30
7 changed files with 135 additions and 3 deletions

View file

@ -84,14 +84,17 @@ class Dispositivo(db.Model):
inv_ced = db.Column(db.String(8))
inv_ente = db.Column(db.String(8))
fornitore = db.Column(db.String(64))
nid = db.Column(db.Integer, db.ForeignKey('network.nid'))
rete = db.relationship("Network", backref='dispositivo')
def __init__(self, tipo, marca, modello, inv_ced, inv_ente, fornitore):
def __init__(self, tipo, marca, modello, inv_ced, inv_ente, fornitore, nid):
self.tipo = tipo
self.marca = marca
self.modello = modello
self.inv_ced = inv_ced
self.inv_ente = inv_ente
self.fornitore = fornitore
self.nid = nid
def __repr__(self):
return "<Dispositivo {}>".format(self.inv_ced)
@ -109,6 +112,19 @@ class Accesso(db.Model):
return "<Accesso {} su {}>".format(self.iid, self.did)
class Network(db.Model):
nid = db.Column(db.Integer, primary_key=True)
nome = db.Column(db.String(80))
ip = db.Column(db.String(20))
def __init__(self, nome, ip):
self.nome=nome
self.ip=ip
def __repr__(self):
return "<Rete {},{}>".format(self.nid, self.nome)
class FakeAccesso:
def __init__(self, dispositivo):
self.did = dispositivo.did
@ -356,13 +372,14 @@ def page_disp_add():
if request.method == 'GET':
opzioni = ["Centralino", "Dispositivo generico di rete", "Marcatempo", "PC", "Portatile", "POS", "Router",
"Server", "Stampante di rete", "Switch", "Telefono IP", "Monitor", "Scanner", "Stampante locale"]
reti = Network.query.all()
impiegati = Impiegato.query.all()
css = url_for("static", filename="style.css")
return render_template("dispositivo/add.htm", css=css, impiegati=impiegati, opzioni=opzioni, type="dev",
return render_template("dispositivo/add.htm", css=css, impiegati=impiegati, opzioni=opzioni, reti=reti, type="dev",
user=session["username"])
else:
nuovodisp = Dispositivo(request.form['tipo'], request.form['marca'], request.form['modello'],
request.form['inv_ced'], request.form['inv_ente'], request.form['fornitore'])
request.form['inv_ced'], request.form['inv_ente'], request.form['fornitore'], request.form['rete'])
db.session.add(nuovodisp)
db.session.commit()
# Trova tutti gli utenti, edizione sporco hack in html
@ -427,6 +444,40 @@ def page_details_imp(iid):
css = url_for("static", filename="style.css")
return render_template("impiegato/details.htm", css=css, imp=impiegato, type="imp",user=session["username"])
@app.route('/net_add', methods=['GET', 'POST'])
def page_net_add():
if 'username' not in session:
return redirect(url_for('page_login'))
if request.method == 'GET':
css = url_for("static", filename="style.css")
return render_template("net/add.htm", css=css, type="net", user=session["username"])
else:
nuovonet = Network(request.form['nomerete'], request.form['ip'])
db.session.add(nuovonet)
db.session.commit()
return redirect(url_for('page_net_list'))
@app.route('/net_del/<int:nid>')
def page_ned_del(nid):
if 'username' not in session:
return redirect(url_for('page_login'))
rete = Network.query.get(nid)
db.session.delete(rete)
db.session.commit()
return redirect(url_for('page_net_list'))
@app.route('/net_list')
def page_net_list():
if 'username' not in session:
return redirect(url_for('page_login'))
reti = Network.query.all()
css = url_for("static", filename="style.css")
return render_template("net/list.htm", css=css, reti=reti, type="net", user=session["username"])
if __name__ == "__main__":
#db.create_all()
#p = b"admin"

View file

@ -78,6 +78,16 @@
<input id="form-fornitore" class="form-control" type="text" placeholder="Fornitore" name="fornitore">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="">Rete</label>
<div class="col-xs-10">
<select id="form-rete" class="form-control" name="rete">
{% for rete in reti %}
<option value="{{ rete.nid }}">{{ rete.nome }} - {{ rete.ip }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-control"></label>
<div class="col-xs-10">

View file

@ -26,6 +26,7 @@
<td>{{ d[0].dispositivo.marca }}</td>
<td>{{ d[0].dispositivo.modello }}</td>
<td>{{ d[0].dispositivo.fornitore }}</td>
<td>{{ d[0].dispositivo.rete.nome }}</td>
<td><a href="/disp_details/{{ d[0].did }}"><span class="glyphicon glyphicon-list-alt"></span></a></td>
<td><a href="/disp_del/{{ d[0].did }}"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>

View file

@ -13,6 +13,7 @@
<li class="{% if type is equalto "serv" %}active{% endif %}"><a href="/serv_list">Servizi</a></li>
<li class="{% if type is equalto "imp" %}active{% endif %}"><a href="/imp_list">Impiegati</a></li>
<li class="{% if type is equalto "disp" %}active{% endif %}"><a href="/disp_list">Dispositivi</a></li>
<li class="{% if type is equalto "net" %}active{% endif %}"><a href="/net_list">Reti</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<p class="navbar-text">

11
templates/net/add.htm Normal file
View file

@ -0,0 +1,11 @@
{% extends "base.htm" %}
{% block content %}
<h1>
Aggiunta nuova rete
</h1>
<form class="form-inline" action="/net_add" method="post">
<input class="form-control" type="text" placeholder="Nome rete" name="nomerete">
<input class="form-control" type="text" placeholder="Set IP" name="ip">
<input class="btn btn-primary" type="submit">
</form>
{% endblock %}

33
templates/net/details.htm Normal file
View file

@ -0,0 +1,33 @@
{% extends "base.htm" %}
{% block title %}Dettagli Impiegato{% endblock %}
{% block content %}
<h1>
Ispeziona Rete
</h1>
<ul class="list-group">
<li class="list-group-item">
<h4 class="list-group-item-heading">
Nome Rete
</h4>
<div class="list-group-item-text">
{{ imp.nomeimpiegato }}
</div>
</li>
<li class="list-group-item">
<h4 class="list-group-item-heading">
IP
</h4>
<div class="list-group-item-text">
{{ imp.username }}
</div>
</li>
<li class="list-group-item">
<h4 class="list-group-item-heading">
Dispositivi
</h4>
<div class="list-group-item-text">
</div>
</li>
</ul>
{% endblock %}

25
templates/net/list.htm Normal file
View file

@ -0,0 +1,25 @@
{% extends "base.htm" %}
{% block content %}
<h1>
Reti esistenti
</h1>
<table class="table table-hover">
<thead>
<tr>
<th>Nome Rete</th>
<th>IP</th>
<th>Ispeziona</th>
<th>Elimina</th>
</tr>
</thead>
<tr>
{% for rete in reti %}
<td>{{ rete.nome }}</td>
<td>{{ rete.ip }}</td>
<td><a href="/disp_details/{{ rete.nid }}"><span class="glyphicon glyphicon-list-alt"></span></a></td>
<td><a href="/net_del/{{ rete.nid }}"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
{% endfor %}
</table>
<a class="btn btn-success" href="/net_add">Aggiungi</a>
{% endblock %}