Fix MailboxDeleteView

This commit is contained in:
Santiago L 2024-01-25 14:19:58 +01:00
parent d4b44d58c8
commit f140fe480e
1 changed files with 7 additions and 15 deletions

View File

@ -391,29 +391,21 @@ class MailboxUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
model = Mailbox
template_name = "musician/mailbox_check_delete.html" template_name = "musician/mailbox_check_delete.html"
success_url = reverse_lazy("musician:mailbox-list") success_url = reverse_lazy("musician:mailbox-list")
def get_object(self, queryset=None): def get_queryset(self) -> QuerySet[Any]:
obj = self.orchestra.retrieve_mailbox(self.kwargs['pk']) return self.model.objects.filter(account=self.request.user)
return obj
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
self.object = self.get_object() response = super().delete(request, *args, **kwargs)
try:
self.orchestra.delete_mailbox(self.object.id)
messages.success(self.request, _('Mailbox deleted!'))
except HTTPError as e:
messages.error(self.request, _('Cannot process your request, please try again later.'))
logger.error(e)
self.notify_managers(self.object) self.notify_managers(self.object)
return response
return HttpResponseRedirect(self.success_url)
def notify_managers(self, mailbox): def notify_managers(self, mailbox):
user = self.get_context_data()['profile'] user = self.request.user
subject = 'Mailbox {} ({}) deleted | Musician'.format(mailbox.id, mailbox.name) subject = f"Mailbox '{mailbox.name}' ({mailbox.id}) deleted | Musician"
content = ( content = (
"User {} ({}) has deleted its mailbox {} ({}) via musician.\n" "User {} ({}) has deleted its mailbox {} ({}) via musician.\n"
"The mailbox has been marked as inactive but has not been removed." "The mailbox has been marked as inactive but has not been removed."