Exemplo n.º 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
            })
Exemplo n.º 2
0
    def get(self, url, date, _from_head=False):
        article = Article.get_by_url(url)
        if not article:
            redirect_url = Article.search(date, url)
            if redirect_url:
                self.redirect(CONFIG.BLOG_HOME_RELATIVE_PATH + redirect_url, permanent=True)
                return
            else:
                raise HTTPError(404)

        if not (article.public or self.is_admin):
            raise HTTPError(404)

        previous_article, next_article = article.get_nearby_articles()
        if _from_head or self.request.headers.get('If-None-Match') or self.is_spider:
            hit_count = ArticleHitCount.get(article.id)
        else:
            hit_count = ArticleHitCount.increase(article.id)
        replies = ArticleComments.get_comment_count_of_article(article.id)

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=article.public)
        self.render('web/article.html', {
            'title': article.title,
            'page': 'article',
            'article': article,
            'previous_article': previous_article,
            'next_article': next_article,
            'hits': hit_count,
            'replies': replies
        })
Exemplo n.º 3
0
    def get(self, url, date, _from_head=False):
        article = Article.get_by_url(url)
        if not article:
            redirect_url = Article.search(date, url)
            if redirect_url:
                self.redirect(CONFIG.BLOG_HOME_RELATIVE_PATH + redirect_url,
                              permanent=True)
                return
            else:
                raise HTTPError(404)

        if not (article.public or self.is_admin):
            raise HTTPError(404)

        previous_article, next_article = article.get_nearby_articles()
        if _from_head or self.request.headers.get(
                'If-None-Match') or self.is_spider:
            hit_count = ArticleHitCount.get(article.id)
        else:
            hit_count = ArticleHitCount.increase(article.id)
        replies = ArticleComments.get_comment_count_of_article(article.id)

        self.set_cache(CONFIG.DEFAULT_CACHE_TIME, is_public=article.public)
        self.render(
            'web/article.html', {
                'title': article.title,
                'page': 'article',
                'article': article,
                'previous_article': previous_article,
                'next_article': next_article,
                'hits': hit_count,
                'replies': replies
            })
Exemplo n.º 4
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
        })
Exemplo n.º 5
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
            })
Exemplo n.º 6
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
        })
Exemplo n.º 7
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
        })
Exemplo n.º 8
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)