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.
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/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 %}
+ |
+
+
+ |
+
+
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...
+
+
+
+ Name |
+ Status |
+ Address |
+ Admin email |
+ Configure |
+
+
+
+ {% for resource in object_list %}
+
+ {{ resource.name }} |
+ {{ resource.status }} |
+ {{ resource.address_name}}@{{ resource.address_domain.name }} |
+ {{ resource.admin_email }} |
+ Mailtrain |
+
+ {% endfor %}
+
+ {% include "musician/components/table_paginator.html" %}
+
{% endblock %}
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'),
]
diff --git a/musician/views.py b/musician/views.py
index 7f7e7c3..ef45234 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
@@ -33,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):