本文整理汇总了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
示例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
示例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