From 0fa34080355a2e4c74fe239b9484452b8d2bb381 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 13 Nov 2019 11:42:23 +0100 Subject: [PATCH] Create mailing list view. --- musician/models.py | 41 +++++++++++++++++++++++++++++++++++------ musician/views.py | 12 +++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/musician/models.py b/musician/models.py index e88caa5..5eab96f 100644 --- a/musician/models.py +++ b/musician/models.py @@ -1,10 +1,10 @@ -class MailService: - name = 'address' - verbose_name = 'Mail' - fields = ('mail_address', 'aliases', 'type', 'type_detail') +from django.utils.html import format_html - FORWARD = 'forward' - MAILBOX = 'mailbox' + +class Service: + name = None + verbose_name = None + fields = () def __init__(self, data={}): if self.verbose_name is None: @@ -16,6 +16,15 @@ class MailService: # retrieve attr of the object and if undefined get raw data return getattr(self, key, self.data.get(key)) + +class MailService(Service): + name = 'address' + verbose_name = 'Mail' + fields = ('mail_address', 'aliases', 'type', 'type_detail') + + FORWARD = 'forward' + MAILBOX = 'mailbox' + @property def aliases(self): return [ @@ -38,3 +47,23 @@ class MailService: return self.data['forward'] # TODO(@slamora) retrieve mailbox usage return {'usage': 0, 'total': 213} + + +class MailinglistService(Service): + name = 'mailinglist' + verbose_name = 'Mailing list' + fields = ('name', 'status', 'address_name', 'admin_email', 'configure') + + @property + def status(self): + # TODO(@slamora): where retrieve if the list is active? + return 'active' + + @property + def address_name(self): + return "{}@{}".format(self.data['address_name'], self.data['address_domain']['name']) + + @property + def configure(self): + # TODO(@slamora): build mailtran absolute URL + return format_html('Mailtrain') diff --git a/musician/views.py b/musician/views.py index 709f393..23d5b57 100644 --- a/musician/views.py +++ b/musician/views.py @@ -14,7 +14,7 @@ from .auth import login as auth_login from .auth import logout as auth_logout from .forms import LoginForm from .mixins import CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin -from .models import MailService +from .models import MailService, MailinglistService class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): @@ -43,7 +43,8 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ raise ImproperlyConfigured( "ServiceListView requires a definiton of 'service'") - return self.orchestra.retrieve_service_list(self.service_class.name) + json_qs = self.orchestra.retrieve_service_list(self.service_class.name) + return [self.service_class(data) for data in json_qs] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -77,16 +78,13 @@ class MailView(ServiceListView): data = thing data['names'] = aliases - addresses.append(MailService(data)) + addresses.append(self.service_class(data)) return addresses class MailingListsView(ServiceListView): - template_name = "musician/mailinglists.html" - - def get_queryset(self): - return self.orchestra.retrieve_service_list('mailinglist') + service_class = MailinglistService class DatabasesView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):