def wrapper(self, *args, **kwargs): # Note: if page_token is None, we'll receive the first page of results back. page_token = decrypt_page_token(kwargs[parsed_args_kwarg]["next_page"]) kwargs[page_token_kwarg] = page_token (result, next_page_token) = func(self, *args, **kwargs) if next_page_token is not None: result["next_page"] = encrypt_page_token(next_page_token) return result
def callback(results, response): if len(results) <= limit: return next_page_token = encrypt_page_token({'start_id': max([obj.id for obj in results])}) link_url = os.path.join(get_app_url(), url_for(request.endpoint, **request.view_args)) link_param = urlencode({'n': limit, 'next_page': next_page_token}) link = '<%s?%s>; rel="next"' % (link_url, link_param) response.headers['Link'] = link