Beispiel #1
0
 def get(self, pid):
     try:
         post = Post.get(id=pid)
         post.tags = Tag.select().join(PostTag).join(Post).where(Post.id == pid)
         self.render('post/edit.html', post=post, side=self.get_side(), title='编辑-' + post.title)
     except DoesNotExist:
         self.send_error(404)
Beispiel #2
0
    def get_side():
        """获取侧边栏内容

        通用侧边栏数据
        """
        side = {
            "recent_post": Post.select().limit(conf["RECENT_POST_NUM"]),
            "random_post": Post.select().order_by(fn.Rand()).limit(conf["RANDOM_POST_NUM"]),
            "tags": Tag.select(Tag, fn.Count(Post.id).alias("count")).join(PostTag).join(Post).group_by(Tag),
        }
        return side
Beispiel #3
0
 def get(self, pid):
     try:
         post = Post.get(id=pid)
         post.tags = Tag.select().join(PostTag).join(Post).where(
             Post.id == pid)
         self.render('post/edit.html',
                     post=post,
                     side=self.get_side(),
                     title='编辑-' + post.title)
     except DoesNotExist:
         self.send_error(404)
Beispiel #4
0
def view_tag(tag_id):
    # View all dishes for a certain tag.
    tag = Tag.get_tag_by_id(tag_id)
    data = {}
    data['similar'] = tag.get_dishes()
    return json.dumps(data)
Beispiel #5
0
def view_tag(tag_id):
    # View all dishes for a certain tag.
    tag = Tag.get_tag_by_id(tag_id)
    data = {}
    data['similar'] = tag.get_dishes()
    return json.dumps(data)