diff options
| author | Aurélien Bompard | 2016-10-26 10:30:58 +0200 |
|---|---|---|
| committer | Barry Warsaw | 2016-10-26 08:39:07 -0400 |
| commit | 88176f08e67a8f6ad706f371167167e75d4a3e04 (patch) | |
| tree | 29e4a10e478d6acc8b5342aa5976613b762c4bbc /src | |
| parent | e75d653f700dcf9a0a31550384d6511c47d024c1 (diff) | |
| download | mailman-88176f08e67a8f6ad706f371167167e75d4a3e04.tar.gz mailman-88176f08e67a8f6ad706f371167167e75d4a3e04.tar.zst mailman-88176f08e67a8f6ad706f371167167e75d4a3e04.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/interfaces/listmanager.py | 5 | ||||
| -rw-r--r-- | src/mailman/model/listmanager.py | 10 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_listmanager.py | 9 | ||||
| -rw-r--r-- | src/mailman/rest/docs/lists.rst | 6 | ||||
| -rw-r--r-- | src/mailman/rest/lists.py | 4 |
5 files changed, 20 insertions, 14 deletions
diff --git a/src/mailman/interfaces/listmanager.py b/src/mailman/interfaces/listmanager.py index 771eabd70..2c7208496 100644 --- a/src/mailman/interfaces/listmanager.py +++ b/src/mailman/interfaces/listmanager.py @@ -143,10 +143,11 @@ class IListManager(Interface): """An iterator over the 2-tuple of (list_name, mail_host) for all mailing lists managed by this list manager.""") - def find(**filters): + def find(*, advertised=None, mail_host=None): """Search for mailing lists matching some criteria. - The filters are mailing list properties that will be filtered upon. + The keyword arguments are mailing list properties that will be + filtered upon. :return: The list of filtered mailing lists. :rtype: list of `IMailingList` diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py index c02736aab..e2519af5b 100644 --- a/src/mailman/model/listmanager.py +++ b/src/mailman/model/listmanager.py @@ -124,7 +124,11 @@ class ListManager: yield list_name, mail_host @dbconnection - def find(self, store, **kw): - query = store.query(MailingList).filter_by(**kw).order_by( - MailingList._list_id) + def find(self, store, *, advertised=None, mail_host=None): + query = store.query(MailingList) + if advertised is not None: + query = query.filter_by(advertised=advertised) + if mail_host is not None: + query = query.filter_by(mail_host=mail_host) + query = query.order_by(MailingList._list_id) return QuerySequence(query) diff --git a/src/mailman/model/tests/test_listmanager.py b/src/mailman/model/tests/test_listmanager.py index d69486370..1a643f248 100644 --- a/src/mailman/model/tests/test_listmanager.py +++ b/src/mailman/model/tests/test_listmanager.py @@ -105,11 +105,12 @@ class TestListManager(unittest.TestCase): def test_find_list(self): ant = create_list('ant@example.com') - create_list('bee@example.com') - ant.anonymous_list = True - result = getUtility(IListManager).find(anonymous_list=True) + bee = create_list('bee@example.com') + self.assertTrue(bee.advertised) + ant.advertised = False + result = getUtility(IListManager).find(advertised=True) self.assertEqual(len(result), 1) - self.assertEqual(result[0], ant) + self.assertEqual(result[0], bee) class TestListLifecycleEvents(unittest.TestCase): diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst index eb8314704..aa9c01362 100644 --- a/src/mailman/rest/docs/lists.rst +++ b/src/mailman/rest/docs/lists.rst @@ -49,14 +49,14 @@ 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. +Advertised lists can be filtered using the ``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') + >>> dump_json('http://localhost:9001/3.0/lists?advertised=true') entry 0: ... list_id: ant.example.com @@ -67,7 +67,7 @@ Advertised lists can be filtered using the ``only_advertised`` query parameter. The same applies to lists from a particular domain. - >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists?only_advertised=true') + >>> dump_json('http://localhost:9001/3.0/domains/example.com/lists?advertised=true') entry 0: ... list_id: ant.example.com diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index dc1d75203..8952f1156 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -111,8 +111,8 @@ class _ListBase(CollectionMixin): def _filter_lists(self, request, **kw): """Filter a collection using query parameters.""" - only_advertised = request.get_param_as_bool('only_advertised') - if only_advertised: + advertised = request.get_param_as_bool('advertised') + if advertised: kw['advertised'] = True return getUtility(IListManager).find(**kw) |
