Added optional limit to get items
authorThierry Florac <tflorac@ulthar.net>
Wed, 28 Nov 2018 09:41:16 +0100
changeset 1135 af500b35394c
parent 1134 35e8b9cd9070
child 1136 34c2f50177d9
Added optional limit to get items
src/pyams_content/shared/view/portlet/__init__.py
--- a/src/pyams_content/shared/view/portlet/__init__.py	Wed Nov 28 09:39:16 2018 +0100
+++ b/src/pyams_content/shared/view/portlet/__init__.py	Wed Nov 28 09:41:16 2018 +0100
@@ -61,7 +61,7 @@
             request = check_request()
         return request.registry.queryUtility(IViewsMerger, name=self.views_merge_mode)
 
-    def get_items(self, request=None, ignore_cache=False):
+    def get_items(self, request=None, limit=None, ignore_cache=False):
         if request is None:
             request = check_request()
         if self.views_context == VIEW_DISPLAY_CONTEXT:
@@ -72,11 +72,12 @@
             ignore_cache = request.annotations.get(PREVIEW_MODE, False)
         merger = self.get_merger(request)
         if merger is not None:
+            start = int(request.params.get('start', 0))
             yield from islice(unique_iter(merger.get_results(self.get_views(),
                                                              context,
                                                              ignore_cache=ignore_cache)),
-                              (self.start or 1) - 1,
-                              self.limit)
+                              start + (self.start or 1) - 1,
+                              min(limit or 999, self.limit or 999))
 
 
 @portlet_config(permission=VIEW_PERMISSION)