From 6fe66518578067b8bbaaa6aa266b7c624fbdf3ec Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 31 Oct 2019 14:00:01 +0100 Subject: [PATCH 1/4] Fix typo. --- musician/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musician/urls.py b/musician/urls.py index 08dfd8b..e18f828 100644 --- a/musician/urls.py +++ b/musician/urls.py @@ -16,7 +16,7 @@ urlpatterns = [ path('auth/logout/', views.LogoutView.as_view(), name='logout'), path('dashboard/', views.DashboardView.as_view(), name='dashboard'), path('mails/', views.MailView.as_view(), name='mails'), - path('maling-lists/', views.MailingListsView.as_view(), name='mailing-lists'), + path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'), path('databases/', views.DatabasesView.as_view(), name='databases'), path('software-as-a-service/', views.SaasView.as_view(), name='saas'), ] From cb7587c2029d30e5ff7adcfdaae14b26b1eed556 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 31 Oct 2019 14:08:49 +0100 Subject: [PATCH 2/4] 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 From b08ecdef177f8170219e764e119d6406eac8cfd8 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 31 Oct 2019 14:09:49 +0100 Subject: [PATCH 3/4] Implement MailingList view supporting pagination. --- .../musician/components/table_paginator.html | 31 +++++++++++++++++++ musician/templates/musician/mailinglists.html | 25 ++++++++++++++- musician/views.py | 24 +++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 musician/templates/musician/components/table_paginator.html diff --git a/musician/templates/musician/components/table_paginator.html b/musician/templates/musician/components/table_paginator.html new file mode 100644 index 0000000..0bfef23 --- /dev/null +++ b/musician/templates/musician/components/table_paginator.html @@ -0,0 +1,31 @@ +{# #} + + + {{ page_obj.paginator.count }} items in total + + {% if page_obj.has_previous %} + « + + {% endif %} + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }} + {% if page_obj.has_next %} + + » + {% endif %} + + +
+ Showing + + per page + +
+ + + diff --git a/musician/templates/musician/mailinglists.html b/musician/templates/musician/mailinglists.html index 927ff1c..031c33e 100644 --- a/musician/templates/musician/mailinglists.html +++ b/musician/templates/musician/mailinglists.html @@ -3,7 +3,30 @@ {% block content %} -

Section title

+

Mailing lists

Little description of what to be expected...

+ + + + + + + + + + + + {% for resource in object_list %} + + + + + + + + {% endfor %} + + {% include "musician/components/table_paginator.html" %} +
NameStatusAddressAdmin emailConfigure
{{ resource.name }}{{ resource.status }}{{ resource.address_name}}@{{ resource.address_domain.name }}{{ resource.admin_email }}Mailtrain
{% endblock %} diff --git a/musician/views.py b/musician/views.py index 4e9674d..ef45234 100644 --- a/musician/views.py +++ b/musician/views.py @@ -34,8 +34,30 @@ class MailView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): template_name = "musician/mail.html" -class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): +class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, ListView): template_name = "musician/mailinglists.html" + paginate_by = 20 + paginate_by_kwarg = 'per_page' + + def get_queryset(self): + return self.orchestra.retrieve_service_list('mailinglist') + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'page_param': self.page_kwarg, + 'per_page_values': [5, 10, 20, 50], + 'per_page_param': self.paginate_by_kwarg, + }) + return context + + def get_paginate_by(self, queryset): + per_page = self.request.GET.get(self.paginate_by_kwarg) or self.paginate_by + try: + paginate_by = int(per_page) + except ValueError: + paginate_by = self.paginate_by + return paginate_by class DatabasesView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): From 5d985883b0a528512e8dfea96ddebfac408207d3 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 31 Oct 2019 14:26:15 +0100 Subject: [PATCH 4/4] Update changelog. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d165d31..f4fd178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,5 +6,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## master - Login & logout methods using backend as auth method -- Base template -- Services sidebar menu +- Base template with services sidebar menu +- [added] Mailing lists view.