def test_get_datastore_cursor_not_found(self): """Test the get of a datastore.Cursor, raises endpoints.BadRequestException. """ with self.assertRaisesRegexp( endpoints.BadRequestException, api_utils._MALFORMED_PAGE_TOKEN_MSG): api_utils.get_datastore_cursor('malformedPageToken')
def list(self, request): """Lists tags in datastore.""" self.check_xsrf_token(self.request_state) if request.page_size <= 0: raise endpoints.BadRequestException( 'The value for page size must be greater than 0.') cursor = None if request.cursor: cursor = api_utils.get_datastore_cursor(urlsafe_cursor=request.cursor) (tag_results, next_cursor, has_additional_results), total_pages = tag_model.Tag.list( page_size=request.page_size, page_index=request.page_index, include_hidden_tags=request.include_hidden_tags, cursor=cursor) tags_messages = [] for tag in tag_results: message = tag_messages.Tag( name=tag.name, hidden=tag.hidden, color=tag.color, protect=tag.protect, description=tag.description, urlsafe_key=tag.key.urlsafe()) tags_messages.append(message) return tag_messages.ListTagResponse( tags=tags_messages, cursor=next_cursor.urlsafe() if next_cursor else None, has_additional_results=has_additional_results, total_pages=total_pages)
def list(self, request): """Lists survey questions.""" cursor = None if request.page_token: cursor = api_utils.get_datastore_cursor( urlsafe_cursor=request.page_token) questions, next_cursor, more = (survey_models.Question.list( question_type=request.question_type, enabled=request.enabled, page_size=request.page_size, next_cursor=cursor)) response = survey_messages.QuestionList() for question in questions: response.questions.append(_build_survey_messages(question)) if next_cursor or more: response.page_token = next_cursor.urlsafe() response.more = more return response
def list(self, request): """Lists tags in datastore.""" self.check_xsrf_token(self.request_state) cursor = None if request.cursor: cursor = api_utils.get_datastore_cursor(urlsafe_cursor=request.cursor) tag_results, next_cursor, has_additional_results = tag_model.Tag.list( page_size=request.page_size, cursor=cursor) tags_messages = [] for tag in tag_results: message = tag_messages.Tag( name=tag.name, hidden=tag.hidden, color=tag.color, protect=tag.protect, description=tag.description, urlsafe_key=tag.key.urlsafe()) tags_messages.append(message) return tag_messages.ListTagResponse( tags=tags_messages, cursor=next_cursor.urlsafe() if next_cursor else None, has_additional_results=has_additional_results)