class CostDynamic(db.Model): __tablename__ = 'cost_dynamic' _local_id = db.Column('local_id', db.BigInteger, db.Sequence('cost_dynamic_local_id_seq'), primary_key=True, unique=True, autoincrement=True) track_id = db.Column(db.BigInteger, db.ForeignKey('tracks.id'), nullable=False, index=True) segment_id = db.Column(db.BigInteger, index=True, nullable=False) # external pgRouting segment id cost_forward = db.Column(db.Numeric(16, 8)) cost_reverse = db.Column(db.Numeric(16, 8)) def __init__(self, track_id, segment_id, cost_forward, cost_reverse): # local_id auto increment self.track_id = track_id self.segment_id = segment_id self.cost_forward = cost_forward self.cost_reverse = cost_reverse def __repr__(self): return '<cost_dynamic local_id=%i, segment=%i, track=%i>' % self._local_id, self.segment_id, self.track_id
class Permission(db.Model): """Individual Permissions for Users.""" __tablename__ = 'permission' id = db.Column(db.Integer, db.Sequence('permission_id_seq'), primary_key=True) name = db.Column(db.Unicode(64), unique=True, index=True) def __repr__(self): return '<Permission %r>' % self.name @staticmethod def insert_permissions(perms): if perms: for p in perms: permission = Permission.query.filter_by(name=p).first() if permission is None: permission = Permission(name=p) db.session.add(permission) db.session.commit() @staticmethod def clean_permissions(perms): if perms: all_permissions = Permission.query.all() for p in all_permissions: if p.name not in perms: db.session.delete(p) db.session.commit()
class Role(db.Model): """User's Role.""" __tablename__ = 'role' id = db.Column(db.Integer, db.Sequence('role_id_seq'), primary_key=True) name = db.Column(db.Unicode(64), unique=True, index=True) permissions = db.relationship('Permission', secondary=permissions, backref=db.backref('roles', lazy='dynamic', cascade='all')) def __repr__(self): return '<Role %r>' % self.name @staticmethod def insert_roles(rls): if rls: for r in rls: role = Role.query.filter_by(name=r).first() if role is None: role = Role(name=r) db.session.add(role) for p in role.permissions: if p.name not in rls[r]: role.permissions.remove(p) perm_names = [pr.name for pr in role.permissions] for p in rls[r]: if p not in perm_names: permission = Permission.query.filter_by(name=p).first() role.permissions.append(permission) db.session.commit()
class SigninLogs(User): __tablename__ = 'signin_logs' id = db.Column(db.Integer, db.Sequence('login_id_seq'), primary_key=True) user_name = db.Column(db.Integer, db.ForeignKey('users.id')) login_attempt_time = db.Column(db.DateTime) login_status = db.Column(db.String)
class User_DevicesModel(db.Model): __tablename__ = 'user_devices' id = db.Column(db.Integer, db.Sequence('user_devices_id_seq'), primary_key=True) user = db.Column(db.Integer, ForeignKey('users.id')) device_type = db.Column(db.String(), primary_key=False) device_model = db.Column(db.String(), primary_key=False) device_brand = db.Column(db.String(), primary_key=False) last_access = db.Column(db.DateTime, primary_key=False) activated = db.Column(db.Boolean, primary_key=False) ip_address = db.Column(sq.ARRAY(db.String()), default=[], primary_key=False) def __init__(self, id, user, device_type, device_model, device_brand, last_access, activated, ip_address): self.id = id self.user = user self.device_type = device_type self.device_model = device_model self.device_brand = device_brand self.last_access = last_access self.activated = activated self.ip_address = ip_address
class PodcastsModel(db.Model): __tablename__ = 'podcasts' id = db.Column(db.Integer(), db.Sequence('podcasts_id_seq'), primary_key=True) title = db.Column(db.String(), primary_key=False) body = db.Column(db.String(), primary_key=False) audio = db.Column(db.String(), primary_key=False) img = db.Column(db.String(), primary_key=False) series_id = db.Column(db.Integer, ForeignKey('podcast_series.id')) series = db.relationship("Podcast_SeriesModel", backref="podcasts_series", foreign_keys=[series_id]) posted_on = db.Column(db.Date, primary_key=False, default=datetime.datetime.utcnow) source = db.Column(db.String(), primary_key=False) def __init__(self, id, title, body, audio, img, series_id, series, posted_on, source): self.id = id self.title = title self.body = body self.audio = audio self.img = img self.series_id = series_id self.series = series self.posted_on = posted_on self.source = source
class LeetCodeNote(db.Model): __tablename__ = "leetcodenote" myid = db.Column(db.Integer, db.Sequence('leetcodenote_id_seq'), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("users.myid"), nullable=False) problem = db.Column(db.String(255), nullable=False) title = db.Column(db.String(255), nullable=False) solution = db.Column(db.String(255), nullable=False) message = db.Column(db.String(255), nullable=False) date_created = db.Column(db.Integer, nullable=False, default=int(time())) def __init__(self, title, problem, solution, message, user_id): self.title = title self.problem = problem self.solution = solution self.message = message self.user_id = user_id def post(self): db.session.add(self) db.session.commit() def put(self, data): for key in data: if getattr(self, key): setattr(self, key, data[key]) db.session.commit()
class ReplyModel(db.Model): __tablename__ = 'replyes' id = db.Column(db.Integer, db.Sequence('replyes_id_seq'), primary_key=True) text = db.Column(db.String, primary_key=False) post_id = db.Column(db.Integer, ForeignKey('posts.id')) user = db.Column(db.Integer, ForeignKey('users.id')) posted_on = db.Column(db.Date, primary_key=False, default=datetime.datetime.now) post = db.relationship('PostModel', backref='replyes', foreign_keys=[post_id]) def __init__(self, id, text, post_id, user, posted_on): self.id = id self.text = text self.post_id = post_id self.user = user self.posted_on = posted_on def __repr__(self): return ('<id {}').format(self.id)
class ProfileDescriptions(db.Model): __tablename__ = 'profile_descriptions' _local_id = db.Column('local_id', db.BigInteger, db.Sequence('profile_descriptions_local_id_seq'), primary_key=True, unique=True, autoincrement=True) id = db.Column('id', db.BigInteger, db.ForeignKey('profiles.id'), nullable=False) language = db.Column(db.Text, nullable=False) description = db.Column(db.Text, nullable=False) # Unique constraint: (id, language must be unique) __table_args__ = (db.Index('profile_desc_uniq_idx', id, language, unique=True), ) default_language = 'en-US' def __init__(self, id, language, description): # 'id' auto increment self.id = id self.language = language self.description = description def __repr__(self): return '<profile_description %i %s>' % self.id, self.name
class ColorList(db.Model): ''' Represents a white/black list ''' __tablename__ = 'colorlist' ACTION_WHITELIST = 0 ACTION_BLACKLIST = 1 KEY_IP = 0 KEY_TLF = 1 id = db.Column(db.Integer, db.Sequence('user_id_seq'), primary_key=True) # white, black action = db.Column(db.Integer, index=True) # ip, tlf key = db.Column(db.Integer, index=True) value = db.Column(db.String(45), index=True) created = db.Column(db.DateTime, default=datetime.utcnow) modified = db.Column(db.DateTime, default=datetime.utcnow) def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) def __repr__(self): return '<ColorList %r>' % self.id
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, db.Sequence('users_id_seq'), primary_key=True) f_name = db.Column(db.String(100)) l_name = db.Column(db.String(100)) full_name = db.Column(db.String(200)) email = db.Column(db.String(200), unique = True, nullable=False) profile_url = db.Column(db.String(1000)) profile_pic = db.Column(db.String(1000)) verified_email = db.Column(db.Boolean) created_on = db.Column(db.DateTime, default = db.func.now()) updated_on = db.Column(db.DateTime, default = db.func.now(), onupdate = db.func.now()) def __init__(self, f_name, l_name, full_name, email, profile_url, profile_pic, verified_email): self.f_name = f_name self.l_name = l_name self.full_name = full_name self.email = email self.profile_url = profile_url self.profile_pic = profile_pic self.verified_email = verified_email def get_id(self): try: return unicode(self.id) except Exception, e: raise NotImplementationError('No id attribiute')
class PatronMovimiento(db.Model): __tablename__ = "patrones_movimiento" id_patron_movimiento = db.Column( db.Integer, db.Sequence("patrones_movimiento_id_patron_movimiento_seq"), primary_key=True, unique=True, ) nombre = db.Column(db.String()) creado_en = db.Column(db.DateTime, default=datetime.utcnow) actualizado_en = db.Column(db.DateTime, default=None) def __init__(self, nombre): self.nombre = nombre def __repr__(self): return "<PatronMovimiento {}>".format(self.id_patron_movimiento) def to_json(self): return { "id": self.id_patron_movimiento, "nombre": self.nombre, "creado_en": self.creado_en, "actualizado_en": self.actualizado_en, }
class User(db.Model): ''' fs用户信息表 包含手机APP用户 以及 小区设备''' __tablename__ = 'web_user' id = db.Column(db.Integer, db.Sequence('user_id_seq'), primary_key=True) phone = db.Column(db.String(25)) # 电话号码或者设备SIP号 usertype = db.Column(db.Integer) pwd = db.Column(db.String(16)) dtTime = db.Column(db.DateTime) status = db.Column(db.Integer) def json2user(self, json): self.phone = json['Phone'] self.pwd = json['Pwd'] self.usertype = json['Devicetype'] self.dtTime = json['DtTime'] self.status = json['Status'] return self def user2json(self): return { "Phone": self.phone, "Pwd": self.pwd, "Devicetype": self.usertype, "DtTime": self.dtTime, "Status": self.status } def __repr__(self): return '<User %r>' % self.i
class Trip(db.Model): __tablename__ = "trip" id = db.Column(db.Integer, db.Sequence('seq_reg_id', start=1, increment=1), primary_key=True) date = db.Column(db.DateTime) pickup_lat = db.Column(db.Float) pickup_lng = db.Column(db.Float) dropoff_lat = db.Column(db.Float) dropoff_lng = db.Column(db.Float) pickup_location = db.Column(db.String(30)) dropoff_location = db.Column(db.String(30)) def __init__(self, date, pickup_lat, pickup_lng, dropoff_lat, dropoff_lng, pickup_location, dropoff_location): self.date = date self.pickup_lat = pickup_lat self.pickup_lng = pickup_lng self.dropoff_lat = dropoff_lat self.dropoff_lng = dropoff_lng self.pickup_location = pickup_location self.dropoff_location = dropoff_location def __repr__(self): return '<Date %r>' % self.date
class Base(db.Model): ''' Base defines the common fields in all the models ''' __abstract__ = True code = db.Column(db.Integer, db.Sequence('seq_reg_id', start=1, increment=1), primary_key=True) name = db.Column(db.String(20), unique=True, nullable=False) def save(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() def update(self): db.session.commit() return self def get_one(self, code): return self.query.filter_by(code=code).first() def get_all(self): return self.query.order_by(self.code).all()
class Rule(db.Model): __tablename__ = 'rule' id = db.Column(db.Integer, db.Sequence("rule_id_seq"), primary_key=True) definition = db.Column(db.Text) user = db.Column(db.String(255), nullable=False) sense = db.Column(db.Text) sense_id = db.Column(db.Text)
class Opening(db.Model): __tablename__ = 'openings' id = db.Column(db.Integer, db.Sequence('opening_id_seq'), primary_key=True) location_id = db.Column(db.Integer, db.ForeignKey('locations.id')) day = db.Column(db.Integer) open_time_one = db.Column(db.Integer) close_time_one = db.Column(db.Integer) open_time_two = db.Column(db.Integer) close_time_two = db.Column(db.Integer) closed = db.Column(db.Boolean) created_on = db.Column(db.DateTime, default=db.func.now()) updated_on = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) def __init__(self, location_id, day, open_time_one, close_time_one, open_time_two, close_time_two, closed): self.location_id = location_id self.day = day self.open_time_one = open_time_one self.close_time_one = close_time_one self.open_time_two = open_time_two self.close_time_two = close_time_two self.closed = closed
class Conversation(BaseModel, db.Model): __tablename__ = 'conversation' id = Column(Integer, db.Sequence('conversations_id_seq'), primary_key=True) message = Column(Text, primary_key=False) user_id = Column(Integer, ForeignKey('users.id')) conversation_id = Column(Integer, ForeignKey("conversations.id")) author = relationship("User", foreign_keys=[user_id]) conversation = relationship("Conversations", backref="chat", foreign_keys=[conversation_id], order_by=id.desc()) def __init__(self, id=None, message='', user_id=None, conversation_id=None): self.id = id self.message = message self.user_id = user_id self.conversation_id = conversation_id def date_sent(self): return self.created_on.strftime("%A %d %b") def when_sent(self): return self.created_on.strftime("%H:%M")
class EjercicioXBloque(db.Model): __tablename__ = "ejerciciosxbloque" id_ejerciciosxbloque = db.Column( db.Integer, db.Sequence("ejerciciosxbloque_id_ejerciciosxbloque_seq"), primary_key=True, unique=True, ) id_ejercicio = db.Column(db.Integer, db.ForeignKey("ejercicios.id_ejercicio")) id_bloque = db.Column(db.Integer, db.ForeignKey("bloques.id_bloque")) num_ejercicio = db.Column(db.Integer) ejercicio = db.relationship("Ejercicio", uselist=False) # bloque = db.relationship("Bloque", uselist=False) repeticiones = db.Column(db.Integer) carga = db.Column(db.Float) def __init__(self, num_ejercicio, ejercicio, repeticiones, carga): self.num_ejercicio = num_ejercicio self.ejercicio = ejercicio self.repeticiones = repeticiones self.carga = carga def __repr__(self): return "<EjercicioXBloque {}>".format(self.id_ejerciciosxbloque) def to_json(self): return { "id": self.id_ejerciciosxbloque, "num_ejercicio": self.num_ejercicio, "ejercicio": self.ejercicio.nombre, "patron": self.ejercicio.patron.nombre, "carga": self.carga, "repeticiones": self.repeticiones, }
class CostStatic(db.Model): __tablename__ = 'cost_static' _local_id = db.Column('local_id', db.BigInteger, db.Sequence('cost_static_local_id_seq'), primary_key=True, unique=True, autoincrement=True) id = db.Column('id', db.BigInteger, db.ForeignKey('way_types.id'), nullable=False) profile = db.Column('profile', db.BigInteger, db.ForeignKey('profiles.id'), nullable=False) cost_forward = db.Column(db.Numeric(16, 8)) cost_reverse = db.Column(db.Numeric(16, 8)) # unique constraint: (id, profile)-tupel __table_args__ = (db.Index('cost_static_uniq_idx', id, profile, unique=True), ) def __init__(self, id, profile, cost_forward, cost_reverse): self.id = id # way_type id self.profile = profile self.cost_forward = cost_forward self.cost_reverse = cost_reverse def __repr__(self): return '<cost_static %i, profile=%i>' % self.id, self.profile def get_dict(self): return { 'way_type': self.id, 'cost_forward': float(self.cost_forward), 'cost_reverse': float(self.cost_reverse), }
class RequestLog(db.Model): __tablename__ = "request_log" id = db.Column(db.Integer, db.Sequence('field_id'), primary_key=True) name = db.Column(db.String(120), index=True, unique=True) position = db.Column(db.Integer) f_type = db.Column(db.FieldType) # The error is happening here. table_info = db.Column(db.Integer, db.ForeignKey('table_info.id'))
class Plantilla(db.Model): __tablename__ = "plantillas" id_plantilla = db.Column( db.Integer, db.Sequence("plantillas_id_plantilla_seq"), primary_key=True, unique=True, ) sesiones = db.relationship( "SesionXPlantilla", lazy="subquery", backref=db.backref("plantillas", lazy=True), order_by="SesionXPlantilla.id_sesionesxplantilla", cascade="all, delete-orphan", ) nombre = db.Column(db.String(100)) id_nivel = db.Column(db.Integer, db.ForeignKey("niveles.id_nivel")) nivel = db.relationship("Nivel", uselist=False) id_objetivo = db.Column(db.Integer, db.ForeignKey("objetivos.id_objetivo")) objetivo = db.relationship("Objetivo", uselist=False) id_organizacion = db.Column( db.Integer, db.ForeignKey("organizaciones.id_organizacion")) organizacion = db.relationship("Organizacion", uselist=False) sesiones_por_semana = db.Column(db.Integer) creado_en = db.Column(db.DateTime, default=datetime.utcnow) actualizado_en = db.Column(db.DateTime, default=None) def __init__( self, nombre: str, sesiones: List[Sesion], nivel: Nivel, objetivo: Objetivo, organizacion: Organizacion, sesiones_por_semana: int, ): self.sesiones = sesiones self.nombre = nombre self.nivel = nivel self.objetivo = objetivo self.organizacion = organizacion self.sesiones_por_semana = sesiones_por_semana def __repr__(self): return "<Plantilla {}>".format(self.id_plantilla) def to_json(self): return { "id": self.id_plantilla, "sesiones": [sesion.to_json() for sesion in self.sesion], "organizacion": self.organizacion.descripcion, "objetivo": self.objetivo.descripcion, "nivel": self.nivel.descripcion, "sesionesPorSemana": str(self.sesiones_por_semana), "creadoEn": self.creado_en, "actualizadoEn": self.actualizdo_en, }
class Profiles(db.Model): __tablename__ = 'profiles' id = db.Column('id', db.BigInteger, db.Sequence('profiles_id_seq'), primary_key=True, index=True, unique=True, autoincrement=True) name = db.Column(db.Text, nullable=False, unique=True) amount_dyncost = db.Column(db.Numeric(16, 8), nullable=False) def __init__(self, name, amount_dyncost=0.0): # 'id' auto increment self.name = name self.amount_dyncost = amount_dyncost def __repr__(self): return '<profile %i %s>' % self.id, self.name def to_dict_short(self): return { 'id': self.id, 'name': self.name, } def to_dict_long(self, language): cost_list = [] costs = CostStatic.query.filter_by(profile=self.id).all() for cost in costs: cost_list.append(cost.get_dict()) return { 'id': self.id, 'name': self.name, 'description': { language: self.get_description(language) }, 'costs': cost_list, 'amount_dyncost': float(self.amount_dyncost), } def get_name(self): return self.name def get_description(self, language): try: description = ProfileDescriptions.query.filter_by( id=self.id, language=language).one().description except MultipleResultsFound: return 'Multiple profile descriptions for profile \'' + self.id + '\' and language \'' + language + '\' found.' except NoResultFound: if language == ProfileDescriptions.default_language: return 'No profile description found.' else: return self.get_description( ProfileDescriptions.default_language) return description
class Usuario(db.Model): __tablename__ = "usuarios" id_usuario = db.Column( db.Integer, db.Sequence("usuarios_id_usuario_seq"), primary_key=True, unique=True, ) uuid = db.Column(db.String(250), unique=True) username = db.Column(db.String(100), unique=True) email = db.Column(db.String(100), unique=True) nombre = db.Column(db.String(100), unique=True) apellido = db.Column(db.String(100), unique=True) img_url = db.Column(db.String(250), unique=True) fecha_nacimiento = db.Column(db.DateTime) id_genero = db.Column(db.Integer, db.ForeignKey("generos.id_genero")) genero = db.relationship("Genero", uselist=False, lazy=True) altura = db.Column(db.Float) peso = db.Column(db.Float) id_nivel = db.Column(db.Integer, db.ForeignKey("niveles.id_nivel")) nivel = db.relationship("Nivel", uselist=False) rol = db.Column(db.String(100)) creado_en = db.Column(db.DateTime, default=datetime.utcnow) actualizado_en = db.Column(db.DateTime, default=None) baja_en = db.Column(db.DateTime, default=datetime.utcnow) def __init__( self, username: str, email: str, uuid: str = None, nombre: str = None, apellido: str = None, fecha_nacimiento: datetime = None, genero: Genero = None, altura: float = None, peso: float = None, nivel: Nivel = None, img_url: str = None, rol: str = "Cliente", ): self.username = username self.uuid = uuid self.email = email self.nombre = nombre self.apellido = apellido self.fecha_nacimiento = fecha_nacimiento self.genero = genero self.altura = altura self.peso = peso self.nivel = nivel self.img_url = img_url self.rol = rol def __repr__(self): return "<Usuario {}>".format(self.id_usuario)
class ClusterAbbr(db.Model, DictSerializable): __tablename__ = 'cluster_abbr' id = db.Column(db.Integer, db.Sequence("cluster_abbr_id"), primary_key=True) abbr = db.Column(db.String(128)) count = db.Column(db.INT) left = db.Column(db.INT) source_id = db.Column(db.INT)
class CashierCheck(): __tablename__ = 'cashier_check_request' id = db.Column(db.Integer, db.Sequence('cashier_check'), primary_key=True) account_from = db.Column(db.Integer, db.ForeignKey('accounts.id')) account_to = db.Column(db.Integer, db.ForeignKey('accounts.id')) amount = db.Column(db.Numeric) requester_id = db.Column(db.Integer, db.ForeignKey('users.id')) approved = db.Column(db.Boolean)
class Sms(db.Model): ''' 短信验证码表 ''' __tablename__ = 'web_sms' id = db.Column(db.Integer, db.Sequence('sms_id_seq'), primary_key=True) phone = db.Column(db.String(20)) code = db.Column(db.String(6)) dtTime = db.Column(db.DateTime) def __repr__(self): return '<Sms %s,%s,%s>' % self.phone, self.code, self.dtTime
class Association(db.Model): __tablename__ = 'association' id = db.Column(db.Integer, db.Sequence('association_id_seq'), primary_key=True) food_log_id = db.Column(db.Integer, db.ForeignKey('food_logs.id')) food_id = db.Column(db.Integer, db.ForeignKey('foods.id')) quantity = db.Column(db.Float) #extra_data = Column(String(50)) food = db.relationship('Food', backref='foodlog_assocs')
class Community(db.Model): ''' 小区 ''' __tablename__ = 'web_community' id = db.Column(db.Integer, db.Sequence('cmny_id_seq'), primary_key=True) community = db.Column(db.String(100)) communityID = db.Column(db.String(10)) account = db.Column(db.String(20)) pwd = db.Column(db.String(16)) parentAcc = db.Column(db.String(16)) status = db.Column(db.Integer)
class Token(db.Model): ''' 监控设备列表 ''' __tablename__ = 'web_token' id = db.Column(db.Integer, db.Sequence('token_id_seq'), primary_key=True) phone = db.Column(db.String(20)) tokenType = db.Column(db.Integer) token = db.Column(db.String(65)) uuid = db.Column(db.String(40)) dtTime = db.Column(db.DateTime) status = db.Column(db.Integer)