Merge branch 'wf-mailinglists'

This commit is contained in:
Santiago Lamora 2019-10-31 14:26:28 +01:00
commit d288770c25
6 changed files with 89 additions and 8 deletions

View file

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

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

@ -0,0 +1,31 @@
{# <!-- table footer based paginator for ListView --> #}
<tfoot>
<tr>
<td colspan="2">{{ page_obj.paginator.count }} items in total</td>
<td class="text-center">
{% if page_obj.has_previous %}
<a href="?page=1&per_page={{ page_obj.paginator.per_page }}">&laquo;</a>
<a href="?page={{ page_obj.previous_page_number }}&per_page={{ page_obj.paginator.per_page }}">&lsaquo;</a>
{% endif %}
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}&per_page={{ page_obj.paginator.per_page }}">&rsaquo;</a>
<a href="?page={{ page_obj.paginator.num_pages }}&per_page={{ page_obj.paginator.per_page }}">&raquo;</a>
{% endif %}
</td>
<td colspan="2" class="text-right">
<form method="get">
Showing
<select name="{{ per_page_param }}">
{% for value in per_page_values %}
{% with page_obj.paginator.per_page as per_page %}
<option value="{{ value }}" {% if value == per_page %}selected{% endif %}>{{ value }}</option>
{% endwith %}
{% endfor %}
</select>
per page
<input type="submit" value="apply" />
</form>
</td>
</tr>
</tfoot>

View file

@ -3,7 +3,30 @@
{% block content %}
<h1>Section title</h1>
<h1>Mailing lists</h1>
<p>Little description of what to be expected...</p>
<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">Name</th>
<th scope="col">Status</th>
<th scope="col">Address</th>
<th scope="col">Admin email</th>
<th scope="col">Configure</th>
</tr>
</thead>
<tbody>
{% for resource in object_list %}
<tr>
<th scope="row">{{ resource.name }}</th>
<td>{{ resource.status }}</td>
<td>{{ resource.address_name}}@{{ resource.address_domain.name }}</td>
<td>{{ resource.admin_email }}</td>
<td><a href="#TODO-{{ resource.manager_url }}" target="_blank" rel="noopener noreferrer">Mailtrain</a></td>
</tr>
{% endfor %}
</tbody>
{% include "musician/components/table_paginator.html" %}
</table>
{% endblock %}

View file

@ -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'),
]

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