diff --git a/musician/api.py b/musician/api.py index bffaa3e..8e38e7c 100644 --- a/musician/api.py +++ b/musician/api.py @@ -7,7 +7,7 @@ from django.http import Http404 from django.urls.exceptions import NoReverseMatch from django.utils.translation import gettext_lazy as _ -from .models import Address, DatabaseService, Domain, SaasService, UserAccount, WebSite +from .models import Address, DatabaseService, Domain, Mailbox, SaasService, UserAccount, WebSite DOMAINS_PATH = 'domains/' TOKEN_PATH = '/api-token-auth/' @@ -179,9 +179,8 @@ class Orchestra(object): return addresses def retrieve_mailbox_list(self): - # TODO(@slamora) encapsulate as a Service class - raw_mailboxes = self.retrieve_service_list('mailbox') - return raw_mailboxes + mailboxes = self.retrieve_service_list(Mailbox.api_name) + return [Mailbox.new_from_json(mailbox_data) for mailbox_data in mailboxes] def retrieve_domain(self, pk): path = API_PATHS.get('domain-detail').format_map({'pk': pk}) diff --git a/musician/models.py b/musician/models.py index b0094b3..9e62d51 100644 --- a/musician/models.py +++ b/musician/models.py @@ -17,6 +17,7 @@ class OrchestraModel: api_name = None verbose_name = None fields = () + param_defaults = {} id = None def __init__(self, **kwargs): @@ -294,6 +295,24 @@ class Address(OrchestraModel): return mailbox_details +class Mailbox(OrchestraModel): + api_name = 'mailbox' + verbose_name = _('Mailbox') + description = _('Description details for mailbox page.') + fields = ('name', 'filtering', 'addresses', 'active') + param_defaults = { + 'name': None, + 'filtering': None, + 'is_active': True, + 'addresses': [], + } + + @classmethod + def new_from_json(cls, data, **kwargs): + addresses = [Address.new_from_json(addr) for addr in data.get('addresses', [])] + return super().new_from_json(data=data, addresses=addresses) + + class MailinglistService(OrchestraModel): api_name = 'mailinglist' verbose_name = _('Mailing list') diff --git a/musician/templates/musician/mail_base.html b/musician/templates/musician/mail_base.html index 1529874..1790e90 100644 --- a/musician/templates/musician/mail_base.html +++ b/musician/templates/musician/mail_base.html @@ -16,8 +16,8 @@ {% trans "Addresses" %} -