Exemple #1
0
    def get(self, post_id):
        page = int(self.get_argument('page', 1))
        per_page = int(self.get_argument('per_page', 20))
        username = self.current_user

        pagination = yield gen.maybe_future(
            Comment.page_list_by_post(post_id, page, per_page))
        comments = list()
        for comment in pagination.items:
            info = yield gen.maybe_future(_comment_info(username, comment))
            comments.append(info)
        result = {
            'page': page,
            'pages': pagination.pages,
            'has_prev': pagination.has_prev,
            'has_next': pagination.has_next,
            'total': pagination.total,
            'comments': comments,
        }
        raise gen.Return(result)