Ejemplo n.º 1
0
class Collection(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order = db.Column(db.Integer, default=0)
    name = db.Column(db.String(200), unique=True)
    full_name = db.Column(db.String(200), unique=True)
    desc = db.Column(db.Text())
    cover = db.Column(db.String(200))
    link = db.Column(db.String(300))
    abbr = db.Column(db.String(50))
    created_at = db.Column(db.DateTime, default=datetime.now)
    kind_id = db.Column(db.Integer, db.ForeignKey('collection_kind.id'))
    kind = db.relationship('CollectionKind',
                           backref=db.backref(
                               'collections',
                               lazy='dynamic',
                               order_by="asc(Collection.order)"))

    @property
    def max_work_order(self):
        if self.works.count() == 0:
            return 0
        return CollectionWork.query.filter(CollectionWork.collection_id == self.id). \
            order_by(CollectionWork.order.desc()).first().order

    def __repr__(self):
        return '<Collection %s>' % self.name
Ejemplo n.º 2
0
class WorkType(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    en = db.Column(db.String(50))
    cn = db.Column(db.String(50))

    def __repr__(self):
        return '<WorkType %s>' % self.cn
Ejemplo n.º 3
0
class Dynasty(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    intro = db.Column(db.Text())
    start_year = db.Column(db.Integer)
    end_year = db.Column(db.Integer)

    def __repr__(self):
        return '<Dynasty %s>' % self.name
Ejemplo n.º 4
0
class CollectionKind(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order = db.Column(db.Integer, default=0)
    name = db.Column(db.String(50), unique=True)
    created_at = db.Column(db.DateTime, default=datetime.now)

    @property
    def max_collection_order(self):
        if self.collections.count() == 0:
            return 0
        return Collection.query.filter(Collection.kind_id == self.id). \
            order_by(Collection.order.desc()).first().order
Ejemplo n.º 5
0
class CollectionWork(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=datetime.now)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref('collections', lazy='dynamic'))

    collection_id = db.Column(db.Integer, db.ForeignKey('collection.id'))
    collection = db.relationship('Collection',
                                 backref=db.backref(
                                     'works',
                                     lazy='dynamic',
                                     order_by="asc(CollectionWork.order)"))
Ejemplo n.º 6
0
class CollectWork(db.Model):
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    user = db.relationship('User',
                           backref=db.backref('collect_works', lazy='dynamic'))

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'), primary_key=True)
    work = db.relationship('Work',
                           backref=db.backref('collectors',
                                              lazy='dynamic',
                                              cascade='delete'))

    def __repr__(self):
        return '<User %d collect Work %d>' % (self.user_id, self.work_id)
Ejemplo n.º 7
0
class TopicComment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    topic_id = db.Column(db.Integer,
                         db.ForeignKey('topic.id'),
                         primary_key=True)
    topic = db.relationship('Topic',
                            backref=db.backref(
                                'comments',
                                lazy='dynamic',
                                order_by="asc(TopicComment.create_time)"))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    user = db.relationship('User',
                           backref=db.backref(
                               'topic_comments',
                               lazy='dynamic',
                               order_by="desc(TopicComment.create_time)"))

    def __repr__(self):
        return '<TopicComment %s>' % self.content
Ejemplo n.º 8
0
class WorkReviewComment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    review_id = db.Column(db.Integer,
                          db.ForeignKey('work_review.id'),
                          primary_key=True)
    review = db.relationship(
        'WorkReview',
        backref=db.backref('comments',
                           lazy='dynamic',
                           order_by="desc(WorkReviewComment.create_time)"))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    user = db.relationship('User',
                           backref=db.backref(
                               'work_review_comments',
                               lazy='dynamic',
                               order_by="desc(WorkReviewComment.create_time)"))

    def __repr__(self):
        return '<WorkReviewComment %s>' % self.content
Ejemplo n.º 9
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    content = db.Column(db.Text)
    click_num = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'topics',
                               lazy='dynamic',
                               order_by="desc(Topic.create_time)"))

    def __repr__(self):
        return '<Topic %s>' % self.title
Ejemplo n.º 10
0
class Quote(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quote = db.Column(db.Text())
    created_at = db.Column(db.DateTime, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, default=datetime.datetime.now)

    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))
    author = db.relationship('Author',
                             backref=db.backref('quotes', lazy='dynamic'))

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref('quotes', lazy='dynamic'))

    def __repr__(self):
        return '<Quote %s>' % self.quote
Ejemplo n.º 11
0
class WorkReview(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    content = db.Column(db.Text)
    is_publish = db.Column(db.Boolean)
    click_num = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref(
                               'reviews',
                               lazy='dynamic',
                               order_by="desc(WorkReview.create_time)"))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'work_reviews',
                               lazy='dynamic',
                               order_by="desc(WorkReview.create_time)"))

    def __repr__(self):
        return '<WorkReview %s>' % self.title
Ejemplo n.º 12
0
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    intro = db.Column(db.Text())
    birth_year = db.Column(db.String(20))
    death_year = db.Column(db.String(20))
    updated_at = db.Column(db.DateTime, default=datetime.datetime.now)

    dynasty_id = db.Column(db.Integer, db.ForeignKey('dynasty.id'))
    dynasty = db.relationship('Dynasty',
                              backref=db.backref(
                                  'authors',
                                  lazy='dynamic',
                                  order_by="asc(Author.birth_year)"))

    def __repr__(self):
        return '<Author %s>' % self.name

    @property
    def random_quote(self):
        """Get a random quote of the author"""
        return self.quotes.order_by(db.func.random()).first()
Ejemplo n.º 13
0
class WorkImage(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(200))
    is_original = db.Column(db.Boolean, default=False)
    from_url = db.Column(db.String(250))
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref('images', lazy='dynamic'))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'work_images',
                               lazy='dynamic',
                               order_by="desc(WorkImage.create_time)"))

    @property
    def url(self):
        return current_app.config['OSS_URL'] + self.filename

    def __repr__(self):
        return '<WorkImage %s>' % self.filename
Ejemplo n.º 14
0
class Work(db.Model):
    """作品"""
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    title_suffix = db.Column(db.String(50))  # 完整的标题,用于没有题目的词,使用第一个短句作为其题目
    foreword = db.Column(db.Text())
    content = db.Column(db.Text())
    intro = db.Column(db.Text())
    layout = db.Column(db.String(10))
    highlight = db.Column(db.Boolean, default=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, default=datetime.datetime.now)
    highlight_at = db.Column(db.DateTime)

    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))
    author = db.relationship('Author',
                             backref=db.backref('works', lazy='dynamic'))

    type_id = db.Column(db.Integer, db.ForeignKey('work_type.id'))
    type = db.relationship('WorkType',
                           backref=db.backref('works', lazy='dynamic'))

    @property
    def full_title(self):
        if self.title_suffix and '·' not in self.title:
            return "%s · %s" % (self.title, self.title_suffix)
        else:
            return self.title

    def __repr__(self):
        return '<Work %s>' % self.title