def get(self): page = int(self.get_argument('page', 1)) per_page = int(self.get_argument('per_page', 20)) pagination = yield gen.maybe_future( Topic.page_list_all(page, per_page)) result = { 'page': page, 'per_page': per_page, 'has_prev': pagination.has_prev, 'has_next': pagination.has_next, 'pages': pagination.pages, 'total': pagination.total, 'topics': [(yield gen.maybe_future(item.to_dict())) for item in pagination.items], } raise gen.Return(result)
def get(self, topic_id): username = self.current_user if topic_id: topic = yield gen.maybe_future(Topic.get(topic_id)) info = yield gen.maybe_future(_topic_info(username, topic)) raise gen.Return(info) else: page = int(self.get_argument('page', 1)) per_page = int(self.get_argument('per_page', 20)) pagination = yield gen.maybe_future( Topic.page_list_all(page, per_page)) result = { 'page': page, 'per_page': per_page, 'has_prev': pagination.has_prev, 'has_next': pagination.has_next, 'pages': pagination.pages, 'total': pagination.total, 'topics': [(yield gen.maybe_future(item.to_dict())) for item in pagination.items], } raise gen.Return(result)