示例#1
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
示例#2
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
示例#3
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
示例#4
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
示例#5
0
class WorkTag(db.Model):
    tag = db.Column(db.String(50), primary_key=True)

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

    def __repr__(self):
        return '<WorkTag %s>' % self.tag
示例#6
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True)
    abbr = db.Column(db.String(50))
    email = db.Column(db.String(50))
    avatar = db.Column(db.String(200))
    signature = db.Column(db.Text)
    is_active = db.Column(db.Boolean, default=False)
    check_inform_time = db.Column(db.DateTime, default=datetime.datetime.now)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

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

    @property
    def friendly_name(self):
        return '我' if check_is_me(self.id) else self.name
示例#7
0
class Dynasty(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    abbr = db.Column(db.String(50), unique=True)
    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

    @property
    def friendly_start_year(self):
        return "%s年" % str(self.start_year).replace('-', '前')

    @property
    def friendly_end_year(self):
        if self.end_year == 2012:
            return "至今"
        else:
            return "%s年" % str(self.end_year).replace('-', '前') 
示例#8
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>")
示例#9
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
示例#10
0
class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    desc = db.Column(db.String(200))
    icon = db.Column(db.String(200))