2017-02-01 07:21:18 +00:00
|
|
|
from flask import Flask
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
# SQL
|
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
|
|
|
|
db = SQLAlchemy(app)
|
|
|
|
|
|
|
|
# Utente login inventario
|
|
|
|
class User(db.Model):
|
|
|
|
uid = db.Column(db.Integer, primary_key=True)
|
|
|
|
username = db.Column(db.String(80), unique=True)
|
|
|
|
passwd = db.Column(db.String(80))
|
|
|
|
|
|
|
|
def __init__(self, username, passwd):
|
|
|
|
self.username = username
|
|
|
|
self.passwd = passwd
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<User {}>".format(self.username, self.passwd)
|
|
|
|
|
|
|
|
# Ente (Unione Terre di Castelli, Comune di Vignola...)
|
|
|
|
class Ente(db.Model):
|
|
|
|
eid = db.Column(db.Integer, primary_key=True)
|
2017-02-01 09:37:53 +00:00
|
|
|
nomeente = db.Column(db.String(64))
|
|
|
|
nomebreveente = db.Column(db.String(16))
|
2017-02-01 07:21:18 +00:00
|
|
|
servizi = db.relationship("Servizio", backref='ente', lazy='dynamic')
|
|
|
|
|
2017-02-03 12:04:11 +00:00
|
|
|
def __init__(self, nomeente, nomebreveente):
|
|
|
|
self.nomeente = nomeente
|
|
|
|
self.nomebreveente = nomebreveente
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2017-02-03 12:04:11 +00:00
|
|
|
return "<Ente {}>".format(self.nomebreveente)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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'))
|
2017-02-01 09:37:53 +00:00
|
|
|
nomeservizio = db.Column(db.String(128))
|
2017-02-01 07:21:18 +00:00
|
|
|
impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic')
|
|
|
|
|
2017-02-03 12:04:11 +00:00
|
|
|
def __init__(self, eid, nomeservizio):
|
2017-02-01 07:21:18 +00:00
|
|
|
self.eid = eid
|
2017-02-03 12:04:11 +00:00
|
|
|
self.nomeservizio = nomeservizio
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2017-02-03 12:04:11 +00:00
|
|
|
return "<Servizio {}>".format(self.nomeservizio)
|
2017-02-01 07:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Impiegato(db.Model):
|
|
|
|
iid = db.Column(db.Integer, primary_key=True)
|
|
|
|
sid = db.Column(db.Integer, db.ForeignKey('servizio.sid'))
|
2017-02-01 09:37:53 +00:00
|
|
|
nomeimpiegato = db.Column(db.String(128))
|
2017-02-01 07:21:18 +00:00
|
|
|
username = db.Column(db.String(32), unique=True)
|
|
|
|
passwd = db.Column(db.String(32))
|
2017-02-02 08:33:54 +00:00
|
|
|
dispositivi = db.relationship("Accesso", backref='impiegato', lazy='dynamic')
|
2017-02-01 07:21:18 +00:00
|
|
|
|
2017-02-03 12:04:11 +00:00
|
|
|
def __init__(self, sid, nomeimpiegato, username, passwd):
|
2017-02-01 07:21:18 +00:00
|
|
|
self.sid = sid
|
2017-02-03 12:04:11 +00:00
|
|
|
self.nomeimpiegato = nomeimpiegato
|
2017-02-01 07:21:18 +00:00
|
|
|
self.username = username
|
|
|
|
self.passwd = passwd
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Impiegato {}>".format(self.nome)
|
|
|
|
|
2017-02-02 08:33:54 +00:00
|
|
|
|
|
|
|
class Dispositivo(db.Model):
|
|
|
|
did = db.Column(db.Integer, primary_key=True)
|
|
|
|
utenti = db.relationship("Accesso", backref='dispositivo', lazy='dynamic')
|
|
|
|
tipo = db.Column(db.String(32))
|
|
|
|
marca = db.Column(db.String(64))
|
|
|
|
modello = db.Column(db.String(32))
|
|
|
|
inv_ced = db.Column(db.String(8))
|
|
|
|
inv_ente = db.Column(db.String(8))
|
|
|
|
fornitore = db.Column(db.String(64))
|
|
|
|
|
2017-02-03 12:04:11 +00:00
|
|
|
def __init__(self, tipo, marca, modello, inv_ced, inv_ente, fornitore):
|
2017-02-02 08:33:54 +00:00
|
|
|
self.tipo = tipo
|
|
|
|
self.marca = marca
|
|
|
|
self.modello = modello
|
|
|
|
self.inv_ced = inv_ced
|
|
|
|
self.inv_ente = inv_ente
|
|
|
|
self.fornitore = fornitore
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Dispositivo {}>".format(self.inv_ced)
|
|
|
|
|
|
|
|
|
|
|
|
class Accesso(db.Model):
|
|
|
|
aid = db.Column(db.Integer, primary_key=True)
|
|
|
|
iid = db.Column(db.Integer, db.ForeignKey('impiegato.iid'))
|
|
|
|
did = db.Column(db.Integer, db.ForeignKey('dispositivo.did'))
|
|
|
|
|
|
|
|
def __init__(self, iid, did):
|
|
|
|
self.iid = iid
|
|
|
|
self.did = did
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Accesso {} su {}>".format(iid, did)
|
|
|
|
|
2017-02-03 12:04:11 +00:00
|
|
|
|
2017-02-01 07:21:18 +00:00
|
|
|
db.create_all()
|
|
|
|
|
2017-02-02 08:33:54 +00:00
|
|
|
nuovouser = User('stagista', 'smecds')
|
|
|
|
db.session.add(nuovouser)
|
|
|
|
nuovouser = User('gmacchi', 'steffo99')
|
2017-02-01 07:21:18 +00:00
|
|
|
db.session.add(nuovouser)
|
|
|
|
db.session.commit()
|