From 9cbeb325bbd5dbe9d075184d8ec02f95279ea52d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 11:16:23 +0100 Subject: [PATCH 1/4] 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 From 5520ff63f307dfe2b177592629c8a38c454dc93b Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 11:32:38 +0100 Subject: [PATCH 2/4] Show active_domain and add 'go to global' button. --- musician/templates/musician/mail.html | 5 ++++- musician/views.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/musician/templates/musician/mail.html b/musician/templates/musician/mail.html index f247653..e8ae8be 100644 --- a/musician/templates/musician/mail.html +++ b/musician/templates/musician/mail.html @@ -2,8 +2,11 @@ {% load i18n %} {% block content %} +{% if active_domain %} +{% trans "Go to global" %} +{% endif %} -

{{ service.verbose_name }}

+

{{ service.verbose_name }}{% if active_domain %} {% trans "for" %} {{ active_domain.name }}{% endif %}

{{ service.description }}

diff --git a/musician/views.py b/musician/views.py index 7ad9187..c45517f 100644 --- a/musician/views.py +++ b/musician/views.py @@ -177,10 +177,19 @@ class MailView(ServiceListView): 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 '' + if domain_id: + return "domain={}".format(domain_id) - return "domain={}".format(domain_id) + return '' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + domain_id = self.request.GET.get('domain') + if domain_id: + context.update({ + 'active_domain': self.orchestra.retrieve_domain(domain_id) + }) + return context class MailingListsView(ServiceListView): From 92715994c2d9d6772df177c552c02c97eb8ab1e3 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 11:57:59 +0100 Subject: [PATCH 3/4] Prepare mailing list to be filtered by domain. Will work when backend supports it. --- musician/templates/musician/mailinglists.html | 5 +++- musician/views.py | 29 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/musician/templates/musician/mailinglists.html b/musician/templates/musician/mailinglists.html index e24ea7a..a5f0824 100644 --- a/musician/templates/musician/mailinglists.html +++ b/musician/templates/musician/mailinglists.html @@ -2,8 +2,11 @@ {% load i18n %} {% block content %} +{% if active_domain %} +{% trans "Go to global" %} +{% endif %} -

{{ service.verbose_name }}

+

{{ service.verbose_name }}{% if active_domain %} {% trans "for" %} {{ active_domain.name }}{% endif %}

{{ service.description }}

diff --git a/musician/views.py b/musician/views.py index c45517f..51a5013 100644 --- a/musician/views.py +++ b/musician/views.py @@ -127,10 +127,17 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ raise ImproperlyConfigured( "ServiceListView requires a definiton of 'service'") + queryfilter = self.get_queryfilter() json_qs = self.orchestra.retrieve_service_list( - self.service_class.api_name) + self.service_class.api_name, + querystring=queryfilter, + ) return [self.service_class.new_from_json(data) for data in json_qs] + def get_queryfilter(self): + """Does nothing by default. Should be implemented on subclasses""" + return '' + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ @@ -197,6 +204,26 @@ class MailingListsView(ServiceListView): template_name = "musician/mailinglists.html" + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + domain_id = self.request.GET.get('domain') + if domain_id: + context.update({ + 'active_domain': self.orchestra.retrieve_domain(domain_id) + }) + return context + + def get_queryfilter(self): + """Retrieve query params (if any) to filter queryset""" + # TODO(@slamora): this is not working because backend API + # doesn't support filtering by domain + domain_id = self.request.GET.get('domain') + if domain_id: + return "domain={}".format(domain_id) + + return '' + + class DatabasesView(ServiceListView): template_name = "musician/databases.html" service_class = DatabaseService From 78fcfeefcbd0f684986021fd82fa8d8a5f2a4ab3 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 17 Dec 2019 11:58:38 +0100 Subject: [PATCH 4/4] Remove unused css id. --- musician/templates/musician/domain_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musician/templates/musician/domain_detail.html b/musician/templates/musician/domain_detail.html index 515a724..168e7e6 100644 --- a/musician/templates/musician/domain_detail.html +++ b/musician/templates/musician/domain_detail.html @@ -2,7 +2,7 @@ {% load i18n %} {% block content %} -{% trans "Go back" %} +{% trans "Go back" %}

{% trans "DNS settings for" %} {{ object.name }}

Litle description of what to be expected in this section to aid the user. Even a link to more help if there is one available.