class auditLogLookup(db.Model, Serializer): # table audit_log_lookups : table modal __tablename__ = 'audit_log_lookups' # rec-id id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) # code-id code_id = db.Column('code_id', db.VARCHAR(length=45)) # status code status = db.Column('status', db.VARCHAR(length=45)) # status description description = db.Column('description', db.VARCHAR(length=45)) # log type type = db.Column('type', db.VARCHAR(length=45)) # severity level severity = db.Column('severity', db.VARCHAR(length=45)) # initrialization def __init__(self, code_id, status, description, type, severity): self.code_id = code_id self.status = status self.description = description self.type = type self.severity = severity # serialize db object to json def serialize(self): d = Serializer.serialize(self) return d
class Role(db.Model, RoleMixin): # 权限表 id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __init__(self, name, description): self.name = name self.description = description
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) active = db.Column(db.Boolean(), default=True, nullable=False) def __init__(self, name, description): self.name = name self.description = description self.active = True
class unoLookup(db.Model, Serializer): # view table Event-logs-live-v __tablename__ = 'uno_lookups' # rec_id id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) # unit_name / uno_id uno_id = db.Column('uno_id', db.VARCHAR(length=45)) # unit_name / uno_name uno_name = db.Column('description', db.VARCHAR(length=45)) # serialize db object to json def serialize(self): d = Serializer.serialize(self) return d
class Detalle(db.Model): __tablename__ = 'Detalle' id = db.Column(db.Integer(), primary_key=True) codProducto = db.Column(db.Integer, db.ForeignKey('Productos.Codigo'), nullable=False) codingreso = db.Column(db.Integer, db.ForeignKey('Ingreso.cod_ingreso')) codsalida = db.Column(db.Integer, db.ForeignKey('salida.Codigo')) Docenas = db.Column(db.Integer, nullable=False) Unidades = db.Column(db.Integer, nullable=False) #relaciones fk_producto = db.relationship("productos") fk_Ingreso = db.relationship("ingreso") fk_Salida = db.relationship("Salida")
class Role(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) permissions = db.relationship('Permission', secondary=permissions_roles, backref=db.backref('roles', lazy='dynamic')) def has_permission(self, permission_name): p = Permission.query.filter_by(name=permission_name).first() return True if p in self.permissions else False def assign_permission(self, permission_name): p = Permission.query.filter_by(name=permission_name).first() self.roles.append(p)
class auditLog(db.Model, Serializer): # table audit_log : table modal __tablename__ = 'audit_logs' # log id id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) # unit_id / uno_id uno_id = db.Column('uno_id', db.VARCHAR(length=45)) # audit log lookup to code code_id = db.Column('code_id', db.VARCHAR(length=45)) # loging time timestamp = db.Column('timestamp', db.TIMESTAMP(), nullable=False) # logging status status = db.Column('status', db.VARCHAR(length=45)) # extra-info user_id = db.Column('user_id', db.VARCHAR(length=45)) mission_id = db.Column('mission_id', db.VARCHAR(length=45)) waypoint_id = db.Column('waypoint_id', db.String(255)) # initrialization def __init__(self, uno_id, code_id, status, audit_time, user_id, mission_id, waypoint_id ): self.uno_id = uno_id self.code_id = code_id self.status = status self.audit_time = audit_time self.user_id = user_id self.mission_id = mission_id self.waypoint_id = waypoint_id # serialize db object to json def serialize(self): d = Serializer.serialize(self) try: d['timestamp'] = d['timestamp'].strftime('%Y-%m-%d %H:%M:%S.%f') except BaseException: d['timestamp'] = str(d['timestamp']) return d
class Permission(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True)
website_title = db.Column(db.String(191)) website_email = db.Column(db.String(191)) address = db.Column(db.Text) logo = db.Column(db.String(191)) favicon = db.Column(db.String(191)) # =========================================================================================== # Auth Models # =========================================================================================== # Here exists Many-to-Many relationship between User and Role # Here exists Many-to-Many relationship between Role and Permission # Here exists Many-to-Many relationship between User and Permission roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) permissions_roles = db.Table( 'permissions_roles', db.Column('role_id', db.Integer(), db.ForeignKey('role.id')), db.Column('permission_id', db.Integer(), db.ForeignKey('permission.id'))) permissions_users = db.Table( 'permissions_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('permission_id', db.Integer(), db.ForeignKey('permission.id'))) class Permission(db.Model):
__author__ = 'responsible' from App import db from flask.ext.security import UserMixin, RoleMixin from passlib.handlers.django import django_pbkdf2_sha256 roles_users = db.Table('roles_users', # 用户权限中间表 db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): # 权限表 id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __init__(self, name, description): self.name = name self.description = description class User(db.Model, UserMixin): # 用户表 id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(11), nullable=False, unique=True) password = db.Column(db.String(128), nullable=False) active = db.Column(db.Boolean(), default=True, nullable=False) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) def __init__(self, username=None, password=None, active=True): self.username = username self.password = django_pbkdf2_sha256.encrypt(password) self.active = True
class Response(db.Model): __tablename__ = "responses" turkid = db.Column('turkid', db.String(20), unique=True, index=True, primary_key=True) fundtype = db.Column('fundtype', db.String(20)) startdate = db.Column('startdate', db.DateTime) enddate = db.Column('enddate', db.DateTime) weeknumber = db.Column('weeknumber', db.Integer()) fundpastbalance = db.Column('fundpastbalance', db.Float()) salarypastbalance = db.Column('salarypastbalance', db.Float()) fundhistory = db.Column('fundhistory', ARRAY(db.Float())) salaryhistory = db.Column('salaryhistory', ARRAY(db.Float())) foodhistorysalary = db.Column('foodhistorysalary', ARRAY(db.Float())) foodhistoryfund = db.Column('foodhistoryfund', ARRAY(db.Float())) miscchoices = db.Column('miscchoices', ARRAY(db.Float())) timespenthistory = db.Column('timespenthistory', ARRAY(db.Float())) def __init__(self, turkid, fundtype): self.turkid = turkid self.fundtype = fundtype self.startdate = datetime.utcnow() self.enddate = datetime.utcnow() self.weeknumber = 0 self.fundpastbalance = 100 self.salarypastbalance = 0 self.fundhistory = [] self.salaryhistory = [] self.foodhistoryfund = [] self.foodhistorysalary = [] self.miscchoices = [] self.timespenthistory = [] def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False @property def info(self): info = {} for key in [ "fundtype", "weeknumber", "fundpastbalance", "salarypastbalance", "fundhistory", "salaryhistory", "foodhistoryfund", "foodhistorysalary", "timespenthistory", "miscchoices" ]: info[key] = self.__dict__.get(key) return info @info.setter def info(self, dict): for key in [ "weeknumber", "fundpastbalance", "salarypastbalance", "fundhistory", "salaryhistory", "foodhistoryfund", "foodhistorysalary", "timespenthistory", "miscchoices" ]: if key in ["fundpastbalance", "salarypastbalance"]: setattr(self, key, float(dict[key])) elif key == "weeknumber": setattr(self, key, int(dict[key])) else: setattr(self, key, dict[key]) def get_id(self): return self.turkid def __repr__(self): base = "MTurk ID = {}\n".format(self.turkid) for key, value in self.info.items(): base += "{} = {}\n".format(key, value) return base
__author__ = 'Alex Galani' from App import db from flask_security import UserMixin, RoleMixin from passlib.hash import bcrypt roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) services_users = db.Table( 'services_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('service_id', db.Integer(), db.ForeignKey('services.id'))) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) active = db.Column(db.Boolean(), default=True, nullable=False) def __init__(self, name, description): self.name = name self.description = description self.active = True class User(db.Model, UserMixin): __tablename__ = "user"