Exemple #1
0
 def get(self):
     request = self.request
     GET = request.GET
     keywords = GET['keywords']
     if keywords:
         keywords = keywords.strip()
     if keywords:
         cursor = unquoted_cursor(GET['cursor'])
         articles, next_cursor = Article.search(
             keywords, None if request.is_admin else True, cursor)
         self.echo(
             'search.html', {
                 'title': '搜索结果',
                 'articles': articles,
                 'next_cursor': next_cursor,
                 'keywords': keywords,
                 'cursor': cursor,
                 'page': 'search'
             })
     else:
         self.echo(
             'message.html', {
                 'page': 'message',
                 'title': '请输入搜索关键字',
                 'h2': '连关键字都没有,你搜索啥啊?',
                 'msg': '填几个关键字再试试吧'
             })
Exemple #2
0
    def get(self, id, cursor=None):
        self.set_cache(0)
        self.set_content_type("json")

        id = int(id)
        if not id:
            self.write(simplejson.dumps({"next_cursor": None, "comments": []}))
            return

        (comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
            db.Key.from_path("Article", id), self.GET["order"] != "desc", cursor=unquoted_cursor(cursor)
        )
        comments_list = []
        for comment, user in izip(comments, users):
            comments_list.append(
                {
                    "user_name": user.name,
                    "url": escape(user.site) if user.site else "",
                    "img": user.get_gravatar(),
                    "ua": comment.ua if not (user.flag & 8) else "",
                    "time": formatted_time(comment.time),
                    "id": comment.key().id(),
                    "content": comment.html_content(),
                }
            )
        self.write(simplejson.dumps({"next_cursor": next_cursor, "comments": comments_list}))
Exemple #3
0
    def get(self, id, cursor=None):
        self.set_cache(0)
        self.set_content_type('json')

        id = int(id)
        if not id:
            self.write(simplejson.dumps({'next_cursor': None, 'comments': []}))
            return

        (comments,
         next_cursor), users = Comment.get_comments_with_user_by_article_key(
             db.Key.from_path('Article', id),
             self.GET['order'] != 'desc',
             cursor=unquoted_cursor(cursor))
        comments_list = []
        for comment, user in izip(comments, users):
            comments_list.append({
                'user_name': user.name,
                'url': escape(user.site) if user.site else '',
                'img': user.get_gravatar(),
                'ua': comment.ua if not (user.flag & 8) else '',
                'time': formatted_time(comment.time),
                'id': comment.key().id(),
                'content': comment.html_content()
            })
        self.write(
            simplejson.dumps({
                'next_cursor': next_cursor,
                'comments': comments_list
            }))
Exemple #4
0
	def get(self, name):
		name = path_to_unicode(name)
		memcache_key = 'get_tag_by_name:' + name
		tag = memcache.get(memcache_key)
		if tag is None:
			tag = Tag.get_by_key_name(name) or ENTITY_NOT_FOUND
		memcache.set(memcache_key, tag, TAGS_CACHE_TIME)
		if tag:
			cursor = unquoted_cursor(self.GET['cursor'])
			articles, next_cursor = tag.get_articles(cursor)
			self.echo('tag.html', {
				'title': u'标签《%s》' % name,
				'tag_name': name,
				'articles': articles,
				'next_cursor': next_cursor,
				'cursor': cursor,
				'page': 'tag'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': '找不到该标签',
				'h2': '糟糕',
				'msg': '好像弄丢了什么东东,完全找不到了的说…'
			})
Exemple #5
0
	def get(self, name):
		name = path_to_unicode(name)
		memcache_key = 'get_category_by_name:' + name
		category = memcache.get(memcache_key)
		if category is None:
			category = Category.get_by_key_name(name) or ENTITY_NOT_FOUND
		memcache_client.set_multi_async({memcache_key: category}, CATEGORY_CACHE_TIME)
		if category:
			cursor = unquoted_cursor(self.GET['cursor'])
			articles, next_cursor = category.get_articles(cursor)
			self.echo('category.html', {
				'title': u'Category: %s' % name,
				'category_name': name,
				'articles': articles,
				'next_cursor': next_cursor,
				'cursor': cursor,
				'page': 'category'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': "Can't find out this category",
				'h2': 'Oh, my god!',
				'msg': 'Something seems to be lost...'
			})
Exemple #6
0
	def get(self, name):
		name = path_to_unicode(name)
		memcache_key = 'get_category_by_name:' + name
		category = memcache.get(memcache_key)
		if category is None:
			category = Category.get_by_key_name(name) or ENTITY_NOT_FOUND
		memcache.set(memcache_key, category, CATEGORY_CACHE_TIME)
		if category:
			cursor = unquoted_cursor(self.GET['cursor'])
			articles, next_cursor = category.get_articles(cursor)
			self.echo('category.html', {
				'title': u'分类《%s》' % name,
				'category_name': name,
				'articles': articles,
				'next_cursor': next_cursor,
				'cursor': cursor,
				'page': 'category'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': '找不到该分类',
				'h2': '糟糕',
				'msg': '好像弄丢了什么东东,完全找不到了的说…'
			})
Exemple #7
0
	def get(self, name):
		name = path_to_unicode(name)
		memcache_key = 'get_tag_by_name:' + name
		tag = memcache.get(memcache_key)
		if tag is None:
			tag = Tag.get_by_key_name(name) or ENTITY_NOT_FOUND
		memcache_client.set_multi_async({memcache_key: tag}, TAGS_CACHE_TIME)
		if tag:
			cursor = unquoted_cursor(self.GET['cursor'])
			articles, next_cursor = tag.get_articles(cursor)
			self.echo('tag.html', {
				'title': u'Tag: %s' % name,
				'tag_name': name,
				'articles': articles,
				'next_cursor': next_cursor,
				'cursor': cursor,
				'page': 'tag'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': "Can't find out this tag",
				'h2': 'Oh, my god!',
				'msg': 'Something seems to be lost...'
			})
Exemple #8
0
 def get(self, id, cursor=None):
     article_id = int(id)
     article = Article.get_article_by_id(article_id) if article_id else None
     if article:
         (comments, next_cursor
          ), users = Comment.get_comments_with_user_by_article_key(
              article.key(), cursor=unquoted_cursor(cursor))
         self.echo(
             'comment.html', {
                 'comments': comments,
                 'next_cursor': next_cursor,
                 'comment_users': users,
                 'id': id,
                 'article': article,
                 'title': u'%s - 评论页' % article.title,
                 'page': 'comments'
             })
     else:
         self.error(404)
         self.echo(
             'error.html', {
                 'page': '404',
                 'title': '找不到该评论页',
                 'h2': '找不到该评论页',
                 'msg': '请检查URL是否输入错误。'
             })
Exemple #9
0
 def get(self):
     cursor = unquoted_cursor(self.GET["cursor"])
     articles, next_cursor = Article.get_articles_for_homepage(cursor)
     self.echo(
         "home_mobile.html",
         {"articles": articles, "next_cursor": next_cursor, "title": BLOG_TITLE, "cursor": cursor, "page": "home"},
     )
Exemple #10
0
 def get(self, name):
     name = path_to_unicode(name)
     memcache_key = 'get_category_by_name:' + name
     category = memcache.get(memcache_key)
     if category is None:
         category = Category.get_by_key_name(name) or ENTITY_NOT_FOUND
     memcache.set(memcache_key, category, CATEGORY_CACHE_TIME)
     if category:
         cursor = unquoted_cursor(self.GET['cursor'])
         articles, next_cursor = category.get_articles(cursor)
         self.echo(
             'category.html', {
                 'title': u'分类《%s》' % name,
                 'category_name': name,
                 'articles': articles,
                 'next_cursor': next_cursor,
                 'cursor': cursor,
                 'page': 'category'
             })
     else:
         self.error(404)
         self.echo(
             'error.html', {
                 'page': '404',
                 'title': '找不到该分类',
                 'h2': '糟糕',
                 'msg': '好像弄丢了什么东东,完全找不到了的说…'
             })
Exemple #11
0
 def get(self, name):
     name = path_to_unicode(name)
     memcache_key = 'get_tag_by_name:' + name
     tag = memcache.get(memcache_key)
     if tag is None:
         tag = Tag.get_by_key_name(name) or ENTITY_NOT_FOUND
     memcache.set(memcache_key, tag, TAGS_CACHE_TIME)
     if tag:
         cursor = unquoted_cursor(self.GET['cursor'])
         articles, next_cursor = tag.get_articles(cursor)
         self.echo(
             'tag.html', {
                 'title': u'标签《%s》' % name,
                 'tag_name': name,
                 'articles': articles,
                 'next_cursor': next_cursor,
                 'cursor': cursor,
                 'page': 'tag'
             })
     else:
         self.error(404)
         self.echo(
             'error.html', {
                 'page': '404',
                 'title': '找不到该标签',
                 'h2': '糟糕',
                 'msg': '好像弄丢了什么东东,完全找不到了的说…'
             })
Exemple #12
0
	def get(self):
		cursor = unquoted_cursor(self.GET['cursor'])
		articles, next_cursor = Article.get_articles_for_homepage(cursor)
		self.echo('home_mobile.html', {
			'articles': articles,
			'next_cursor': next_cursor,
			'title': BLOG_TITLE,
			'cursor': cursor,
			'page': 'home'
		})
Exemple #13
0
	def get(self, cursor=None):
		cursor = unquoted_cursor(self.GET['cursor'])
		articles, next_cursor = Article.get_unpublished_articles(cursor)
		self.echo('unpublished_articles.html', {
			'cursor': cursor,
			'articles': articles,
		    'next_cursor': next_cursor,
		    'title': '未发布的文章',
		    'page': 'unpublished_article'
		})
Exemple #14
0
	def get(self):
		id = self.GET['id']
		id = int(id) if id else 0
		num, next_cursor = Sitemap.fill(id, unquoted_cursor(self.GET['cursor']))
		if num == Sitemap._LIMIT: # need fetch more articles
			taskqueue.add(queue_name='generate-sitemap', method='GET',
			    url=BLOG_ADMIN_RELATIVE_PATH + 'generate_sitemap?id=%d&cursor=%s' % (id + 1, next_cursor))
			self.write('The sitemap generating task has been added.')
		else:
			self.write('The sitemap has been generated.')
Exemple #15
0
	def get(self, cursor=None):
		cursor = unquoted_cursor(self.GET['cursor'])
		articles, next_cursor = Article.get_unpublished_articles(cursor)
		self.echo('unpublished_articles.html', {
			'cursor': cursor,
			'articles': articles,
		    'next_cursor': next_cursor,
		    'title': '未发布的文章',
		    'page': 'unpublished_article'
		})
Exemple #16
0
 def get(self):
     cursor = unquoted_cursor(self.GET['cursor'])
     articles, next_cursor = Article.get_articles_for_homepage(cursor)
     self.echo(
         'home_mobile.html', {
             'articles': articles,
             'next_cursor': next_cursor,
             'title': BLOG_TITLE,
             'cursor': cursor,
             'page': 'home'
         })
Exemple #17
0
	def get(self):
		id = self.GET['id']
		id = int(id) if id else 1
		num, next_cursor = Sitemap.fill(id, unquoted_cursor(self.GET['cursor']))
		if num == Sitemap._LIMIT: # 可能还没找到所有的
			taskqueue.add(queue_name='generate-sitemap', method='GET',
			    url=BLOG_ADMIN_RELATIVE_PATH + 'generate_sitemap?id=%d&cursor=%s' % (id + 1, next_cursor))
			self.write('站点地图生成任务添加成功')
		else:
			self.write('站点地图生成完毕')
			memcache.delete('get_sitemap')
Exemple #18
0
	def get(self):
		id = self.GET['id']
		id = int(id) if id else 1
		num, next_cursor = Sitemap.fill(id, unquoted_cursor(self.GET['cursor']))
		if num == Sitemap._LIMIT: # 可能还没找到所有的
			taskqueue.add(queue_name='generate-sitemap', method='GET',
			    url=BLOG_ADMIN_RELATIVE_PATH + 'generate_sitemap?id=%d&cursor=%s' % (id + 1, next_cursor))
			self.write('站点地图生成任务添加成功')
		else:
			self.write('站点地图生成完毕')
			memcache.delete('get_sitemap')
Exemple #19
0
	def get(self, cursor=None):
		import hook
		hook.init()

		cursor = unquoted_cursor(self.GET['cursor'])
		articles, next_cursor = Article.get_unpublished_articles(cursor)
		self.echo('unpublished_articles.html', {
			'cursor': cursor,
			'articles': articles,
		    'next_cursor': next_cursor,
		    'title': 'Unpublished articles',
		    'page': 'unpublished_article'
		})
Exemple #20
0
	def get(self, id, cursor=None):
		self.set_cache(0)
		self.set_content_type('json')

		(comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
				db.Key.from_path('Article', int(id)), self.GET['order'] != 'desc', cursor=unquoted_cursor(cursor))
		comments_list = []
		for comment, user in izip(comments, users):
			comments_list.append({
				'user_name': user.name,
				'url': escape(user.site) if user.site else '',
				'img': user.get_gravatar(),
				'ua': comment.ua,
				'time': formatted_time(comment.time),
				'id': comment.key().id(),
				'content': comment.html_content()
			})
		self.write(simplejson.dumps({
			 'next_cursor': next_cursor,
			 'comments': comments_list
		}))
Exemple #21
0
 def get(self, id, cursor=None):
     article_id = int(id)
     article = Article.get_article_by_id(article_id) if article_id else None
     if article:
         (comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
             article.key(), cursor=unquoted_cursor(cursor)
         )
         self.echo(
             "comment.html",
             {
                 "comments": comments,
                 "next_cursor": next_cursor,
                 "comment_users": users,
                 "id": id,
                 "article": article,
                 "title": u"%s - 评论页" % article.title,
                 "page": "comments",
             },
         )
     else:
         self.error(404)
         self.echo("error.html", {"page": "404", "title": "找不到该评论页", "h2": "找不到该评论页", "msg": "请检查URL是否输入错误。"})
Exemple #22
0
	def get(self, id, cursor=None):
		article =  Article.get_article_by_id(int(id))
		if article:
			(comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
				article.key(), cursor=unquoted_cursor(cursor))
			self.echo('comment.html', {
				'comments': comments,
				'next_cursor': next_cursor,
				'comment_users': users,
				'id': id,
			    'article': article,
				'title': u'%s - 评论页' % article.title,
				'page': 'comments'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': '找不到该评论页',
				'h2': '找不到该评论页',
				'msg': '请检查URL是否输入错误。'
			})
Exemple #23
0
	def get(self, id, cursor=None):
		article_id = int(id)
		article = Article.get_article_by_id(article_id) if article_id else None
		if article:
			(comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
				article.key(), cursor=unquoted_cursor(cursor))
			self.echo('comment.html', {
				'comments': comments,
				'next_cursor': next_cursor,
				'comment_users': users,
				'id': id,
			    'article': article,
				'title': '%s - comments' % article.title,
				'page': 'comments'
			})
		else:
			self.error(404)
			self.echo('error.html', {
				'page': '404',
				'title': "Can't find out this comment",
				'h2': "Can't find out this comment.",
				'msg': 'Please check whether you entered a wrong URL.'
			})
Exemple #24
0
 def get(self, name):
     name = path_to_unicode(name)
     memcache_key = "get_category_by_name:" + name
     category = memcache.get(memcache_key)
     if category is None:
         category = Category.get_by_key_name(name) or ENTITY_NOT_FOUND
     memcache.set(memcache_key, category, CATEGORY_CACHE_TIME)
     if category:
         cursor = unquoted_cursor(self.GET["cursor"])
         articles, next_cursor = category.get_articles(cursor)
         self.echo(
             "category.html",
             {
                 "title": u"分类《%s》" % name,
                 "category_name": name,
                 "articles": articles,
                 "next_cursor": next_cursor,
                 "cursor": cursor,
                 "page": "category",
             },
         )
     else:
         self.error(404)
         self.echo("error.html", {"page": "404", "title": "找不到该分类", "h2": "糟糕", "msg": "好像弄丢了什么东东,完全找不到了的说…"})
Exemple #25
0
	def get(self):
		request = self.request
		GET = request.GET
		keywords = GET['keywords']
		if keywords:
			keywords = keywords.strip()
		if keywords:
			cursor = unquoted_cursor(GET['cursor'])
			articles, next_cursor = Article.search(keywords, None if request.is_admin else True, cursor)
			self.echo('search.html', {
				'title': '搜索结果',
				'articles': articles,
				'next_cursor': next_cursor,
				'keywords': keywords,
				'cursor': cursor,
				'page': 'search'
			})
		else:
			self.echo('message.html', {
				'page': 'message',
				'title': '请输入搜索关键字',
				'h2': '连关键字都没有,你搜索啥啊?',
				'msg': '填几个关键字再试试吧'
			})
Exemple #26
0
	def get(self):
		request = self.request
		GET = request.GET
		keywords = GET['keywords']
		if keywords:
			keywords = keywords.strip()
		if keywords:
			cursor = unquoted_cursor(GET['cursor'])
			articles, next_cursor = Article.search(keywords, None if request.is_admin else True, cursor)
			self.echo('search.html', {
				'title': 'Search result',
				'articles': articles,
				'next_cursor': next_cursor,
				'keywords': keywords,
				'cursor': cursor,
				'page': 'search'
			})
		else:
			self.echo('message.html', {
				'page': 'message',
				'title': 'Please enter some search keywords',
				'h2': 'What do you search for?',
				'msg': 'Please enter some search keywords.'
			})
Exemple #27
0
 def get(self, name):
     name = path_to_unicode(name)
     memcache_key = "get_tag_by_name:" + name
     tag = memcache.get(memcache_key)
     if tag is None:
         tag = Tag.get_by_key_name(name) or ENTITY_NOT_FOUND
     memcache.set(memcache_key, tag, TAGS_CACHE_TIME)
     if tag:
         cursor = unquoted_cursor(self.GET["cursor"])
         articles, next_cursor = tag.get_articles(cursor)
         self.echo(
             "tag.html",
             {
                 "title": u"标签《%s》" % name,
                 "tag_name": name,
                 "articles": articles,
                 "next_cursor": next_cursor,
                 "cursor": cursor,
                 "page": "tag",
             },
         )
     else:
         self.error(404)
         self.echo("error.html", {"page": "404", "title": "找不到该标签", "h2": "糟糕", "msg": "好像弄丢了什么东东,完全找不到了的说…"})
Exemple #28
0
 def get(self):
     request = self.request
     GET = request.GET
     keywords = GET["keywords"]
     if keywords:
         keywords = keywords.strip()
     if keywords:
         cursor = unquoted_cursor(GET["cursor"])
         articles, next_cursor = Article.search(keywords, None if request.is_admin else True, cursor)
         self.echo(
             "search.html",
             {
                 "title": "搜索结果",
                 "articles": articles,
                 "next_cursor": next_cursor,
                 "keywords": keywords,
                 "cursor": cursor,
                 "page": "search",
             },
         )
     else:
         self.echo(
             "message.html", {"page": "message", "title": "请输入搜索关键字", "h2": "连关键字都没有,你搜索啥啊?", "msg": "填几个关键字再试试吧"}
         )
Exemple #29
0
	def get(self, id, cursor=None):
		self.set_cache(0)
		self.set_content_type('json')

		id = int(id)
		if not id:
			self.write(json.dumps({
				 'next_cursor': None,
				 'comments': []
			}))
			return

		isHttps = self.request.scheme == 'https'
		(comments, next_cursor), users = Comment.get_comments_with_user_by_article_key(
				db.Key.from_path('Article', id), self.GET['order'] != 'desc', cursor=unquoted_cursor(cursor))
		comments_list = []
		for comment, user in izip(comments, users):
			if user:
				user_name = user.name
				user_site = escape(user.site) if user.site else ''
			else:
				user_name = u'Anonymous'
				user_site = ''
			comments_list.append({
				'user_name': user_name,
				'url': user_site,
				'img': user.get_gravatar(isHttps),
				'ua': comment.ua,
				'time': formatted_time(comment.time),
				'id': comment.key().id(),
				'content': comment.html_content()
			})
		self.write(json.dumps({
			 'next_cursor': next_cursor,
			 'comments': comments_list
		}))