Ejemplo n.º 1
0
class Comment(db.Document):
    author = db.ReferenceField(User)
    post = db.ReferenceField(Post)
    guest_user = db.StringField()  # 用来存匿名用户的
    raw = db.StringField()  # 正文-未加工过的正文
    content = db.StringField()  # 正文
    pub_time = db.DateTimeField()  # 发表时间
    update_time = db.DateTimeField()  # 更新时间
    status = db.StringField(choices=COMMENT_STATUS, default='pending')

    def save(self):
        self.update_time = datetime.datetime.utcnow()
        if not self.pub_time:
            self.pub_time = datetime.datetime.utcnow()

        # raw 转 content
        self.content = get_content_markdown(self.raw)
        return super(Comment, self).save()
Ejemplo n.º 2
0
class Tracker(db.Document):
    post = db.ReferenceField(Post)
    ip = db.StringField()
    user_agent = db.StringField()
    create_time = db.DateTimeField()

    def save(self):
        if not self.create_time:
            self.create_time = datetime.datetime.utcnow()
        return super(Tracker, self).save()
Ejemplo n.º 3
0
class Draft(db.Document):
    title = db.StringField(max_length=255, required=True)  # 标题
    abstract = db.StringField()  # 摘要
    pub_time = db.DateTimeField(default=datetime.datetime.now)  # 创建时间
    update_time = db.DateTimeField()  # 更新时间
    raw = db.StringField(required=True)  # 正文-未加工过的正文
    content = db.StringField(required=True)  # 正文
    author = db.ReferenceField(User)  # 这里的author指向User
    category = db.StringField(max_length=64)  # 分类
    tags = db.ListField(db.StringField(max_length=32))  # 标签
    is_draft = db.BooleanField(default=True)  # 是否存有草稿
    post = db.ReferenceField(Post)  # 指向Post

    # 自定义save()
    def save(self):
        self.update_time = datetime.datetime.utcnow()
        if not self.pub_time:
            self.pub_time = datetime.datetime.utcnow()

        # raw 转 content
        self.content = get_content_markdown(self.raw)
        return super(Draft, self).save()
Ejemplo n.º 4
0
class PostStatistics(db.Document):
    post = db.ReferenceField(Post)
    visit_count = db.IntField(default=0)
    verbose_count_base = db.IntField(default=0)