當前位置: 首頁>>代碼示例>>Python>>正文


Python datastore_query.Cursor方法代碼示例

本文整理匯總了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>') 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:19,代碼來源:guestbook.py

示例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) 
開發者ID:google,項目名稱:loaner,代碼行數:18,代碼來源:tag_model_test.py

示例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. 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:25,代碼來源:datastore_range_iterators.py

示例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) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:18,代碼來源:domain_user.py

示例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)) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:23,代碼來源:domain_user.py

示例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 
開發者ID:luci,項目名稱:luci-py,代碼行數:22,代碼來源:ts_mon_metrics.py

示例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') 
開發者ID:googlearchive,項目名稱:cloud-playground,代碼行數:19,代碼來源:fixit.py

示例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) 
開發者ID:google,項目名稱:upvote,代碼行數:19,代碼來源:handler_utils.py

示例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) 
開發者ID:google,項目名稱:loaner,代碼行數:11,代碼來源:tag_model_test.py

示例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) 
開發者ID:google,項目名稱:loaner,代碼行數:12,代碼來源:tag_model_test.py

示例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) 
開發者ID:google,項目名稱:loaner,代碼行數:10,代碼來源:tag_model_test.py

示例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) 
開發者ID:google,項目名稱:loaner,代碼行數:10,代碼來源:tag_model_test.py

示例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 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:15,代碼來源:datastore_range_iterators.py

示例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. 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:28,代碼來源:datastore_range_iterators.py

示例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)) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:14,代碼來源:recall_task.py


注:本文中的google.appengine.datastore.datastore_query.Cursor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。