diff options
| author | Aurélien Bompard | 2016-05-19 17:06:58 +0200 |
|---|---|---|
| committer | Barry Warsaw | 2016-10-26 08:39:07 -0400 |
| commit | 72197b0ca012c55b290230d846c6a65314c6fe05 (patch) | |
| tree | bf2c1ee87c02592ca37d717033b44c6180b84524 | |
| parent | 6c1e74d93212ee6922ea8500dbecb4cf2eff1114 (diff) | |
| download | mailman-72197b0ca012c55b290230d846c6a65314c6fe05.tar.gz mailman-72197b0ca012c55b290230d846c6a65314c6fe05.tar.zst mailman-72197b0ca012c55b290230d846c6a65314c6fe05.zip | |
| -rw-r--r-- | src/mailman/rest/docs/lists.rst | 30 | ||||
| -rw-r--r-- | src/mailman/rest/lists.py | 14 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst index 6554b04c2..eb8314704 100644 --- a/src/mailman/rest/docs/lists.rst +++ b/src/mailman/rest/docs/lists.rst @@ -49,6 +49,33 @@ You can also query for lists from a particular domain. start: 0 total_size: 1 +Advertised lists can be filtered using the ``only_advertised`` query parameter. +:: + + >>> mlist = create_list('bird@example.com') + >>> mlist.advertised = False + >>> transaction.commit() + + >>> dump_json('http://localhost:9001/3.0/lists?only_advertised=true') + entry 0: + ... + list_id: ant.example.com + ... + http_etag: "..." + start: 0 + total_size: 1 + +The same applies to lists from a particular domain. + + >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists?only_advertised=true') + entry 0: + ... + list_id: ant.example.com + ... + http_etag: "..." + start: 0 + total_size: 1 + Paginating over list records ---------------------------- @@ -59,9 +86,6 @@ request URI. Page 1 is the first page and ``count`` defines the size of the page. :: - >>> mlist = create_list('bird@example.com') - >>> transaction.commit() - >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists' ... '?count=1&page=1') entry 0: diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index c3919c001..3d2ed072c 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -107,7 +107,16 @@ class _ListBase(CollectionMixin): def _get_collection(self, request): """See `CollectionMixin`.""" - return list(getUtility(IListManager)) + return self._filter_lists( + request, list(getUtility(IListManager))) + + def _filter_lists(self, request, lists): + """Filter a collection using query parameters.""" + only_advertised = request.get_param_as_bool('only_advertised') + if only_advertised: + return [l for l in lists if l.advertised] + else: + return lists @public @@ -299,7 +308,8 @@ class ListsForDomain(_ListBase): def _get_collection(self, request): """See `CollectionMixin`.""" - return list(self._domain.mailing_lists) + return self._filter_lists( + request, list(self._domain.mailing_lists)) @public |
