def post_create(self, request): """ Create new post """ post = Post(name=request.name, body=request.body) post.put() return self._post_from_db(post)
def posts_list(self, request): """ List posts """ limit = min(request.limit, MAX_LIMIT) start_cursor = Cursor(urlsafe=request.next_token) query = Post.query() posts, next_cursor, more = query.fetch_page(limit, start_cursor=start_cursor, batch_size=limit) next_token = next_cursor.urlsafe() if next_cursor and more else None resp_posts = [self._post_from_db(post) for post in posts] return PostsCollection(posts=resp_posts, next_token=next_token)