diff --git a/musician/api.py b/musician/api.py index 0536b5c..dcfe7e2 100644 --- a/musician/api.py +++ b/musician/api.py @@ -18,6 +18,7 @@ API_PATHS = { # services 'database-list': 'databases/', 'domain-list': 'domains/', + 'domain-detail': 'domains/{pk}/', 'address-list': 'addresses/', 'mailbox-list': 'mailboxes/', 'mailinglist-list': 'lists/', @@ -55,9 +56,13 @@ class Orchestra(object): return response.json().get("token", None) - def request(self, verb, resource, querystring=None, raise_exception=True): + def request(self, verb, resource=None, querystring=None, url=None, raise_exception=True): assert verb in ["HEAD", "GET", "POST", "PATCH", "PUT", "DELETE"] - url = self.build_absolute_uri(resource) + if resource is not None: + url = self.build_absolute_uri(resource) + elif url is None: + raise AttributeError("Provide `resource` or `url` params") + if querystring is not None: url = "{}?{}".format(url, querystring) @@ -86,6 +91,13 @@ class Orchestra(object): raise PermissionError("Cannot retrieve profile of an anonymous user.") return UserAccount.new_from_json(output[0]) + def retrieve_domain(self, pk): + path = API_PATHS.get('domain-detail').format_map({'pk': pk}) + + url = urllib.parse.urljoin(self.base_url, path) + status, domain_json = self.request("GET", url=url) + return Domain.new_from_json(domain_json) + def retrieve_domain_list(self): output = self.retrieve_service_list(Domain.api_name) domains = [] diff --git a/musician/templates/musician/domain_detail.html b/musician/templates/musician/domain_detail.html new file mode 100644 index 0000000..6cb459e --- /dev/null +++ b/musician/templates/musician/domain_detail.html @@ -0,0 +1,28 @@ +{% extends "musician/base.html" %} +{% load i18n %} + +{% block content %} +

{% 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.

+ + + + + + + + + + + + + + {% for record in object.records %} + + + + + {% endfor %} + +
{% trans "Type" %}{% trans "Value" %}
{{ record.type }}{{ record.value }}
+{% endblock %} diff --git a/musician/urls.py b/musician/urls.py index 340d409..6bae570 100644 --- a/musician/urls.py +++ b/musician/urls.py @@ -15,6 +15,7 @@ urlpatterns = [ path('auth/login/', views.LoginView.as_view(), name='login'), path('auth/logout/', views.LogoutView.as_view(), name='logout'), path('dashboard/', views.DashboardView.as_view(), name='dashboard'), + path('domains//', views.DomainDetailView.as_view(), name='domain-detail'), path('billing/', views.BillingView.as_view(), name='billing'), path('profile/', views.ProfileView.as_view(), name='profile'), path('mails/', views.MailView.as_view(), name='mails'), diff --git a/musician/views.py b/musician/views.py index b6b4298..7d93509 100644 --- a/musician/views.py +++ b/musician/views.py @@ -186,6 +186,26 @@ class SaasView(ServiceListView): template_name = "musician/saas.html" +class DomainDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): + template_name = "musician/domain_detail.html" + + def get_queryset(self): + return [] # self.orchestra.retrieve_domain_list() + + def get_object(self, queryset=None): + if queryset is None: + queryset = self.get_queryset() + + pk = self.kwargs.get(self.pk_url_kwarg) + # TODO try to retrieve object capturing exception + try: + domain = self.orchestra.retrieve_domain(pk) + except: + raise + + return domain + + class LoginView(FormView): template_name = 'auth/login.html' form_class = LoginForm