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


Python ndb.FilterNode方法代碼示例

本文整理匯總了Python中google.appengine.ext.ndb.FilterNode方法的典型用法代碼示例。如果您正苦於以下問題:Python ndb.FilterNode方法的具體用法?Python ndb.FilterNode怎麽用?Python ndb.FilterNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.FilterNode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_query

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import FilterNode [as 別名]
def make_query(self, ns):
    """Make a query of entities within this range.

    Query options are not supported. They should be specified when the query
    is run.

    Args:
      ns: namespace of this query.

    Returns:
      a db.Query or ndb.Query, depends on the model class's type.
    """
    if issubclass(self.model_class, db.Model):
      query = db.Query(self.model_class, namespace=ns)
      for f in self.filters:
        query.filter("%s %s" % (f[0], f[1]), f[2])
    else:
      query = self.model_class.query(namespace=ns)
      for f in self.filters:
        query = query.filter(ndb.FilterNode(*f))
    return query 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:23,代碼來源:property_range.py

示例2: filter_ndb_query

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import FilterNode [as 別名]
def filter_ndb_query(self, query, filters=None):
    """Add query filter to restrict to this key range.

    Args:
      query: An ndb.Query instance.
      filters: optional list of filters to apply to the query. Each filter is
        a tuple: (<property_name_as_str>, <query_operation_as_str>, <value>).
        User filters are applied first.

    Returns:
      The input query restricted to this key range.
    """
    assert _IsNdbQuery(query)


    if filters:
      for f in filters:
        query = query.filter(ndb.FilterNode(*f))

    if self.include_start:
      start_comparator = ">="
    else:
      start_comparator = ">"
    if self.include_end:
      end_comparator = "<="
    else:
      end_comparator = "<"
    if self.key_start:
      query = query.filter(ndb.FilterNode("__key__",
                                          start_comparator,
                                          self.key_start))
    if self.key_end:
      query = query.filter(ndb.FilterNode("__key__",
                                          end_comparator,
                                          self.key_end))
    return query 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:38,代碼來源:__init__.py

示例3: _QueryModel

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import FilterNode [as 別名]
def _QueryModel(self, search_dict, ancestor=None):
    """Queries the model class for field-value pairs.

    Args:
      search_dict: A dictionary mapping from field name to search by to the
          search term.
      ancestor: ndb.Key, If provided, the ancestor for the query.

    Returns:
      The model query.

    Raises:
      QueryError: If the queried field is not a property of the model.
      QueryTypeError: If search_term does not match the type of the search_base
          model property.
    """
    filter_nodes = []
    for search_base, search_term in search_dict.items():
      field_name = string_utils.CamelToSnakeCase(search_base)

      # If the model class offers a translation function for property queries,
      # invoke it and set the field and search term to the result.
      try:
        field_name, search_term = self.MODEL_CLASS.TranslatePropertyQuery(
            field_name, search_term)
      except AttributeError:
        pass
      else:
        logging.info('Converted query to (%s = %s)', field_name, search_term)

      # Check for the property on the model itself (as opposed to, say, catching
      # a getattr exception) to ensure that the field being accessed is an ndb
      # property as opposed to a Python attribute.
      if not datastore_utils.HasProperty(self.MODEL_CLASS, field_name):
        raise QueryError('Invalid searchBase %s' % field_name)

      field = getattr(self.MODEL_CLASS, field_name)

      # If the field is of a non-string type, attempt to coerce the argument to
      # conform to this type
      search_term = _CoerceQueryParam(field, search_term)

      filter_nodes.append(ndb.FilterNode(field_name, '=', search_term))

    query = self.MODEL_CLASS.query(ancestor=ancestor)
    if filter_nodes:
      query = query.filter(ndb.AND(*filter_nodes))
    return query 
開發者ID:google,項目名稱:upvote,代碼行數:50,代碼來源:handler_utils.py


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