summaryrefslogtreecommitdiff
path: root/src/mailman/rest/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/helpers.py')
-rw-r--r--src/mailman/rest/helpers.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/mailman/rest/helpers.py b/src/mailman/rest/helpers.py
index 8de2632bc..a7bbc2bae 100644
--- a/src/mailman/rest/helpers.py
+++ b/src/mailman/rest/helpers.py
@@ -139,9 +139,12 @@ class CollectionMixin:
return etag(resource)
def _get_collection(self, request):
- """Return the collection as a concrete list.
+ """Return the collection as a list-like object.
- This must be implemented by subclasses.
+ The returned value must support iteration and slicing. It can for
+ example be a concrete list or an SQLAlchemy request.
+
+ This method must be implemented by subclasses.
:param request: An http request.
:return: The collection
@@ -162,9 +165,12 @@ class CollectionMixin:
# get turned into HTTP 400 errors.
count = request.get_param_as_int('count', min=0)
page = request.get_param_as_int('page', min=1)
- total_size = len(collection)
+ try:
+ total_size = collection.count()
+ except TypeError:
+ total_size = len(collection)
if count is None and page is None:
- return 0, total_size, collection
+ return 0, total_size, list(collection)
list_start = (page - 1) * count
list_end = page * count
return list_start, total_size, collection[list_start:list_end]