本文整理汇总了Python中google.appengine.datastore.datastore_query.Cursor方法的典型用法代码示例。如果您正苦于以下问题:Python datastore_query.Cursor方法的具体用法?Python datastore_query.Cursor怎么用?Python datastore_query.Cursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.datastore.datastore_query
的用法示例。
在下文中一共展示了datastore_query.Cursor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def get(self):
"""Handles requests like /list?cursor=1234567."""
cursor = Cursor(urlsafe=self.request.get('cursor'))
greets, next_cursor, more = Greeting.query().fetch_page(
self.GREETINGS_PER_PAGE, start_cursor=cursor)
self.response.out.write('<html><body>')
for greeting in greets:
self.response.out.write(
'<blockquote>%s</blockquote>' % cgi.escape(greeting.content))
if more and next_cursor:
self.response.out.write('<a href="/list?cursor=%s">More...</a>' %
next_cursor.urlsafe())
self.response.out.write('</body></html>')
示例2: test_list_tags_more
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def test_list_tags_more(self):
(page_one_result, first_cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=1, cursor=None, include_hidden_tags=False)
self.assertListEqual(page_one_result, [self.tag1])
self.assertTrue(has_additional_results)
self.assertEqual(total_pages, 3)
(page_two_result, next_cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=tag_model.Tag.query().count(), cursor=first_cursor,
include_hidden_tags=False)
self.assertListEqual(page_two_result, [self.tag2, self.tag5])
self.assertIsInstance(next_cursor, datastore_query.Cursor)
self.assertFalse(has_additional_results)
self.assertEqual(total_pages, 1)
示例3: to_json
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def to_json(self):
"""Inherit doc."""
cursor_object = False
if self._query is not None:
if isinstance(self._query, db.Query):
self._cursor = self._query.cursor()
else:
cursor_object = True
self._cursor = self._query.cursor_after().to_websafe_string()
else:
self._cursor = None
return {"property_range": self._property_range.to_json(),
"query_spec": self._query_spec.to_json(),
"cursor": self._cursor,
"ns_range": self._ns_range.to_json_object(),
"name": self.__class__.__name__,
"cursor_object": cursor_object}
# TODO(user): it sucks we need to handle cursor_to_str in many places.
# In the long run, datastore adaptor refactor will take care of this as
# we will only need to deal with low level datastore API after that.
# Thus we will not add Cursor as a json primitive MR should understand.
示例4: FetchOnePageOfActiveUsersForTask
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def FetchOnePageOfActiveUsersForTask(cls, task_key_id, cursor):
"""Utility to query and fetch all active users.
Used to retrieve the entire list of (not suspended) domain users to process.
Args:
task_key_id: Int unique id of the task record.
cursor: Cursor from previous fetch_page() calls.
Returns:
Iterable of one page of DomainUserToCheckModel users.
"""
return cls.GetQueryForAllTaskUsers(
task_key_id=task_key_id,
user_state_filters=ACTIVE_USER_STATES).fetch_page(
_USER_ROWS_FETCH_PAGE, start_cursor=cursor)
示例5: FetchOneUIPageOfUsersForTask
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def FetchOneUIPageOfUsersForTask(cls, task_key_urlsafe, urlsafe_cursor,
user_state_filters=None,
message_state_filters=None):
"""Utility to query and fetch all users for UI pages.
Args:
task_key_urlsafe: String unique id of the task record.
urlsafe_cursor: String cursor from previous fetch_page() calls.
This is a publishable version acquired via '.urlsafe()'.
user_state_filters: List of strings to filter users.
message_state_filters: List of strings to filter users.
Returns:
Iterable of one page of DomainUserToCheckModel users.
"""
return cls.GetQueryForAllTaskUsers(
task_key_id=ndb.Key(urlsafe=task_key_urlsafe).id(),
user_state_filters=user_state_filters,
message_state_filters=message_state_filters).fetch_page(
_USER_ROWS_FETCH_PAGE,
start_cursor=Cursor(urlsafe=urlsafe_cursor))
示例6: __init__
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def __init__(self, payload):
self.start_time = utils.utcnow()
self.cursor = None
self.task_start = self.start_time
self.task_count = 0
self.count = 0
if not payload:
return
try:
params = json.loads(payload)
if params['cursor']:
self.cursor = Cursor(urlsafe=params['cursor'])
self.task_start = datetime.datetime.strptime(
params['task_start'], utils.DATETIME_FORMAT)
self.task_count = params['task_count']
self.count = params['count']
except (ValueError, KeyError) as e:
logging.error('_ShardParams: bad JSON: %s: %s', payload, e)
# Stop the task chain and let the request fail.
raise
示例7: post
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def post(self): # pylint:disable-msg=invalid-name,missing-docstring
assert self.request.environ[common.HTTP_X_APPENGINE_QUEUENAME]
query = model.Project.query(namespace=settings.PLAYGROUND_NAMESPACE)
cursor = self.request.get('cursor', None)
if cursor:
cursor = Cursor(urlsafe=cursor)
projects, next_cursor, more = query.fetch_page(_CURSOR_PAGE_SIZE,
start_cursor=cursor)
if more and next_cursor:
taskqueue.add(queue_name='fixit',
url='/playground/fix/project',
params={'cursor': next_cursor.urlsafe()})
for project in projects:
FixProject(project)
if not next_cursor:
shared.w('REACHED END OF QUERY CURSOR, '
'ALTHOUGH OTHER TASKS MAY STILL BE EXECUTING')
示例8: respond_with_page
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def respond_with_page(self, content, cursor, has_more):
"""Sets the handler response to the page contents provided.
Args:
content: list, A list of the objects to be used as the page contents.
cursor: datastore_query.Cursor, The cursor representing the resumption
point for the next page of the query.
has_more: bool, Whether there are more results after this page.
"""
safe_cursor = cursor.urlsafe() if cursor else None
response_dict = {
'content': content,
'cursor': safe_cursor,
'more': has_more,
'per_page': self.per_page}
logging.info('Responding with a page of %d item(s)', len(content))
self.respond_json(response_dict)
示例9: test_list_tags_include_hidden
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def test_list_tags_include_hidden(self):
(query_results, cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=tag_model.Tag.query().count(), include_hidden_tags=True)
self.assertListEqual(
query_results, [self.tag1, self.tag2, self.tag3, self.tag4, self.tag5])
self.assertEqual(total_pages, 1)
self.assertIsInstance(cursor, datastore_query.Cursor)
self.assertFalse(has_additional_results)
示例10: test_list_tags_exclude_hidden
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def test_list_tags_exclude_hidden(self):
(query_results, cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=tag_model.Tag.query().count(), include_hidden_tags=False)
self.assertListEqual(query_results, [self.tag1, self.tag2, self.tag5])
self.assertNotIn(self.tag3, query_results)
self.assertNotIn(self.tag4, query_results)
self.assertIsInstance(cursor, datastore_query.Cursor)
self.assertFalse(has_additional_results)
self.assertEqual(total_pages, 1)
示例11: test_list_tags_middle_page
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def test_list_tags_middle_page(self):
(page_result, next_cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=1, page_index=2, include_hidden_tags=False)
self.assertListEqual(page_result, [self.tag2])
self.assertIsInstance(next_cursor, datastore_query.Cursor)
self.assertTrue(has_additional_results)
self.assertEqual(total_pages, 3)
示例12: test_list_tags_last_page
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def test_list_tags_last_page(self):
(page_result, next_cursor,
has_additional_results), total_pages = tag_model.Tag.list(
page_size=2, page_index=2, include_hidden_tags=False)
self.assertListEqual(page_result, [self.tag5])
self.assertIsInstance(next_cursor, datastore_query.Cursor)
self.assertFalse(has_additional_results)
self.assertEqual(total_pages, 2)
示例13: from_json
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def from_json(cls, json):
"""Inherit doc."""
obj = cls(property_range.PropertyRange.from_json(json["property_range"]),
namespace_range.NamespaceRange.from_json_object(json["ns_range"]),
model.QuerySpec.from_json(json["query_spec"]))
cursor = json["cursor"]
# lint bug. Class method can access protected fields.
# pylint: disable=protected-access
if cursor and json["cursor_object"]:
obj._cursor = datastore_query.Cursor.from_websafe_string(cursor)
else:
obj._cursor = cursor
return obj
示例14: to_json
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def to_json(self):
"""Inherit doc."""
cursor = self._cursor
if self._query is not None:
if isinstance(self._query, db.Query):
cursor = self._query.cursor()
else:
cursor = self._query.cursor_after()
if cursor is None or isinstance(cursor, basestring):
cursor_object = False
else:
cursor_object = True
cursor = cursor.to_websafe_string()
return {"property_range": self._property_range.to_json(),
"query_spec": self._query_spec.to_json(),
"cursor": cursor,
"ns_range": self._ns_range.to_json_object(),
"name": self.__class__.__name__,
"cursor_object": cursor_object}
# TODO(user): it sucks we need to handle cursor_to_str in many places.
# In the long run, datastore adaptor refactor will take care of this as
# we will only need to deal with low level datastore API after that.
# Thus we will not add Cursor as a json primitive MR should understand.
示例15: FetchOneUIPageOfTasksForDomain
# 需要导入模块: from google.appengine.datastore import datastore_query [as 别名]
# 或者: from google.appengine.datastore.datastore_query import Cursor [as 别名]
def FetchOneUIPageOfTasksForDomain(cls, user_domain, urlsafe_cursor):
"""Utility to query and fetch all tasks.
Args:
user_domain: String to force safety check of proper domain.
urlsafe_cursor: String cursor from previous fetch_page() calls.
Returns:
Iterable of one page of RecallTaskModel tasks.
"""
return cls.GetQueryForAllTasks(user_domain).fetch_page(
_TASK_ROWS_FETCH_PAGE, start_cursor=Cursor(urlsafe=urlsafe_cursor))