Пример #1
0
class Work(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    foreword = db.Column(db.Text())
    content = db.Column(db.Text())
    intro = db.Column(db.Text())
    create_time = db.Column(db.DateTime)

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

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

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

    @property
    def clean_content(self):
        c = re.sub(r'<([^<]+)>', '', self.content)
        c = c.replace('%', '')
        c = c.replace('(一)', "")
        c = c.replace('(一)', "")
        return c

    @property
    def friendly_content(self):
        """
        Add comment -> Split ci -> Generate paragraph
        """
        c = re.sub(r'<([^<^b]+)>', r"<sup title='\1'></sup>", self.content)
        c = c.replace('%', "&nbsp;&nbsp;")
        c = markdown2.markdown(c)
        return c
Пример #2
0
class WorkTag(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'), primary_key=True)
    work = db.relationship('Work', backref=db.backref('tags'))

    tag_id = db.Column(db.Integer, db.ForeignKey('tag.id'), primary_key=True)
    tag = db.relationship('Tag', backref=db.backref('works'))

    def __repr__(self):
        return '<WorkTag %s>' % self.tag
Пример #3
0
class AuthorQuote(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quote = db.Column(db.Text())

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

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

    def __repr__(self):
        return '<AuthorQuote %s>' % self.quote
Пример #4
0
class WorkImage(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String(200))
    filename = db.Column(db.String(200))
    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'))

    def __repr__(self):
        return '<WorkImage %s>' % self.filename
Пример #5
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)
Пример #6
0
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True)
    abbr = db.Column(db.String(50), unique=True)
    intro = db.Column(db.Text())
    birth_year = db.Column(db.String(20))
    death_year = db.Column(db.String(20))

    dynasty_id = db.Column(db.Integer, db.ForeignKey('dynasty.id'))
    dynasty = db.relationship('Dynasty',
                              backref=db.backref('authors', lazy='dynamic'))

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

    @property
    def random_quote(self):
        """
        Get a random quote of the author
        """
        if not hasattr(self, '_random_quote'):
            self._random_quote = AuthorQuote.query.filter(
                AuthorQuote.author_id == self.id).order_by(
                    db.func.rand()).first()
        return self._random_quote
Пример #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'))

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

    @property
    def friendly_create_time(self):
        return time_diff(self.create_time)

    def __repr__(self):
        return '<TopicComment %s>' % self.content
Пример #8
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'))

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

    @property
    def friendly_create_time(self):
        return time_diff(self.create_time)

    @property
    def friendly_content(self):
        return self.content.replace('\n', "<div class='text-gap'></div>")

    def __repr__(self):
        return '<WorkReview %s>' % self.title
Пример #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'))

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

    @property
    def friendly_create_time(self):
        return time_diff(self.create_time)

    @property
    def friendly_content(self):
        return self.content.replace('\n', "<div class='text-gap'></div>")