def post(self): name = self.get_argument('name', None) if not name: self.finish('添加失败,标签名不能为空') return Tag.add(name) self.finish('添加成功')
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 })
def get(self): categories = Category.get_all_names_with_paths() tags = Tag.get_all() self.render('admin/create_article.html', { 'title': '发表新文章', 'page': 'create_article', 'categories': categories, 'tags': sorted(tags) })
def get(self, article_id): article_id = int(article_id) if not article_id: raise HTTPError(404) article = Article.get_by_id(article_id) if not article: raise HTTPError(404) categories = Category.get_all_names_with_paths() tags = Tag.get_all() self.render('admin/edit_article.html', { 'title': u'编辑《%s》' % article.title, 'page': 'edit_article', 'article': article, 'categories': categories, 'tags': sorted(tags) })
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 })