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:
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('<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 .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):