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

Part 1 of dev show

This commit is contained in:
Lorenzo 2017-09-12 12:50:28 +02:00
parent 60437cbe19
commit 9b5f75c7d2
3 changed files with 150 additions and 0 deletions

View file

@ -519,6 +519,52 @@ def page_disp_details(did):
user=session["username"])
@app.route('/disp_show/<int:did>', methods=['GET', 'POST'])
def page_disp_show(did):
if 'username' not in session:
return redirect(url_for('page_login'))
if request.method == 'GET':
disp = Dispositivo.query.filter_by(did=did).first_or_404()
return render_template("dispositivo/show.htm", disp=disp, accessi=accessi, type="disp",
user=session["username"])
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.")
disp = Dispositivo.query.filter_by(did=did).first_or_404()
disp.tipo = request.form['tipo']
disp.marca = request.form['marca']
disp.modello = request.form['modello']
disp.inv_ced = request.form['inv_ced']
disp.inv_ente = request.form['inv_ente']
disp.fornitore = request.form['fornitore']
disp.rete = request.form['rete']
db.session.commit()
# Trova tutti gli utenti, edizione sporco hack in html
users = list()
while True:
# Trova tutti gli utenti esistenti
userstring = 'utente{}'.format(len(users))
if userstring in request.form:
users.append(request.form[userstring])
else:
break
for user in users:
nuovologin = Accesso(int(user), nuovodisp.did)
db.session.add(nuovologin)
db.session.commit()
# TODO: se un dispositivo non ha utenti si incasina parecchio
return redirect(url_for('page_disp_list'))
@app.route('/net_add', methods=['GET', 'POST'])
def page_net_add():
"""Pagina di creazione nuova rete:

BIN
static/joke.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,104 @@
{% extends "base.htm" %}
{% block extrahead %}
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<script>
var users = 0;
function genhtml(n) {
return "<select id=\"utente" + n + "\" class=\"form-control\" name=\"utente" + n + "\">{% for impiegato in impiegati %}<option value=\"{{impiegato.iid}}\">{{impiegato.nomeimpiegato}} - {{impiegato.username}}</option>{% endfor %}</select>"
}
function adduser() {
$("#users-column").append(genhtml(users));
users += 1;
$("#remove-user").removeClass("disabled");
}
function removeuser() {
if (users > 0) {
$("#utente" + (users - 1)).remove();
users -= 1;
if (users === 0) {
$("#remove-user").addClass("disabled");
}
}
}
</script>
{% endblock %}
{% block content %}
<h1>
Modifica dispositivo
</h1>
<form class="form-horizontal" action="/disp_add" method="post">
<div class="form-group">
<label class="col-xs-2" for="">Tipo dispositivo</label>
<div class="col-xs-10">
<select id="form-tipo" class="form-control" name="tipo" value="{{ dispositivo.tipo }}">
{% for opzione in opzioni %}
<option value="{{ opzione }}">{{ opzione }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-utente">Utenti</label>
<div class="col-xs-10" id="users-column">
<div id="add-user" class="btn btn-success" onclick="adduser()"><span class="glyphicon glyphicon-plus"></span></div>
<div id="remove-user" class="btn btn-danger disabled" onclick="removeuser()"><span class="glyphicon glyphicon-minus"></span></div>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-marca">Marca</label>
<div class="col-xs-10">
<input id="form-marca" class="form-control" type="text" placeholder="Marca" name="marca" value="{{ dispositivo.marca }}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-modello">Modello</label>
<div class="col-xs-10">
<input id="form-modello" class="form-control" type="text" placeholder="Modello" name="modello" value="{{ dispositivo.modello }}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-ced">Inventario CED</label>
<div class="col-xs-10">
<input id="form-ced" class="form-control" type="text" placeholder="Inventario CED" name="inv_ced" value="{{ dispositivo.inv_ced }}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-ente">Inventario ente</label>
<div class="col-xs-10">
<input id="form-ente" class="form-control" type="text" placeholder="Inventario ente" name="inv_ente" value="{{ dispositivo.inv_ente }}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-fornitore">Fornitore</label>
<div class="col-xs-10">
<input id="form-fornitore" class="form-control" type="text" placeholder="Fornitore" name="fornitore" value="{{ dispositivo.fornitore }}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-seriale">Numero Seriale</label>
<div class="col-xs-10">
<input id="form-seriale" class="form-control" type="text" placeholder="Seriale" name="seriale" value="{{ dispositivo.seriale }}">
</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.network_ip }}/{{ rete.subnet }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-control"></label>
<div class="col-xs-10">
<input class="form-control btn btn-primary" type="submit">
</div>
</div>
</form>
{% endblock %}