diff --git a/modoboa/admin/models.py b/modoboa/admin/models.py index fbd162fb6..682e0d36b 100644 --- a/modoboa/admin/models.py +++ b/modoboa/admin/models.py @@ -555,6 +555,7 @@ class Domain(DatesAware): events.raiseEvent("DomainAliasDeleted", self.domainalias_set.all()) ungrant_access_to_objects(self.domainalias_set.all()) if self.mailbox_set.count(): + Quota.objects.filter(username__contains='@%s' % self.name).delete() events.raiseEvent("DeleteMailbox", self.mailbox_set.all()) ungrant_access_to_objects(self.mailbox_set.all()) hm = parameters.get_admin("HANDLE_MAILBOXES", raise_error=False) @@ -724,6 +725,8 @@ class Mailbox(DatesAware): self.quota = value def get_cur_quota(self): + if not self.quota: + return 0 q = Quota.objects.get(username=self.full_address) return q.bytes / (self.quota * 1048576) * 100 @@ -743,8 +746,19 @@ class Mailbox(DatesAware): Quota.objects.create(username=self.full_address) def delete(self, keepdir=False): - q = Quota.objects.get(username=self.full_address) - q.delete() + """Custom delete method + + We try to delete the associated quota in the same time (it may + has already been removed if we're deleting a domain). + + :param bool keepdir: delete the mailbox home dir on the filesystem or not + """ + try: + q = Quota.objects.get(username=self.full_address) + except Quota.DoesNotExist: + pass + else: + q.delete() super(Mailbox, self).delete() if not keepdir: self.delete_dir() diff --git a/modoboa/admin/static/admin/js/admin.js b/modoboa/admin/static/admin/js/admin.js index 3db113d36..72dfb7383 100644 --- a/modoboa/admin/static/admin/js/admin.js +++ b/modoboa/admin/static/admin/js/admin.js @@ -122,13 +122,13 @@ Domains.prototype = { var deloptions = (data.handle_mailboxes) ? {keepdir: gettext("Do not delete domain directory")} : {}; - var warnmsg = (data.auto_account_removal) + var warnmsg = (data.auto_account_removal && data.auto_account_removal == "yes") ? gettext("This operation will remove ALL data associated to this domain.") : gettext("This operation will remove all data associated to this domain, excepting accounts."); $("a[name=deldomain]").confirm({ question: gettext("Delete this domain?"), - warning: gettext("This operation will remove ALL data associated to this domain."), + warning: warnmsg, checkboxes: deloptions, success_cb: $.proxy(this.reload_listing, this) });