From 9cbeb325bbd5dbe9d075184d8ec02f95279ea52d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 11:16:23 +0100 Subject: [PATCH] Filter mail addresses by domain (if any). --- musician/views.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/musician/views.py b/musician/views.py index ae3b019..7ad9187 100644 --- a/musician/views.py +++ b/musician/views.py @@ -153,9 +153,14 @@ class MailView(ServiceListView): return mailboxes[0]['id'] - # group addresses with the same mailbox + # retrieve mails applying filters (if any) + queryfilter = self.get_queryfilter() raw_data = self.orchestra.retrieve_service_list( - self.service_class.api_name) + self.service_class.api_name, + querystring=queryfilter, + ) + + # group addresses with the same mailbox addresses = [] for key, group in groupby(raw_data, retrieve_mailbox): aliases = [] @@ -169,6 +174,14 @@ class MailView(ServiceListView): return addresses + def get_queryfilter(self): + """Retrieve query params (if any) to filter queryset""" + domain_id = self.request.GET.get('domain') + if domain_id is None: + return '' + + return "domain={}".format(domain_id) + class MailingListsView(ServiceListView): service_class = MailinglistService