class Kontkurs(db.Model): id = db.Column('id_1', db.Integer, primary_key=True) title = db.Column("obozn") shup = db.Column(db.Integer) spclntion = db.Column(db.Integer) kurs = db.Column(db.Integer) fil = db.Column(db.Integer) fac_id = db.Column("fac", db.Integer, db.ForeignKey('vacfac.id_5')) aobozn_id = db.Column("aobozn", db.Integer, db.ForeignKey('vacaobozn.id_6')) stud = db.Column(db.Integer) groups = db.Column(db.Integer) pgroups = db.Column(db.Integer) smenao = db.Column(db.Integer) smenav = db.Column(db.Integer) groupkey = db.Column(db.Integer) undoworksps = db.Column(db.String(250)) anothernumstudsps = db.Column(db.String(250)) newnumstud = db.Column(db.SmallInteger) ntcgraph = db.Column(db.SmallInteger) syear = db.Column(db.Integer) groupslist = db.relationship('Kontgrp', backref='kontkurs', lazy='joined') kontlist = db.relationship('Kontlist', backref='kontkurs', lazy='select') raspnagr = db.relationship("Raspnagr", backref=db.backref('kontkurs', lazy='select')) def __str__(self, *args, **kwargs): return "<Kontkurs: {}>".format(self.title.strip()) def __repr__(self): return str(self) def get_title(self): return self.title.replace("(И,О)", "")
class SQLModel(db.Model): """ sql """ __tablename__ = "sql_model" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False, comment="SQL名") project_id = db.Column(db.ForeignKey("requirement_model.id")) project = db.relationship('RequirementModel', backref=db.backref('sql_model', lazy='dynamic')) database_id = db.Column(db.ForeignKey("database_model.id")) database = db.relationship('DatabaseModel', backref=db.backref('sql_model', lazy='dynamic')) content = db.Column(db.Text, nullable=False, comment="sql语句") special_field = db.Column(db.String(64), nullable=False, comment="特殊字段") parent_id = db.Column(db.Integer, db.ForeignKey("sql_model.id")) parent = db.relationship("SQLModel", remote_side=[id]) parent_field = db.Column(db.String(64), nullable=False, comment="父字段") is_deleted = db.Column(db.Boolean, default=False) dt_create = db.Column(db.DateTime, default=time_utils.now_dt) dt_update = db.Column(db.DateTime, default=time_utils.now_dt, onupdate=time_utils.now_dt) def __repr__(self): return self.name def __str__(self): return self.name
class Zanlist(db.Model): __tablename__ = "zanlist" # __mapper_args__ = { # 'primary_key': ['zanlist.zants', 'zanlist.zan'] # } zants = db.Column(db.Integer, db.ForeignKey("zansps.id_54"), primary_key=True) raspnagr_id = db.Column("zan", db.Integer, db.ForeignKey("raspnagr.id_51"))
class UserProjectLink(db.Model): __tablename__ = "user_project" user_id = db.Column(db.Integer, db.ForeignKey("users.id"), primary_key=True) project_id = db.Column(db.Integer, db.ForeignKey("projects.id"), primary_key=True)
class Complaint(db.Model): __tablename__ = 'Complaint' id = db.Column(db.Integer, primary_key=True) comment = db.Column(db.Text(collation='utf8_bin'), nullable=False) flat_id = db.Column(db.ForeignKey('Flat.id', onupdate='CASCADE'), nullable=False, index=True) comp_type_id = db.Column(db.ForeignKey('TypeComplaint.id', onupdate='CASCADE'), nullable=False, index=True) date = db.Column(db.Date, nullable=False) comp_type = db.relationship('TypeComplaint', primaryjoin='Complaint.comp_type_id == TypeComplaint.id', backref='complaints') flat = db.relationship('Flat', primaryjoin='Complaint.flat_id == Flat.id', backref='complaints')
class Flat(db.Model): __tablename__ = 'Flat' id = db.Column(db.Integer, primary_key=True) size = db.Column(db.Integer, nullable=False) owner_id = db.Column(db.ForeignKey('Owner.id', ondelete='SET NULL', onupdate='CASCADE'), index=True) house_id = db.Column(db.ForeignKey('House.id', ondelete='SET NULL', onupdate='CASCADE'), index=True) num = db.Column(db.Integer, nullable=False) house = db.relationship('House', primaryjoin='Flat.house_id == House.id', backref='flats') owner = db.relationship('Owner', primaryjoin='Flat.owner_id == Owner.id', backref='flats')
class Publication_Download(db.Model): __tablename__ = 'publication_download' __table_args__ = (db.UniqueConstraint('user_id', 'publication_id', name='_pub_download_track'), ) id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users_user.id')) publication_id = db.Column(db.Integer, db.ForeignKey('publication.id')) datetime_on = db.Column(db.DateTime, default=now) publication = db.relationship('Publication', back_populates='downloads')
class TaskLock(Base): __tablename__ = 'cluster_task_lock' cluster_id = db.Column(db.ForeignKey(Cluster.id), nullable=False, unique=True) task_id = db.Column(db.ForeignKey(ClusterTask.id), nullable=False, unique=True) task = db.relationship(ClusterTask, foreign_keys='TaskLock.task_id') step_id = db.Column(db.ForeignKey(TaskStep.id), unique=True) step = db.relationship(TaskStep, foreign_keys='TaskLock.step_id')
class ArticleDB(db.Model): __tablename__ = "project_articles" id = db.Column(db.Integer, primary_key=True) info = db.Column(db.Text) created = db.Column(db.DateTime(True), default=dt.utcnow) project_id = db.Column(db.Integer, db.ForeignKey("projects.id")) user_id = db.Column(db.Integer, db.ForeignKey("users.id")) project = db.relationship("Project", back_populates="articles") user = db.relationship("User", foreign_keys=user_id)
class AudActions(db.Model): __tablename__ = "aud_actions" id = db.Column('id', db.Integer, primary_key=True) aud = db.Column("aud_id", db.Integer, db.ForeignKey('auditories.id_60')) aud_to = db.Column("aud_to_id", db.Integer, db.ForeignKey('auditories.id_60')) kont = db.Column(db.Integer) action = db.Column(db.SmallInteger) comment = db.Column(db.String(100)) prep_id = db.Column(db.Integer, db.ForeignKey('prepods.id_61')) date = db.Column(db.DateTime) para = db.Column(db.SmallInteger) para_count = db.Column(db.SmallInteger)
class File(db.Model): __tablename__ = "project_files" id = db.Column(db.Integer, primary_key=True) path = db.Column(db.Text) size = db.Column(db.Integer) comment = db.Column(db.Text) created = db.Column(db.DateTime(True), default=dt.utcnow) project_id = db.Column(db.Integer, db.ForeignKey("projects.id")) user_id = db.Column(db.Integer, db.ForeignKey("users.id")) project = db.relationship("Project", back_populates="files") user = db.relationship("User", foreign_keys=user_id)
class DireitoAcesso(db.Model, CRUD): __tablename__ = "direito_acesso" id = db.Column(db.Integer, primary_key=True) id_usuario = db.Column(db.Integer, db.ForeignKey("usuario.id"), nullable=False) id_sala = db.Column(db.Integer, db.ForeignKey("sala.id"), nullable=False) nome_sala = db.relationship("Sala", uselist=False) alive = db.Column(db.Boolean, nullable=False) def __init__(self, id_usuario, id_sala): self.id_usuario = id_usuario self.id_sala = id_sala self.alive = True
class Client(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(), nullable=False) last_name = db.Column(db.String(), nullable=False) gender = db.Column(db.String(), nullable=False) country = db.Column(db.String(), nullable=False) dob = db.Column(db.String(), nullable=False) phone_no = db.Column(db.Integer(), nullable=False) criminal_record = db.Column(db.Boolean, default=False) ssn = db.Column(db.Integer(), nullable=False) date_registered = db.Column(db.DateTime, nullable=False, default=datetime.now) agent_id = db.Column(db.Integer, db.ForeignKey('agent.id')) apartment_id = db.Column(db.Integer, db.ForeignKey('apartment.id'))
class Proxy(Base): __tablename__ = 'proxy' host = db.Column(db.String(255), nullable=False) port = db.Column(db.Integer, nullable=False) eru_container_id = db.Column(db.String(64), index=True) cluster_id = db.Column(db.ForeignKey(Cluster.id), index=True) suppress_alert = db.Column(db.Integer, nullable=False, default=1) proxy_type = db.Column(db.Integer, nullable=False, default=0) __table_args__ = (db.Index('address', 'host', 'port', unique=True), ) @cached_property def containerized(self): return self.eru_container_id is not None @cached_property def container_info(self): from flask import g if g.container_client is None or not self.containerized: return None return g.container_client.get_container(self.eru_container_id) @cached_property def cluster(self): return Cluster.query.get(self.cluster_id) def proxy_typename(self): if self.proxy_type == TYPE_CERBERUS: return 'Cerberus' elif self.proxy_type == TYPE_CORVUS: return 'Corvus' else: return 'Unknow'
class Comment(Machine, db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(80), nullable=False) content = db.Column(db.String(80), nullable=False) created = db.Column(db.DateTime, default=datetime.utcnow()) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False) status = db.Column(db.String(80), nullable=False) def __init__(self, **kwargs): super(Comment, self).__init__(**kwargs) # 状态定义 states = ['wait', 'pass', 'not pass'] Machine.__init__(self, states=states, initial='wait') self.add_transition('review', 'wait', 'pass') self.status = 'wait' # Machine(self, states, transitions=transitions) def __repr__(self): return '<Comment %r>' % self.content def on_enter_pass(self): self.status = 'pass' db.session.commit() print('wait for u')
class WishAuddPara(db.Model): __tablename__ = "wishauddpara" wish = db.Column("wish", db.Integer, db.ForeignKey('wishaudd.id_62'), primary_key=True) para = db.Column("para", db.SmallInteger) wish_instance = db.relationship('WishAudd', backref=db.backref('pairs', lazy='joined'))
class Auditory(db.Model): __tablename__ = "auditories" id = db.Column('id_60', db.Integer, primary_key=True) title = db.Column("obozn", db.String(20)) korp_id = db.Column("korp", db.Integer, db.ForeignKey('vackorp.id_67')) maxstud = db.Column(db.SmallInteger) specoborud = db.Column(db.SmallInteger) def __str__(self, *args, **kwargs): return "<Auditory: {}>".format(self.title.strip()) def __repr__(self): return str(self) @staticmethod def get_key(title: str): title = title.strip().lower().replace("_вт", "").replace("-", "").replace(".", "") title = title.translate(LETTER_MAPPING_TABLE) return title @staticmethod def get_new_aud_title(title): return f"enter_{Auditory.get_key(title)}" raspnagr = db.relationship('Raspnagr', backref=db.backref('auditory', lazy='joined'), lazy='dynamic') raspis = db.relationship('Raspis', backref=db.backref('auditory', lazy='joined'), lazy='dynamic')
class RedisNode(Base): __tablename__ = 'redis_node' host = db.Column(db.String(255), nullable=False) port = db.Column(db.Integer, nullable=False) eru_container_id = db.Column(db.String(64), index=True) assignee_id = db.Column(db.ForeignKey(Cluster.id), index=True) suppress_alert = db.Column(db.Integer, nullable=False, default=1) __table_args__ = (db.Index('address', 'host', 'port', unique=True), ) def free(self): return self.assignee_id is None @cached_property def eru_deployed(self): return self.eru_container_id is not None @cached_property def eru_info(self): import eru_utils if eru_utils.eru_client is None or not self.eru_deployed: return None try: return eru_utils.eru_client.get_container(self.eru_container_id) except EruException as e: logging.exception(e) return { 'version': '-', 'host': '-', 'created': 'CONTAINER NOT ALIVE', }
class Order_items(db.Model): __tablename__ = 'order_items' id = db.Column(db.Integer, primary_key=True) order_id = db.Column(db.Integer, db.ForeignKey('orders.id')) price_per_unit = db.Column(db.Float) quantity = db.Column(db.Integer) product = db.Column(db.String()) deliveries = db.relationship("Deliveries") def __init__(self, order_id, price_per_unit, quantity, product): self.order_id = order_id self.price_per_unit = price_per_unit self.quantity = quantity self.product = product def __repr__(self): return '<id {}>'.format(self.id) def serialize(self): return { 'id': self.id, 'order_id': self.order_id, 'price_per_unit': self.price_per_unit, 'quantity': self.quantity, 'product': self.product, 'deliveries': [delivery.serialize() for delivery in self.deliveries] }
class ClusterBalancePlan(Base): __tablename__ = 'cluster_balance_plan' cluster_id = db.Column(db.ForeignKey(Cluster.id), unique=True, nullable=False) balance_plan_json = db.Column(DB_TEXT_TYPE, nullable=False) @cached_property def balance_plan(self): return json.loads(self.balance_plan_json) def save(self): self.balance_plan_json = json.dumps(self.balance_plan) db.session.add(self) db.session.flush() @cached_property def pod(self): return self.balance_plan['pod'] @cached_property def host(self): return self.balance_plan.get('host') @cached_property def slaves(self): return self.balance_plan.get('slaves', []) @cached_property def aof(self): return (self.balance_plan.get('entrypoint') == 'aof' or self.balance_plan['aof'])
class TasksLogModel(db.Model): """ 任务日志 """ __tablename__ = "tasks_log_model" id = db.Column(db.Integer, primary_key=True) ex_type = db.Column(db.Integer, comment="执行类型") task_no = db.Column(db.ForeignKey("tasks_model.id")) task = db.relationship('TasksModel', backref=db.backref('tasks_log_model', lazy='dynamic')) return_info = db.Column(db.Text, nullable=True, comment="返回信息") dt_handled = db.Column(db.DateTime, default=time_utils.now_dt, comment="处理时间") is_successful = db.Column(db.Boolean, default=True, comment="是否成功") recipient = db.Column(db.Text, nullable=True, comment="收信人") file_name = db.Column(db.String(128), nullable=True, comment="文件名") is_deleted = db.Column(db.Boolean, default=False) dt_create = db.Column(db.DateTime, default=time_utils.now_dt) dt_update = db.Column(db.DateTime, default=time_utils.now_dt, onupdate=time_utils.now_dt) def __repr__(self): return str(self.task_no) def __str__(self): return str(self.id)
class Review(db.Model): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(), nullable=False) email = db.Column(db.String(), nullable=False) message = db.Column(db.String(), nullable=False) apartment_id = db.Column(db.Integer, db.ForeignKey('apartment.id')) date_comment = db.Column(db.DateTime, nullable=False, default=datetime.now)
class RequirementModel(db.Model): """ 需求 """ __tablename__ = "requirement_model" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False, comment="项目名") comments = db.Column(db.String(128), nullable=True, comment="备注") user_mail_list = db.Column(db.Text, nullable=False, comment="用户邮箱") # sqls = db.relationship('SQLModel', backref='project', lazy='dynamic') # tasks = db.relationship('TasksModel', backref='project', lazy='dynamic') task_type_id = db.Column(db.ForeignKey("task_type_model.id")) task_type = db.relationship('TaskTypeModel', backref=db.backref('requirement_model', lazy='dynamic')) is_deleted = db.Column(db.Boolean, default=False) dt_create = db.Column(db.DateTime, default=time_utils.now_dt) dt_update = db.Column(db.DateTime, default=time_utils.now_dt, onupdate=time_utils.now_dt) def __repr__(self): return self.name def __str__(self): return self.name
class Proxy(Base): __tablename__ = 'proxy' host = db.Column(db.String(255), nullable=False) port = db.Column(db.Integer, nullable=False) eru_container_id = db.Column(db.String(64), index=True) cluster_id = db.Column(db.ForeignKey(Cluster.id), index=True) suppress_alert = db.Column(db.Integer, nullable=False, default=1) __table_args__ = (db.Index('address', 'host', 'port', unique=True), ) @cached_property def eru_deployed(self): return self.eru_container_id is not None @cached_property def eru_info(self): import eru_utils if eru_utils.eru_client is None or not self.eru_deployed: return None return eru_utils.eru_client.get_container(self.eru_container_id) @cached_property def cluster(self): return Cluster.query.get(self.cluster_id)
class Request(db.Model): __tablename__ = 'Request' id = db.Column(db.Integer, primary_key=True) spec_id = db.Column(db.ForeignKey('Specialist.id', onupdate='CASCADE'), nullable=False, index=True) flat_id = db.Column(db.ForeignKey('Flat.id', onupdate='CASCADE'), nullable=False, index=True) date = db.Column(db.Date, nullable=False) comment = db.Column(db.Text(collation='utf8_bin'), nullable=False) flat = db.relationship('Flat', primaryjoin='Request.flat_id == Flat.id', backref='requests') spec = db.relationship('Specialist', primaryjoin='Request.spec_id == Specialist.id', backref='requests') def __init__(self, s, f, d, c): self.spec_id = s self.flat_id = f self.date = d self.comment = c
class LimboUser(db.Model): __tablename__ = "limbo_users" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128)) surname = db.Column(db.String(128)) email = db.Column(db.String(128)) phone = db.Column(db.String(10)) lab = db.Column(db.String(128)) position = db.Column(db.String(128)) login = db.Column(db.String(128), unique=True) active = db.Column(db.Boolean, default=False) comment = db.Column(db.Text) modified = db.Column(db.DateTime(True)) created = db.Column(db.DateTime(True)) ref_id = db.Column(db.Integer, db.ForeignKey("users.id")) reference = db.relationship("User", foreign_keys=ref_id) acl_id = db.Column(db.Integer, db.ForeignKey("acl.id")) def __repr__(self): return '<Limbo User {}>'.format(self.login) def full_name(self): if self.name and self.surname: return "%s %s" % (self.name.capitalize(), self.surname.capitalize()) return "Not available" def task_ready(self): return "login: %s and name: %s and surname: %s and email: %s" % ( self.login, self.name, self.surname, self.email) def to_dict(self): return { "id": self.id, "login": self.login if self.login else "", "name": self.name if self.name else "", "fullname": self.full_name(), "surname": self.surname if self.surname else "", "email": self.email if self.email else "", "phone": self.phone if self.phone else "", "lab": self.lab if self.lab else "", "position": self.position if self.position else "", "active": self.active if self.active else "", "comment": self.comment if self.comment else "", }
class Follow(db.Model): __tablename__ = "follows" id = db.Column(db.Integer, autoincrement=True, primary_key=True) follower_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) followee_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) follower = db.relationship('User', backref=db.backref('followers', lazy=True), foreign_keys=[follower_id]) followee = db.relationship('User', backref=db.backref('followees', lazy=True), foreign_keys=[followee_id])
class TriggerTarget(db.Model): __tablename__ = 'triggertargets' id = db.Column(db.Integer, primary_key=True) triggerID = db.Column(db.Integer, db.ForeignKey('triggers.id')) type = db.Column(db.Enum('email', 'sms')) address = db.Column(db.String(length=100)) snsSubscription = db.Column(db.String(length=200))
class Evento(db.Model, CRUD): __tablename__ = "eventos" id = db.Column(db.Integer, primary_key=True) evento = db.Column(db.Enum(Evento), nullable=False) horario = db.Column(db.DateTime, nullable=False) # id_direito_acesso = db.Column(db.Integer, db.ForeignKey("direito_acesso.id")) id_usuario = db.Column(db.Integer, db.ForeignKey("usuario.id"), nullable=False) id_sala = db.Column(db.Integer, db.ForeignKey("sala.id"), nullable=False) def __init__(self, evento, horario, id_usuario, id_sala): self.evento = evento self.horario = horario self.id_usuario = id_usuario self.id_sala = id_sala
class Subreddit(db.Model): """ """ __tablename__ = 'subreddits_subreddit' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(SUBREDDIT.MAX_NAME), unique=True) group = db.Column(db.String(SUBREDDIT.MAX_NAME)) description = db.Column(db.String(SUBREDDIT.MAX_DESCRIPTION)) admin_id = db.Column(db.Integer, db.ForeignKey('users_user.id')) created_on = db.Column(db.DateTime, default=db.func.now()) updated_on = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) threads = db.relationship('Thread', backref='subreddit', lazy='dynamic') status = db.Column(db.SmallInteger, default=SUBREDDIT.ALIVE) def __repr__(self): return '<Subreddit %r>' % (self.name) def get_threads(self, order_by='timestamp'): """ default order by timestamp """ if order_by == 'timestamp': return self.threads.order_by(db.desc(Thread.created_on)).\ all()[:SUBREDDIT.MAX_THREADS] else: return self.threads.order_by(db.desc(Thread.created_on)).\ all()[:SUBREDDIT.MAX_THREADS] def get_status(self): """ returns string form of status, 0 = 'dead', 1 = 'alive' """ return SUBREDDIT.STATUS[self.status] def get_age(self): """ returns the raw age of this subreddit in seconds """ return (self.created_on - datetime.datetime(1970, 1, 1)).total_seconds() def pretty_date(self, typeof='created'): """ returns a humanized version of the raw age of this subreddit, eg: 34 minutes ago versus 2040 seconds ago. """ if typeof == 'created': return utils.pretty_date(self.created_on) elif typeof == 'updated': return utils.pretty_date(self.updated_on) """