Python google.appengine.ext.ndb.FilterNode() Examples
The following are 6
code examples of google.appengine.ext.ndb.FilterNode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.ext.ndb
, or try the search function
.
Example #1
Source File: property_range.py From browserscope with Apache License 2.0 | 6 votes |
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
Example #2
Source File: property_range.py From locality-sensitive-hashing with MIT License | 6 votes |
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
Example #3
Source File: property_range.py From python-compat-runtime with Apache License 2.0 | 6 votes |
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
Example #4
Source File: property_range.py From appengine-mapreduce with Apache License 2.0 | 6 votes |
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
Example #5
Source File: __init__.py From python-compat-runtime with Apache License 2.0 | 5 votes |
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
Example #6
Source File: handler_utils.py From upvote with Apache License 2.0 | 4 votes |
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