1
Fork 0
mirror of https://github.com/Steffo99/estus.git synced 2024-11-24 16:44:19 +00:00

Add order add and edit and list page

This commit is contained in:
Steffo 2017-09-19 09:36:39 +02:00
parent 119620de85
commit 073f85b571
4 changed files with 118 additions and 3 deletions

View file

@ -1,3 +1,4 @@
import datetime
import os import os
from flask import Flask, session, url_for, redirect, request, render_template, abort from flask import Flask, session, url_for, redirect, request, render_template, abort
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
@ -191,6 +192,23 @@ class Rete(db.Model):
return "<Rete {},{}>".format(self.nid, self.nome) return "<Rete {},{}>".format(self.nid, self.nome)
class Ordine(db.Model):
"""Ordine di uno o più dispositivi"""
__tablename__ = "ordini"
oid = db.Column(db.Integer, primary_key=True)
data = db.Column(db.Date)
numero_ordine = db.Column(db.String)
def __str__(self):
if self.numero_ordine is not None:
return f"Ordine {self.numero_ordine}"
return f"Ordine #{self.oid}"
def __repr__(self):
return f"<Ordine {self.oid}>"
class FakeAccesso: class FakeAccesso:
"""Hackerino usato nel caso in cui non ci sia nessun impiegato assegnato a un dispositivo. """Hackerino usato nel caso in cui non ci sia nessun impiegato assegnato a un dispositivo.
Viva il duck typing!""" Viva il duck typing!"""
@ -784,10 +802,12 @@ def page_user_del(uid):
if 'username' not in session: if 'username' not in session:
return abort(403) return abort(403)
if User.query.count() <= 1: if User.query.count() <= 1:
return render_template("error.htm", error="Non puoi cancellare l'ultimo utente rimasto!") return render_template("error.htm", error="Non puoi cancellare l'ultimo utente rimasto!",
user=session.get("username"))
utente = User.query.get_or_404(uid) utente = User.query.get_or_404(uid)
if utente.username == session["username"]: if utente.username == session["username"]:
return render_template("error.htm", error="Non puoi cancellare l'utente con cui sei loggato!") return render_template("error.htm", error="Non puoi cancellare l'utente con cui sei loggato!",
user=session.get("username"))
db.session.delete(utente) db.session.delete(utente)
db.session.commit() db.session.commit()
return redirect(url_for('page_user_list')) return redirect(url_for('page_user_list'))
@ -813,6 +833,55 @@ def page_user_add():
return redirect(url_for('page_user_list')) return redirect(url_for('page_user_list'))
@app.route('/order_list')
def page_order_list():
"""Pagina di elenco degli ordini registrati nel database."""
if 'username' not in session:
return abort(403)
ordini = Ordine.query.order_by(Ordine.data).all()
return render_template("ordine/list.htm", orders=ordini, pagetype="order", user=session.get("username"))
@app.route('/order_add', methods=['GET', 'POST'])
def page_order_add():
"""Pagina di creazione nuovo ordine"""
if 'username' not in session:
return abort(403)
if request.method == 'GET':
return render_template("ordine/show.htm", action="add", pagetype="order", user=session.get("username"))
else:
if request.form["data"] != "":
yyyy, mm, dd = request.form["data"].split("-", 2)
data = datetime.date(int(yyyy), int(mm), int(dd))
else:
data = None
nuovoordine = Ordine(data=data, numero_ordine=request.form["numero_ordine"])
db.session.add(nuovoordine)
db.session.commit()
return redirect(url_for("page_order_list"))
@app.route('/order_show/<int:oid>', methods=['GET', 'POST'])
def page_order_show(oid):
"""Pagina di modifica ordine"""
if 'username' not in session:
return abort(403)
if request.method == 'GET':
order = Ordine.query.get_or_404(oid)
return render_template("ordine/show.htm", order=order, action="show", pagetype="order",
user=session.get("username"))
else:
order = Ordine.query.get_or_404(oid)
if request.form["data"] != "":
yyyy, mm, dd = request.form["data"].split("-", 2)
order.data = datetime.date(int(yyyy), int(mm), int(dd))
else:
order.data = None
order.numero_ordine = request.form["numero_ordine"]
db.session.commit()
return redirect(url_for("page_order_list"))
@app.route('/query', methods=['GET', 'POST']) @app.route('/query', methods=['GET', 'POST'])
def page_query(): def page_query():
"""Pagina delle query manuali: """Pagina delle query manuali:

View file

@ -16,8 +16,9 @@
<li class="{% if pagetype is equalto "ente" %}active{% endif %}"><a href="/ente_list">Enti</a></li> <li class="{% if pagetype is equalto "ente" %}active{% endif %}"><a href="/ente_list">Enti</a></li>
<li class="{% if pagetype is equalto "serv" %}active{% endif %}"><a href="/serv_list">Servizi</a></li> <li class="{% if pagetype is equalto "serv" %}active{% endif %}"><a href="/serv_list">Servizi</a></li>
<li class="{% if pagetype is equalto "imp" %}active{% endif %}"><a href="/imp_list">Impiegati</a></li> <li class="{% if pagetype is equalto "imp" %}active{% endif %}"><a href="/imp_list">Impiegati</a></li>
<li class="{% if pagetype is equalto "disp" %}active{% endif %}"><a href="/disp_list">Dispositivi</a></li>
<li class="{% if pagetype is equalto "net" %}active{% endif %}"><a href="/net_list">Reti</a></li> <li class="{% if pagetype is equalto "net" %}active{% endif %}"><a href="/net_list">Reti</a></li>
<li class="{% if pagetype is equalto "order" %}active{% endif %}"><a href="/order_list">Ordini</a></li>
<li class="{% if pagetype is equalto "disp" %}active{% endif %}"><a href="/disp_list">Dispositivi</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li class="{% if pagetype is equalto "user" %}active{% endif %}"><a href="/user_list">Utenti</a></li> <li class="{% if pagetype is equalto "user" %}active{% endif %}"><a href="/user_list">Utenti</a></li>

26
templates/ordine/list.htm Normal file
View file

@ -0,0 +1,26 @@
{% extends "base.htm" %}
{% block title %}Elenco ordini • estus{% endblock %}
{% block content %}
<h1>
Ordini esistenti
</h1>
<a class="btn btn-success" href="/order_add"><span class="glyphicon glyphicon-plus"></span> Aggiungi</a>
<table class="table table-hover">
<thead>
<tr>
<th>Data dell'ordine</th>
<th>Numero dell'ordine</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
{% for order in orders %}
<tr>
<td>{% if order.data %}{{ order.data }}{% endif %}</td>
<td>{% if order.numero_ordine %}{{ order.numero_ordine }}{% endif %}</td>
<td><a href="/order_details/{{ order.oid }}" title="Dettagli"><span class="glyphicon glyphicon-zoom-in"></span></a> <a href="/order_show/{{ order.oid }}"><span class="glyphicon glyphicon-pencil"></span></a> <a href="/order_del/{{ order.oid }}"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

19
templates/ordine/show.htm Normal file
View file

@ -0,0 +1,19 @@
{% extends "base.htm" %}
{% block title %}Modifica ordine • estus{% endblock %}
{% block content %}
<h1>
{% if action == "add" %}
Crea ordine
{% elif action == "show" %}
Modifica ordine
{% endif %}
</h1>
<div class="alert alert-warning">
Il campo data non è ancora <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1366188">correttamente supportato da Firefox</a> e altri Browser. Se il calendario non viene fuori, inserite le date nel formato AAAA-MM-GG.
</div>
<form class="form-inline" {% if order %}action="/order_show/{{ order.oid }}"{% endif %} method="post">
<input class="form-control" type="date" placeholder="yyyy-mm-dd" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" name="data" {% if order %}value="{{ order.data }}"{% endif %}>
<input class="form-control" type="text" placeholder="Numero ordine" name="numero_ordine" {% if order %}value="{{ order.numero_ordine }}"{% endif %}>
<input class="btn btn-primary" type="submit">
</form>
{% endblock %}