예제 #1
0
 def get(self, topic_id, *args, **kwargs):
     try:
         topic = PostTopic.get(PostTopic.str == topic_id)
     except PostTopic.DoesNotExist:
         self.redirect("/static/404.html")
         return
     current_page = get_cleaned_query_data(self, [
         'page',
     ], blank=True)['page']
     if current_page:
         current_page = int(current_page)
         if current_page < 1:
             self.redirect("/static/404.html")
             return
         posts, page_number_limit = Post.list_by_topic(
             topic, page_number=current_page)
     else:
         current_page = 1
         posts, page_number_limit = Post.list_by_topic(topic)
     top_posts, _ = Post.list_top()
     pages = get_page_nav(current_page, page_number_limit,
                          config.default_page_limit)
     self.render('index/index.html',
                 posts=posts,
                 top_posts=top_posts,
                 topic_category_cache=topic_category_cache,
                 hot_post_cache=hot_post_cache,
                 systatus=system_status_cache,
                 current_topic=topic,
                 pages=pages,
                 pages_prefix_url='/topic/' + topic.str + '?page=')
예제 #2
0
파일: blog.py 프로젝트: susnmos/torweb
    def get(self, *args, **kwargs):
        current_page = get_cleaned_query_data(self, [
            'page',
        ], blank=True)['page']
        current_page = get_page_number(current_page)
        posts, page_number_limit = BlogPost.list_recently(
            page_number=current_page)
        for post in posts:
            post.labels = BlogPostLabel.get_post_label(post)
        pages = get_page_nav(current_page, page_number_limit,
                             config.default_page_limit)

        # 使用到联合、分组等查询, 得到每个分类下文章个数, 得到每个标签下文章个数
        # select category_id, blogpostcategory.name, count(blogpost.id) from blogpost inner join blogpostcategory on blogpost.category_id=blogpostcategory.id group by category_id;
        categorys = BlogPost.select(BlogPostCategory.name, fn.COUNT(BlogPost.id).alias('count'))\
            .join(BlogPostCategory, on=(BlogPostCategory.id == BlogPost.category))\
            .group_by(BlogPost.category)
        for category in categorys:
            category.name = category.category.name

        labels = BlogPostLabel.select(
            BlogPostLabel.name,
            fn.COUNT(BlogPostLabel.post).alias('count')).where(
                BlogPostLabel.is_del == False).group_by(BlogPostLabel.name)

        self.render('blog/index.html',
                    posts=posts,
                    labels=labels,
                    categorys=categorys,
                    pages=pages,
                    pages_prefix_url='/blog?page=')
예제 #3
0
    def get(self, *args, **kwargs):
        # profiling 性能分析
        # from profiling.tracing import TracingProfiler
        #
        # # profile your program.
        # profiler = TracingProfiler()
        # profiler.start()

        current_page = get_cleaned_query_data(self, [
            'page',
        ], blank=True)['page']
        current_page = get_page_number(current_page)
        posts, page_number_limit = Post.list_recently(page_number=current_page)
        top_posts, _ = Post.list_top()
        pages = get_page_nav(current_page, page_number_limit,
                             config.default_page_limit)
        self.render('index/index.html',
                    posts=posts,
                    top_posts=top_posts,
                    topic_category_cache=topic_category_cache,
                    hot_post_cache=hot_post_cache,
                    systatus=system_status_cache,
                    current_topic=None,
                    pages=pages,
                    pages_prefix_url='/?page=')
예제 #4
0
파일: blog.py 프로젝트: jmpews/torweb
    def get(self, category_name, *args, **kwargs):
        try:
            category = BlogPostCategory.get(BlogPostCategory.name == category_name)
        except BlogPostCategory.DoesNotExist:
            self.redirect("/static/404.html")
            return
        current_page = get_cleaned_query_data(self, ['page',], blank=True)['page']
        current_page = get_page_number(current_page)
        posts, page_number_limit = BlogPost.list_by_category(category, page_number=current_page)
        for post in posts:
            post.labels = BlogPostLabel.get_post_label(post)
        pages = get_page_nav(current_page, page_number_limit, config.default_page_limit)

        # 使用到联合、分组等查询, 得到每个分类下文章个数, 得到每个标签下文章个数
        # select category_id, blogpostcategory.name, count(blogpost.id) from blogpost inner join blogpostcategory on blogpost.category_id=blogpostcategory.id group by category_id;
        categorys = BlogPost.select(BlogPostCategory.name, fn.COUNT(BlogPost.id).alias('count'))\
            .join(BlogPostCategory, on=(BlogPostCategory.id == BlogPost.category))\
            .group_by(BlogPost.category)
        for category in categorys:
            category.name = category.category.name

        labels = BlogPostLabel.select(BlogPostLabel.name, fn.COUNT(BlogPostLabel.post).alias('count')).where(BlogPostLabel.is_del == False).group_by(BlogPostLabel.name)

        self.render('blog/index.html',
                    posts=posts,
                    labels=labels,
                    categorys=categorys,
                    pages=pages,
                    pages_prefix_url='/blog/category/'+category_name+'?page=')
예제 #5
0
파일: utils.py 프로젝트: jmpews/torweb
def get_topic_index_info(topic_id, current_page, page_limit=config.default_page_limit):
    try:
        topic = PostTopic.get(PostTopic.str == topic_id)
    except PostTopic.DoesNotExist:
        return None
    current_page = get_page_number(current_page)
    posts, page_number_limit = Post.list_by_topic(topic, page_number=current_page)
    top_posts, _ = Post.list_top()
    pages = get_page_nav(current_page, page_number_limit, page_limit)
    return topic, posts, top_posts, pages
예제 #6
0
파일: utils.py 프로젝트: susnmos/torweb
def get_topic_index_info(topic_id,
                         current_page,
                         page_limit=config.default_page_limit):
    try:
        topic = PostTopic.get(PostTopic.str == topic_id)
    except PostTopic.DoesNotExist:
        return None
    current_page = get_page_number(current_page)
    posts, page_number_limit = Post.list_by_topic(topic,
                                                  page_number=current_page)
    top_posts, _ = Post.list_top()
    pages = get_page_nav(current_page, page_number_limit, page_limit)
    return topic, posts, top_posts, pages
예제 #7
0
파일: utils.py 프로젝트: jmpews/torweb
def get_index_info(current_page, page_limit=config.default_page_limit):
    current_page = get_page_number(current_page)
    posts, page_number_limit = Post.list_recently(page_number=current_page)
    top_posts, _ = Post.list_top()
    pages = get_page_nav(current_page, page_number_limit, page_limit)
    return posts, top_posts, pages
예제 #8
0
파일: utils.py 프로젝트: susnmos/torweb
def get_index_info(current_page, page_limit=config.default_page_limit):
    current_page = get_page_number(current_page)
    posts, page_number_limit = Post.list_recently(page_number=current_page)
    top_posts, _ = Post.list_top()
    pages = get_page_nav(current_page, page_number_limit, page_limit)
    return posts, top_posts, pages