Create mailing list view.

This commit is contained in:
Santiago Lamora 2019-11-13 11:42:23 +01:00
parent 24bce2ab04
commit 0fa3408035
2 changed files with 40 additions and 13 deletions

View File

@ -1,10 +1,10 @@
class MailService: from django.utils.html import format_html
name = 'address'
verbose_name = 'Mail'
fields = ('mail_address', 'aliases', 'type', 'type_detail')
FORWARD = 'forward'
MAILBOX = 'mailbox' class Service:
name = None
verbose_name = None
fields = ()
def __init__(self, data={}): def __init__(self, data={}):
if self.verbose_name is None: if self.verbose_name is None:
@ -16,6 +16,15 @@ class MailService:
# retrieve attr of the object and if undefined get raw data # retrieve attr of the object and if undefined get raw data
return getattr(self, key, self.data.get(key)) 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 @property
def aliases(self): def aliases(self):
return [ return [
@ -38,3 +47,23 @@ class MailService:
return self.data['forward'] return self.data['forward']
# TODO(@slamora) retrieve mailbox usage # TODO(@slamora) retrieve mailbox usage
return {'usage': 0, 'total': 213} 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('<a href="#TODO">Mailtrain</a>')

View File

@ -14,7 +14,7 @@ from .auth import login as auth_login
from .auth import logout as auth_logout from .auth import logout as auth_logout
from .forms import LoginForm from .forms import LoginForm
from .mixins import CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin from .mixins import CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin
from .models import MailService from .models import MailService, MailinglistService
class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
@ -43,7 +43,8 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ
raise ImproperlyConfigured( raise ImproperlyConfigured(
"ServiceListView requires a definiton of 'service'") "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): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -77,16 +78,13 @@ class MailView(ServiceListView):
data = thing data = thing
data['names'] = aliases data['names'] = aliases
addresses.append(MailService(data)) addresses.append(self.service_class(data))
return addresses return addresses
class MailingListsView(ServiceListView): class MailingListsView(ServiceListView):
template_name = "musician/mailinglists.html" service_class = MailinglistService
def get_queryset(self):
return self.orchestra.retrieve_service_list('mailinglist')
class DatabasesView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): class DatabasesView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):