class Category(db.Model): __tablename__ = 'article_categories' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40)) 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 BuyRankings(db.Model): """ 购买排行(用于书籍排行) """ __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'} id = db.Column(db.Integer(), primary_key=True) # ID book_id = db.Column(db.Integer(), index=True) # 书籍ID book_name = db.Column(db.String(100)) # 书籍名称 channel_type = db.Column(db.SmallInteger(), index=True) #1男2女 author_name = db.Column(db.String(50))#作者 is_publish = db.Column(db.Integer()) # 是否出版(1:是;2:否) status = db.Column(db.Integer())# 连载状态(1:已完结;2:未完结) created = db.Column(db.DateTime) # 创建时间 buy_num = db.Column(db.Integer()) #购买次数 book_time = db.Column(db.DateTime) # 创建时间 def __init__(self, book_id, channel_type, author_name, is_publish, status, created, buy_num, book_name, book_time): self.book_id = book_id self.channel_type = channel_type self.author_name = author_name self.is_publish = is_publish self.status = status self.created = created self.buy_num = buy_num self.book_name = book_name self.book_time = book_time
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True) email = db.Column(db.String(120), unique=True) bookmarks = db.relationship('Bookmark', backref='user', lazy='dynamic') password_hash = db.Column(db.String(256)) @property def password(self): raise AttributeError('Password: Write Only Field. Check the models file if you are unsure') @password.setter def password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) @staticmethod def get_by_username(username): return User.query.filter_by(username=username).first() # ToDo: Add a get_userid_by_user def __repr__(self): return '<User %r>' % self.username
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True, index=True, nullable=False) username = db.Column(db.String(64), unique=True, index=True, nullable=False) password = db.Column(db.String(128), nullable=False) pic = db.Column(db.String(20), nullable=False, default='default.jpg') post_ids = db.relationship('Post', backref='author', lazy=True) def create_post(self, vals): post = Post( title=vals.get('title'), url=vals.get('url'), description=vals.get('description'), user_id=self.id, channel_id=vals.get('channel'), ) return post def create_channel(self, vals): channel = Post( title=vals.get('title'), description=vals.get('description'), admin_id=self.id, ) return channel def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Discipline(db.Model): __tablename__ = "vacpred" id = db.Column('id_15', db.Integer, primary_key=True) title = db.Column("pred", db.String(250)) titles = db.Column("preds", db.String(250)) raspnagr = db.relationship('Raspnagr', backref=db.backref('discipline', 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 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 PollingStat(Base): __tablename__ = 'polling_stat' polling_time = db.Column(db.DateTime, default=datetime.now, nullable=False, index=True) stat_json = db.Column(DB_TEXT_TYPE, nullable=False) def __init__(self, nodes_ok, nodes_fail, proxies_ok, proxies_fail): Base.__init__(self, stat_json=json.dumps({ 'nodes_ok': nodes_ok, 'nodes_fail': nodes_fail, 'proxies_ok': proxies_ok, 'proxies_fail': proxies_fail, })) @cached_property def stat(self): return json.loads(self.stat_json) @cached_property def nodes_ok(self): return self.stat['nodes_ok'] @cached_property def nodes_fail(self): return self.stat['nodes_fail'] @cached_property def proxies_ok(self): return self.stat['proxies_ok'] @cached_property def proxies_fail(self): return self.stat['proxies_fail']
class Chair(db.Model): __tablename__ = "vackaf" id = db.Column('id_17', db.Integer, primary_key=True) title = db.Column("kaf", db.String(100)) short_title = db.Column("sokr", db.String(10)) raspnagr = db.relationship('Raspnagr', backref=db.backref('chair', lazy='joined'), lazy='dynamic')
class User(db.Model): id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(80), unique=True) password = db.Column(db.String(128)) last_login = db.Column(db.String(64)) def update_login_time(self): self.last_login = datetime.utcnow().isoformat(timespec='seconds') + 'Z' db.session.commit() @property def is_authenticated(self): return True @property def is_active(self): return True @property def is_anonymous(self): return False def get_id(self): return self.id def __unicode__(self): return self.username
class Orders(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) created_at = db.Column(db.Date) order_name = db.Column(db.String()) customer_id = db.Column(db.String()) order_items = db.relationship("Order_items") def __init__(self, created_at, order_name, customer_id): self.created_at = created_at self.order_name = order_name self.customer_id = customer_id def __repr__(self): return '<id {}>'.format(self.id) def serialize(self, customer={}): return { 'id': self.id, 'created_at': self.created_at, 'order_name': self.order_name, 'customer_id': self.customer_id, 'order_items': [order_item.serialize() for order_item in self.order_items], 'customer': customer }
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 FAQ(db.Model): id = db.Column(db.Integer, primary_key=True) question = db.Column(db.String(128), index=True, unique=True) answer = db.Column(db.String(128)) def __repr__(self): return '<Question {}>'.format(self.question)
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 SmsCaptcha(db.Model): """ 验证码记录 """ id = db.Column(db.Integer, primary_key=True) phone = db.Column(db.String(20)) captcha = db.Column(db.String(10)) action = db.Column(db.Integer) # 0 - unknown, 1 - register 2 - reset pwd created = db.Column(db.DateTime, server_default=func.now())
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 Teacher(db.Model): __tablename__ = "prepods" id = db.Column('id_61', db.Integer, primary_key=True) full_name = db.Column('prep', db.String(100)) name = db.Column('preps', db.String(50)) raspnagr = db.relationship('Raspnagr', backref=db.backref('teacher', lazy='joined'), lazy='dynamic')
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 BindPhoneActivity(db.Model): """绑定手机送288阅币活动""" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, unique=True) created = db.Column(db.DateTime, server_default=func.now()) def __init__(self, user_id): self.user_id = user_id
class House(db.Model): __tablename__ = 'House' id = db.Column(db.Integer, primary_key=True) adress = db.Column(db.String(200, 'utf8_bin'), nullable=False) photo = db.Column(db.String(200, 'utf8_bin')) name = db.Column(db.String(200, 'utf8_bin'), nullable=False) descr = db.Column(db.Text(collation='utf8_bin'), nullable=False)
class Silla(db.Model): id = db.Column(db.Integer, unique=True, primary_key=True) tipo = db.Column(db.Text) precio = db.Column(db.Integer) def __init__(self, tipo, precio): self.tipo = tipo self.precio = precio
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 WishKontdPara(db.Model): __tablename__ = "wishkontdpara" __table_args__ = ( PrimaryKeyConstraint('wish', 'para'), ) wish = db.Column("wish", db.Integer) para = db.Column("para", db.SmallInteger)
class Specialist(db.Model): __tablename__ = 'Specialist' id = db.Column(db.Integer, primary_key=True) fio = db.Column(db.String(200, 'utf8_bin'), nullable=False) experience = db.Column(db.Integer, nullable=False) prof_id = db.Column(db.ForeignKey('Prof.id', onupdate='CASCADE'), nullable=False, index=True) prof = db.relationship('Prof', primaryjoin='Specialist.prof_id == Prof.id', backref='specialists')
class Proxy(Base): __tablename__ = 'proxy' host = db.Column(db.String(32), nullable=False) port = db.Column(db.Integer, nullable=False) 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), )
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 AdminUserGroup(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64)) def __init__(self, name): self.name = name def to_admin_dict(self): return dict(id=self.id, name=self.name)
class ContainerImage(Base): __tablename__ = 'cont_image' type = db.Column(db.Integer, index=True, default=TYPE_REDIS, nullable=False) name = db.Column(db.String(255), nullable=False, index=True, unique=True) description = db.Column(db.String(255)) creation = db.Column(db.DateTime)
class UserBalance(db.Model): """ 用户余额 """ user_id = db.Column(db.Integer, primary_key=True) # 用户ID balance = db.Column(db.BigInteger, nullable=False) # 余额 total = db.Column(db.BigInteger, nullable=False, default=0) # 累计充值 def __init__(self, user_id, balance, total=0): self.user_id = user_id self.balance = balance self.total = total