Create a generic method to retrieve any service.

This commit is contained in:
Santiago Lamora 2019-10-31 14:08:49 +01:00
parent 6fe6651857
commit cb7587c202
2 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -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