# HG changeset patch # User Thierry Florac # Date 1498563717 -7200 # Node ID 464671eede988b21b836cad211d16352f1c95a6b # Parent 9da606c609cb73625671cf6b5b735436fb492986 Updated CatalogResultSet class to be able to feed it with a list of internal IDs as well a Query object, and added "prepend" and "append" methods to be able to add a list of items to the beginning or the end of the initial results list diff -r 9da606c609cb -r 464671eede98 src/pyams_catalog/query.py --- a/src/pyams_catalog/query.py Tue Jun 06 17:05:31 2017 +0200 +++ b/src/pyams_catalog/query.py Tue Jun 27 13:41:57 2017 +0200 @@ -29,20 +29,38 @@ def __init__(self, query): self.query = query self.intids = query_utility(IIntIds) + self.first = [] + self.last = [] def __iter__(self): + for item in self.first: + yield item intids = self.intids - if intids is None: - raise StopIteration - query = self.query - if isinstance(query, Query): - query = query.execute() - if isinstance(query, tuple): - query = query[1] - for oid in query: - target = intids.queryObject(oid) - if target is not None: - yield target + if intids is not None: + query = self.query + if isinstance(query, Query): + query = query.execute() + if isinstance(query, tuple): + query = query[1] + for oid in query: + if isinstance(oid, int): + target = intids.queryObject(oid) + if target is not None: + yield target + else: + yield oid + for item in self.last: + yield item + + def prepend(self, items): + if isinstance(items, CatalogResultSet): + items = list(items) + self.first.extend(items) + + def append(self, items): + if isinstance(items, CatalogResultSet): + items = list(items) + self.last.extend(items) def or_(source, added):