diff options
| author | Aurélien Bompard | 2015-11-23 11:20:23 +0100 |
|---|---|---|
| committer | Barry Warsaw | 2016-01-06 18:54:00 -0500 |
| commit | 48adfd3470e35b2c209971110917013c50b4e3f7 (patch) | |
| tree | eb46eba361abf23c7d3ed7ac35e9868532554328 /src/mailman/rest/helpers.py | |
| parent | e93affa947002959138cf8a45f33bea5fa06d3f7 (diff) | |
| download | mailman-48adfd3470e35b2c209971110917013c50b4e3f7.tar.gz mailman-48adfd3470e35b2c209971110917013c50b4e3f7.tar.zst mailman-48adfd3470e35b2c209971110917013c50b4e3f7.zip | |
Diffstat (limited to 'src/mailman/rest/helpers.py')
| -rw-r--r-- | src/mailman/rest/helpers.py | 14 |
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] |
