Example #1
0
    def get(self, tag_name):
        if not Tag.exists(tag_name):
            raise HTTPError(404)

        articles, next_cursor = TagArticle.get_articles(tag_name, self.cursor)
        if articles:
            article_ids = [article.id for article in articles]
            hit_counts = ArticleHitCount.get_by_ids(article_ids)
            replies_dict = ArticleComments.get_comment_count_of_articles(
                article_ids)
        else:
            hit_counts = replies_dict = {}
            next_cursor = None

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=True)
        self.render(
            'web/tag_articles.html', {
                'title': u'标签《%s》' % tag_name,
                'page': 'tag_articles',
                'next_cursor': next_cursor,
                'tag_name': tag_name,
                'articles': articles,
                'hit_counts': hit_counts,
                'replies_dict': replies_dict
            })
Example #2
0
    def get(self):
        articles, next_cursor = Article.get_articles_for_homepage(self.cursor)
        if articles:
            article_ids = [article.id for article in articles]
            hit_counts = ArticleHitCount.get_by_ids(article_ids)
            replies_dict = ArticleComments.get_comment_count_of_articles(article_ids)
        else:
            hit_counts = replies_dict = {}

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=True)
        self.render('web/home.html', {
            'title': CONFIG.BLOG_TITLE,
            'page': 'home',
            'articles': articles,
            'hit_counts': hit_counts,
            'replies_dict': replies_dict,
            'next_cursor': next_cursor
        })
Example #3
0
    def get(self):
        articles, next_cursor = Article.get_articles_for_homepage(self.cursor)
        if articles:
            article_ids = [article.id for article in articles]
            hit_counts = ArticleHitCount.get_by_ids(article_ids)
            replies_dict = ArticleComments.get_comment_count_of_articles(
                article_ids)
        else:
            hit_counts = replies_dict = {}

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=True)
        self.render(
            'web/home.html', {
                'title': CONFIG.BLOG_TITLE,
                'page': 'home',
                'articles': articles,
                'hit_counts': hit_counts,
                'replies_dict': replies_dict,
                'next_cursor': next_cursor
            })
Example #4
0
    def get(self, page):
        if page:
            page = int(page)
        else:
            page = 1
        articles = Article.get_unpublished_articles(page)
        if articles:
            article_ids = [article.id for article in articles]
            hit_counts = ArticleHitCount.get_by_ids(article_ids)
            replies_dict = ArticleComments.get_comment_count_of_articles(article_ids)
        else:
            hit_counts = replies_dict = {}

        self.render('admin/unpublished_articles.html', {
            'title': u'未发布的文章',
            'page': 'unpublished_articles',
            'articles': articles,
            'hit_counts': hit_counts,
            'replies_dict': replies_dict,
            'next_page': page + 1
        })
Example #5
0
    def get(self, tag_name):
        if not Tag.exists(tag_name):
            raise HTTPError(404)

        articles, next_cursor = TagArticle.get_articles(tag_name, self.cursor)
        if articles:
            article_ids = [article.id for article in articles]
            hit_counts = ArticleHitCount.get_by_ids(article_ids)
            replies_dict = ArticleComments.get_comment_count_of_articles(article_ids)
        else:
            hit_counts = replies_dict = {}
            next_cursor = None

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=True)
        self.render('web/tag_articles.html', {
            'title': u'标签《%s》' % tag_name,
            'page': 'tag_articles',
            'next_cursor': next_cursor,
            'tag_name': tag_name,
            'articles': articles,
            'hit_counts': hit_counts,
            'replies_dict': replies_dict
        })
Example #6
0
    def get(self):
        keywords = self.get_argument('keywords', None)
        if keywords:
            article_ids = KeywordArticle.query_by_keyword(keywords)
            if article_ids:
                articles = Article.get_by_ids(article_ids, public_only=True)
                article_ids = [article.id for article in articles]
                hit_counts = ArticleHitCount.get_by_ids(article_ids)
                replies_dict = ArticleComments.get_comment_count_of_articles(article_ids)
            else:
                articles = []
                hit_counts = replies_dict = {}

            self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=True)
            self.render('web/search.html', {
                'title': u'搜索《%s》' % keywords,
                'page': 'search',
                'keywords': keywords,
                'articles': articles,
                'hit_counts': hit_counts,
                'replies_dict': replies_dict
            })
        else:
            raise HTTPError(400)