def GET(self, post_url=None): try: import hashlib post_id = post_url post = Post.get_by_id(int(post_id)) if not post: raise web.notfound() fullpath = web.ctx.home + web.ctx.fullpath check = "%s%s" % (fullpath, post.key()) checksum = hashlib.sha1(check).hexdigest() comments_query = Comment.all().filter('post =', post) if blog.comment_sort == 'asc': comments_query.order('created') else: comments_query.order('-created') comments = comments_query.fetch(blog.comment_pagesize) return render('theme/show.html', post=post, checksum=checksum, comments=comments) except: raise web.notfound()
def body(self): content = memcache.get('widget_comments') if not content: comments = Comment.all().order('-created').fetch(10) content = [] write = content.append write('<ul>') for comment in comments: write("""<li> <span class="author"><a href="%s" target="_blank">%s</a></span> <a href="%s#cmt">%s</a> </li>""" % (comment.homepage, comment.name, comment.post.getUrl(), comment.content)) write('</ul>') content = '\n'.join(content) memcache.set('widget_comments', content) return content