# HG changeset patch # User Madhusudan C.S. # Date 1250015968 25200 # Node ID 054810192277d1e5f3e1c5b7f6e2a281dd501615 # Parent e8b599ba7b37794f048fb9bfa57d6cd426dec71d Added ancestors property to getQueryForFields for queries with ancestor filter. Reviewed by: Lennard de Rijk diff -r e8b599ba7b37 -r 054810192277 app/soc/logic/models/base.py --- a/app/soc/logic/models/base.py Tue Aug 11 10:54:56 2009 -0700 +++ b/app/soc/logic/models/base.py Tue Aug 11 11:39:28 2009 -0700 @@ -18,6 +18,7 @@ """ __authors__ = [ + '"Madhusudan C.S." ', '"Todd Larsen" ', '"Sverre Rabbelier" ', '"Lennard de Rijk" ', @@ -311,8 +312,8 @@ raise out_of_band.Error(msg, status=404) - def getForFields(self, filter=None, unique=False, - limit=1000, offset=0, order=None): + def getForFields(self, filter=None, unique=False, limit=1000, offset=0, + ancestors=None, order=None): """Returns all entities that have the specified properties. Args: @@ -320,20 +321,22 @@ unique: if set, only the first item from the resultset will be returned limit: the amount of entities to fetch at most offset: the position to start at + ancestors: list of ancestors properties to set for this query order: a list with the sort order """ if unique: limit = 1 - query = self.getQueryForFields(filter=filter, order=order) + query = self.getQueryForFields(filter=filter, + ancestors=ancestors, order=order) try: result = query.fetch(limit, offset) except db.NeedIndexError, exception: result = [] - logging.exception("%s, model: %s filter: %s, order: %s" % - (exception, self._model, filter, order)) + logging.exception("%s, model: %s filter: %s, ancestor: %s, order: %s" % + (exception, self._model, filter, ancestor, order)) # TODO: send email if unique: @@ -341,11 +344,12 @@ return result - def getQueryForFields(self, filter=None, order=None): + def getQueryForFields(self, filter=None, ancestors=None, order=None): """Returns a query with the specified properties. Args: filter: a dict for the properties that the entities should have + ancestors: list with ancestor properties to set for this query order: a list with the sort order Returns: @@ -355,6 +359,9 @@ if not filter: filter = {} + if not ancestors: + ancestors = [] + if not order: order = [] @@ -373,6 +380,9 @@ else: query.filter(key, value) + for ancestor in ancestors: + query.ancestor(ancestor) + for key in order: query.order(key)