class AccountModel(db.Model): __tablename__ = 'account' id = db.Column(db.Integer(), nullable=False, primary_key=True) nickname = db.Column(db.Unicode(256), nullable=True) email = db.Column(db.Unicode(1024), nullable=True, index=True) email_confirmed = db.Column(db.Boolean(), nullable=False, server_default=sql.false()) _password = db.Column('password', db.String(length=128), nullable=False) info = db.Column(db.MutableDict.as_mutable(db.JSONType()), nullable=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) @hybrid_property def password(self): return self._password @password.setter def _set_password(self, plaintext): self._password = generate_password_hash(plaintext) def is_correct_password(self, plaintext): check_password_hash(self._password, plaintext)
class SlideModel(db.Model): __tablename__ = 'slide' id = db.Column(db.Integer(), nullable=False, primary_key=True) title = db.Column(db.Unicode(256), nullable=True, index=True) describe = db.Column(db.Unicode(1024), nullable=True, index=True) order = db.Column(db.Integer(), nullable=False, index=True) image = db.Column(db.Unicode(length=2083), nullable=False) link = db.Column(db.Unicode(length=2083), nullable=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp())
class MatchModel(db.Model): __tablename__ = 'match' id = db.Column(db.Integer(), nullable=False, primary_key=True) round_id = db.Column(db.Integer(), db.ForeignKey('round.id'), nullable=False, index=True) place = db.Column(db.Unicode(1024), nullable=False) introduction = db.Column(db.UnicodeText(), nullable=False) date_started = db.Column(db.DateTime(timezone=True), nullable=True, index=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) players = db.relationship( 'MatchPlayerModel', primaryjoin='MatchModel.id==MatchPlayerModel.match_id', order_by=MatchPlayerModel.is_home.desc(), foreign_keys='[MatchPlayerModel.match_id]', backref=db.backref('match', lazy='subquery', innerjoin=True), passive_deletes='all', lazy='dynamic') @property def url(self): return url_for("views.match", cid=self.id) def __str__(self): return self.name
class BoardModel(db.Model): __tablename__ = 'board' id = db.Column(db.Integer(), nullable=False, primary_key=True) name = db.Column(db.Unicode(256), nullable=False) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) rounds = db.relationship('RoundModel', primaryjoin='BoardModel.id==RoundModel.board_id', order_by=RoundModel.num.desc(), foreign_keys='[RoundModel.board_id]', backref=db.backref('board', lazy='subquery', innerjoin=True), passive_deletes='all', lazy='dynamic') @property def url(self): return url_for("views.board", cid=self.id) def __str__(self): return self.name
class ArticleModel(db.Model): __tablename__ = 'article' id = db.Column(db.Integer(), nullable=False, primary_key=True) cid = db.Column('channel_id', db.Integer(), db.ForeignKey('channel.id'), nullable=False, index=True) is_sticky = db.Column(db.Boolean(), nullable=False, server_default=sql.false()) title = db.Column(db.Unicode(64), nullable=False, unique=True, index=True) date_published = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) _content = db.relationship( 'ArticleContentModel', backref=db.backref('article', lazy='joined', innerjoin=True), primaryjoin='ArticleModel.id==ArticleContentModel.id', foreign_keys='[ArticleContentModel.id]', uselist=False, cascade='all, delete-orphan') @property def url(self): return url_for('views.article', aid=self.id) @hybrid_property def content(self): return self._content.content @content.setter def content_setter(self, value): if not self._content: self._content = ArticleContentModel(id=self.id, content=value) self._content.content = value @property def html(self): return Markup(self.content) def __str__(self): return self.title
class NaviModel(db.Model): __tablename__ = 'navi' id = db.Column(db.Integer(), nullable=False, primary_key=True) name = db.Column(db.Unicode(256), nullable=False, unique=True, index=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) channels = db.relationship('ChannelModel', secondary=NaviChannelModel.__table__) def __str__(self): return self.name
class StaffModel(db.Model): __tablename__ = 'staff' id = db.Column(db.Integer(), nullable=False, primary_key=True) level_id = db.Column(db.Integer(), db.ForeignKey('level.id'), nullable=False, index=True) name = db.Column(db.Unicode(256), nullable=False) avatar = db.Column(db.Unicode(length=2083), nullable=False) synopsis = db.Column(db.UnicodeText(), nullable=False) info = db.Column(db.MutableDict.as_mutable(db.JSONType()), nullable=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) @hybrid_property def paper(self): return self.info.get('paper') @paper.setter def _set_paper(self, value): self.info['paper'] = value
class TeamModel(db.Model): __tablename__ = 'team' id = db.Column(db.Integer(), nullable=False, primary_key=True) name = db.Column(db.Unicode(256), nullable=False, unique=True, index=True) introduction = db.Column(db.UnicodeText(), nullable=False) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) @property def url(self): return url_for("views.team", cid=self.id) def __str__(self): return self.name
class LevelModel(db.Model): __tablename__ = 'level' id = db.Column(db.Integer(), nullable=False, primary_key=True) title = db.Column(db.Unicode(256), nullable=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) all_staff = db.relationship( 'StaffModel', primaryjoin='LevelModel.id==StaffModel.level_id', order_by='StaffModel.date_created', foreign_keys='[StaffModel.level_id]', backref=db.backref('level', lazy='joined', innerjoin=True), passive_deletes='all', lazy='dynamic') def __str__(self): return self.title
class ArticleModel(db.Model): __tablename__ = 'article' id = db.Column(db.Integer(), nullable=False, primary_key=True) cid = db.Column('channel_id', db.Integer(), db.ForeignKey('channel.id'), nullable=False, index=True) is_sticky = db.Column(db.Boolean(), nullable=False, server_default=sql.false()) title = db.Column(db.Unicode(64), nullable=False, unique=True, index=True) date_published = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) _content = db.relationship( 'ArticleContentModel', backref=db.backref('article', lazy='joined', innerjoin=True), primaryjoin='ArticleModel.id==ArticleContentModel.id', foreign_keys='[ArticleContentModel.id]', uselist=False, cascade='all, delete-orphan') @property def language(self): return self.channel.language @property def title_language(self): if re.match(REGEX, self.title.strip()): return 'en' else: return 'cn' @property def url(self): return url_for('views.article', aid=self.id) @hybrid_property def content(self): return self._content.content @content.setter def content_setter(self, value): if not self._content: self._content = ArticleContentModel(id=self.id, content=value) self._content.content = value @property def html(self): return Markup(self.content) @classmethod def get_article_query(cls, cids=[], limit=10): query = (cls.query.filter(cls.cid.in_(cids)).filter( cls.date_published <= func.now()).order_by( ArticleModel.date_published.desc()).limit(limit)) return query def __str__(self): return self.title
class ChannelModel(db.Model): __tablename__ = 'channel' id = db.Column(db.Integer(), nullable=False, primary_key=True) parent_id = db.Column(db.Integer(), db.ForeignKey('channel.id'), index=True) name = db.Column(db.Unicode(256), nullable=False, unique=True, index=True) date_created = db.Column(db.DateTime(timezone=True), nullable=False, index=True, server_default=db.func.current_timestamp()) _summary = db.relationship( 'ChannelSummaryModel', backref=db.backref('channel', lazy='joined', innerjoin=True), primaryjoin='ChannelModel.id==ChannelSummaryModel.id', foreign_keys='[ChannelSummaryModel.id]', uselist=False, cascade='all, delete-orphan') @hybrid_property def summary(self): return self._summary.content @summary.setter def summary_setter(self, value): if not self._summary: self._summary = ChannelSummaryModel(id=self.id, content=value) self._summary.content = value @property def html(self): return Markup(self.summary) parent = db.relationship('ChannelModel', remote_side=[id], backref='channels') articles = db.relationship( 'ArticleModel', primaryjoin='and_(ChannelModel.id==ArticleModel.cid,' 'ArticleModel.date_published<=func.now())', order_by=articles_order_by, foreign_keys='[ArticleModel.cid]', passive_deletes='all', lazy='dynamic') all_articles = db.relationship( 'ArticleModel', primaryjoin='ChannelModel.id==ArticleModel.cid', order_by=articles_order_by, foreign_keys='[ArticleModel.cid]', backref=db.backref('channel', lazy='joined', innerjoin=True), passive_deletes='all', lazy='dynamic') @property def url(self): return url_for("views.channel", cid=self.id) def __str__(self): return self.name