Updated "append" and "prepend" methods to keep items order
authorThierry Florac <thierry.florac@onf.fr>
Tue, 08 Jan 2019 14:02:47 +0100
changeset 44 32052893d519
parent 43 9fff3eaacd26
child 45 69827ed47dde
Updated "append" and "prepend" methods to keep items order
src/pyams_catalog/query.py
--- a/src/pyams_catalog/query.py	Fri Apr 27 10:34:21 2018 +0200
+++ b/src/pyams_catalog/query.py	Tue Jan 08 14:02:47 2019 +0100
@@ -12,14 +12,9 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
+from hypatia.query import Query
 from zope.intid.interfaces import IIntIds
 
-# import packages
-from hypatia.query import Query
 from pyams_utils.registry import query_utility
 
 
@@ -52,15 +47,18 @@
         for item in self.last:
             yield item
 
+    def __len__(self):
+        return len(self.first) + len(self.query) + len(self.last)
+
     def prepend(self, items):
-        if isinstance(items, CatalogResultSet):
-            items = list(items)
-        self.first.extend(items)
+        insert = self.first.insert
+        for index, item in enumerate(items):
+            insert(index, item)
 
     def append(self, items):
-        if isinstance(items, CatalogResultSet):
-            items = list(items)
-        self.last.extend(items)
+        append = self.last.append
+        for item in items:
+            append(item)
 
 
 def or_(source, added):