From cb7587c2029d30e5ff7adcfdaae14b26b1eed556 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 31 Oct 2019 14:08:49 +0100 Subject: [PATCH] Create a generic method to retrieve any service. --- musician/api.py | 8 ++++++-- musician/views.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/musician/api.py b/musician/api.py index 9e91561..5e36372 100644 --- a/musician/api.py +++ b/musician/api.py @@ -14,6 +14,7 @@ API_PATHS = { # services 'domain-list': 'domains/', + 'mailinglist-list': 'lists/', # ... TODO (@slamora) complete list of backend URLs } @@ -61,8 +62,11 @@ class Orchestra(object): return status, output - def retrieve_domains(self): - status, output = self.request("GET", 'domain-list') + def retrieve_service_list(self, service_name): + pattern_name = '{}-list'.format(service_name) + if pattern_name not in API_PATHS: + raise ValueError("Unknown service {}".format(service_name)) + _, output = self.request("GET", pattern_name) return output def retreve_profile(self): diff --git a/musician/views.py b/musician/views.py index 7f7e7c3..4e9674d 100644 --- a/musician/views.py +++ b/musician/views.py @@ -5,6 +5,7 @@ from django.urls import reverse_lazy from django.utils.http import is_safe_url from django.views.generic.base import RedirectView, TemplateView from django.views.generic.edit import FormView +from django.views.generic.list import ListView from . import api, get_version from .auth import login as auth_login @@ -20,7 +21,7 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): context = super().get_context_data(**kwargs) # TODO retrieve all data needed from orchestra - raw_domains = self.orchestra.retrieve_domains() + raw_domains = self.orchestra.retrieve_service_list('domain') context.update({ 'domains': raw_domains