Refactor Mailboxes list view

This commit is contained in:
Santiago L 2023-11-23 11:18:30 +01:00
parent fc09f776c4
commit 6497122024
2 changed files with 14 additions and 17 deletions

View File

@ -28,7 +28,7 @@
</td> </td>
<td>{{ mailbox.filtering }}</td> <td>{{ mailbox.filtering }}</td>
<td> <td>
{% for addr in mailbox.addresses %} {% for addr in mailbox.addresses.all %}
<a href="{% url 'musician:address-update' addr.data.id %}"> <a href="{% url 'musician:address-update' addr.data.id %}">
{{ addr.full_address_name }} {{ addr.full_address_name }}
</a><br/> </a><br/>

View File

@ -23,6 +23,7 @@ from requests.exceptions import HTTPError
from orchestra import get_version from orchestra import get_version
from orchestra.contrib.bills.models import Bill from orchestra.contrib.bills.models import Bill
from orchestra.contrib.domains.models import Domain from orchestra.contrib.domains.models import Domain
from orchestra.contrib.mailboxes.models import Address, Mailbox
from orchestra.contrib.saas.models import SaaS from orchestra.contrib.saas.models import SaaS
from orchestra.utils.html import html_to_pdf from orchestra.utils.html import html_to_pdf
@ -32,10 +33,11 @@ from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
MailboxUpdateForm, MailForm) MailboxUpdateForm, MailForm)
from .mixins import (CustomContextMixin, ExtendedPaginationMixin, from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
UserTokenRequiredMixin) UserTokenRequiredMixin)
from .models import Address from .models import Address as AddressService
from .models import Bill as BillService from .models import Bill as BillService
from .models import (DatabaseService, Mailbox, MailinglistService, from .models import DatabaseService
PaymentSource, SaasService) from .models import Mailbox as MailboxService
from .models import MailinglistService, SaasService
from .settings import ALLOWED_RESOURCES from .settings import ALLOWED_RESOURCES
from .utils import get_bootstraped_percent from .utils import get_bootstraped_percent
@ -227,28 +229,21 @@ class BillDownloadView(CustomContextMixin, UserTokenRequiredMixin, View):
class MailView(ServiceListView): class MailView(ServiceListView):
service_class = Address service_class = AddressService
model = Address
template_name = "musician/addresses.html" template_name = "musician/addresses.html"
extra_context = { extra_context = {
# Translators: This message appears on the page title # Translators: This message appears on the page title
'title': _('Mail addresses'), 'title': _('Mail addresses'),
} }
def get_queryset(self):
# retrieve mails applying filters (if any)
queryfilter = self.get_queryfilter()
addresses = self.orchestra.retrieve_mail_address_list(
querystring=queryfilter
)
return addresses
def get_queryfilter(self): def get_queryfilter(self):
"""Retrieve query params (if any) to filter queryset""" """Retrieve query params (if any) to filter queryset"""
domain_id = self.request.GET.get('domain') domain_id = self.request.GET.get('domain')
if domain_id: if domain_id:
return "domain={}".format(domain_id) return {"domain": domain_id}
return '' return {}
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -366,7 +361,8 @@ class MailingListsView(ServiceListView):
class MailboxesView(ServiceListView): class MailboxesView(ServiceListView):
service_class = Mailbox service_class = MailboxService
model = Mailbox
template_name = "musician/mailboxes.html" template_name = "musician/mailboxes.html"
extra_context = { extra_context = {
# Translators: This message appears on the page title # Translators: This message appears on the page title
@ -375,7 +371,8 @@ class MailboxesView(ServiceListView):
class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView): class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView):
service_class = Mailbox service_class = MailboxService
model = Mailbox
template_name = "musician/mailbox_form.html" template_name = "musician/mailbox_form.html"
form_class = MailboxCreateForm form_class = MailboxCreateForm
success_url = reverse_lazy("musician:mailbox-list") success_url = reverse_lazy("musician:mailbox-list")