-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
281 lines (225 loc) · 9.5 KB
/
base.py
File metadata and controls
281 lines (225 loc) · 9.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Dependencias
from flask import Flask, request, session
from flask.ext.script import Manager, Server
from random import SystemRandom
from datetime import timedelta
import os
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, String, ForeignKey
from flask.ext.migrate import Migrate, MigrateCommand
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import relationship, backref, sessionmaker
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, PrimaryKeyConstraint, UniqueConstraint, Sequence
app = Flask(__name__, static_url_path='')
manager = Manager(app)
manager.add_command("runserver", Server(
use_debugger = True,
use_reloader = True,
host = '127.0.0.1')
)
@app.before_request
def make_session_permanent():
session.permanent = True
app.permanent_session_lifetime = timedelta(minutes=45)
session.modified = True
@app.route('/')
def root():
session.pop("idPila", None)
return app.send_static_file('index.html')
@manager.command
def createdb():
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import sessionmaker
engine = create_engine(URL(**app.config['DATABASE']))
db.metadata.drop_all(engine)
db.metadata.create_all(engine)
DBSession = sessionmaker(bind = engine)
session = DBSession()
#Application code starts here
app.config['DATABASE'] = {
'drivername': 'postgres',
'host': 'localhost',
'port': '5432',
'username': 'apmwsc',
'password': 'safepassword',
'database': 'apmwsc'
}
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
engine = create_engine(URL(**app.config['DATABASE']))
DBSession = sessionmaker(bind = engine)
sessionDB = DBSession()
#Clase para pila de productos
class Producto(db.Model):
__tablename__ = 'Productos'
idProducto = db.Column(Integer, primary_key = True) #autoincremento
nombre = db.Column(String(500), unique = True, nullable = False)
descripcion = db.Column(String(500), unique = False)
escala = db.Column(String(14),nullable = False)
def __init__(self,nombre,escala,descripcion=None):
self.nombre = nombre
self.descripcion = descripcion
self.escala = escala
def getALL(self):
return engine.execute("select * from \"Products\";")
# Clase Accion
class Accion(db.Model):
__tablename__ = 'Acciones'
idAccion = db.Column(Integer, primary_key = True) # Autoincremento
descripcion = db.Column(String(500), unique = False, nullable=False)
idProducto = db.Column(Integer, db.ForeignKey('Productos.idProducto'))
producto = db.relationship('Producto', backref = db.backref('acciones', lazy = 'dynamic'))
''' Metodo init
Constructor de accion
'''
def __init__(self, descripcion, idProducto):
self.descripcion = descripcion
self.idProducto = idProducto
# Clase Actor
class Actor(db.Model):
__tablename__ = 'Actores'
idActor = db.Column(Integer , primary_key = True)
nombre = db.Column(String(50) , unique = False, nullable=False)
descripcion = db.Column(String(500), unique = False, nullable=False)
idProducto = db.Column(Integer, db.ForeignKey('Productos.idProducto'))
producto = db.relationship('Producto', backref = db.backref('actores', lazy = 'dynamic'))
''' Metodo init
Constructor del actor
'''
def __init__(self, nombre, descripcion, idProducto):
self.nombre = nombre
self.descripcion = descripcion
self.idProducto = idProducto
def getALL(self):
return engine.execute("select * from \"Actores\";")
# Clase Objetivo
class Objetivo(db.Model):
__tablename__ = 'Objetivos'
idObjetivo = db.Column(Integer, primary_key = True) #Autoincremento
descripcion = db.Column(String(500), unique = False, nullable=False)
idProducto = db.Column(Integer, db.ForeignKey('Productos.idProducto'))
transversal = db.Column(String(15), unique = False, nullable=False)
producto = db.relationship('Producto', backref = db.backref('objetivos', lazy = 'dynamic'))
''' Metodo init
Constructor del objetivo
'''
def __init__(self,descripcion, idProducto, transversal):
self.descripcion = descripcion
self.idProducto = idProducto
self.transversal = transversal
# Class User.
class dbuser(db.Model):
__tablename__ = 'dbuser'
fullname = Column(String(50))
username = Column(String(16), primary_key = True)
password = Column(String(100)) #para que pueda aceptar hash
email = Column(String(30))
idActor = Column(Integer, ForeignKey('Actores.idActor')) # Roll que ocupa
''' Metodo init
Constructor del usuario
'''
def __init__(self, fullname, username, password, email, idActor):
self.fullname = fullname
self.username = username
self.password = password
self.email = email
self.idActor = idActor
# Clase historias de usuarios
class Historia(db.Model):
__tablename__ = 'Historias'
idHistoria = db.Column(Integer, primary_key = True) #Autoincremento
codigo = db.Column(String(500), unique = False, nullable=False)
tipo = db.Column(String(15), nullable=False)
idProducto = db.Column(Integer, db.ForeignKey('Productos.idProducto'), unique = False, nullable=False)
idAccion = db.Column(Integer, db.ForeignKey('Acciones.idAccion'), nullable=True)
idHistoriaPadre = db.Column(Integer, db.ForeignKey('Historias.idHistoria'), unique = False, nullable=True)
prioridad = db.Column(Integer, unique = False,nullable=False) #Del 1 al 20
''' Metodo init
Constructor de las historias de usuarios
'''
def __init__(self,codigo, idProducto,idAccion,tipo,prioridad,idHistoriaPadre=None):
self.codigo = codigo
self.idProducto = idProducto
self.idAccion = idAccion
self.tipo = tipo
if idHistoriaPadre:
self.idHistoriaPadre = idHistoriaPadre
self.prioridad=prioridad
# Clase para objetivos de una historia
class ObjetivosHistoria(db.Model):
__tablename__ = 'ObjetivosHistorias'
idHistoria = db.Column(Integer, db.ForeignKey('Historias.idHistoria'), unique = False, primary_key=True)
idObjetivo = db.Column(Integer, db.ForeignKey('Objetivos.idObjetivo'), unique = False, primary_key=True)
''' Metodo init
Constructor de Objetivos asociados a Historias
'''
def __init__(self,idHistoria,idObjetivo):
self.idHistoria = idHistoria
self.idObjetivo = idObjetivo
# Clase para actores de una historia
class ActoresHistoria(db.Model):
__tablename__ = 'ActoresHistorias'
idHistoria = db.Column(Integer, db.ForeignKey('Historias.idHistoria'), unique = False, primary_key=True)
idActor = db.Column(Integer, db.ForeignKey('Actores.idActor'), unique = False, primary_key=True)
''' Metodo init
Constructor de Actores asociados a Historias
'''
def __init__(self,idHistoria,idActor):
self.idHistoria = idHistoria
self.idActor = idActor
# Clase Tareas
class Tarea(db.Model):
__tablename__ = 'Tareas'
idTarea = db.Column(Integer, primary_key = True) #Autoincremento
descripcion = db.Column(String(500), unique = False, nullable=False)
idHistoria = db.Column(Integer, db.ForeignKey('Historias.idHistoria'), unique = False, primary_key=True)
nombreCategoria = db.Column(String(100), db.ForeignKey('Categorias.nombreCategoria'), unique = False)
peso = db.Column(Integer, nullable=False)
''' Metodo init
Constructor de Tareas de una historia
'''
def __init__(self,descripcion,idHistoria,nombreCategoria,peso):
self.descripcion = descripcion
self.idHistoria = idHistoria
self.nombreCategoria = nombreCategoria
self.peso = peso
# Calse Categoria
class Categoria(db.Model):
__tablename__ = 'Categorias'
idCategoria = db.Column(Integer, primary_key = True) #Autoincremento
nombreCategoria = db.Column(String(50),unique = True,nullable=False)
peso = db.Column(Integer, nullable = False)
''' Metodo init
Constructor de Categorias de Tareas
'''
def __init__(self,nombreCategoria,peso):
self.nombreCategoria = nombreCategoria
self.peso = peso
from app.scrum.ident import ident
app.register_blueprint(ident)
from app.scrum.prod import prod
app.register_blueprint(prod)
from app.scrum.mast import mast
app.register_blueprint(mast)
from app.scrum.dev import dev
app.register_blueprint(dev)
from app.scrum.actor import actor
app.register_blueprint(actor)
from app.scrum.objetivo import objetivo
app.register_blueprint(objetivo)
from app.scrum.accion import accion
app.register_blueprint(accion)
from app.scrum.historias import historias
app.register_blueprint(historias)
from app.scrum.tareas import tareas
app.register_blueprint(tareas)
from app.scrum.cates import cates
app.register_blueprint(cates)
if __name__ == '__main__':
app.config.update(
SECRET_KEY = repr(SystemRandom().random())
)
manager.run()