WIP: update mailboxes.

see #831
This commit is contained in:
Antoine Nguyen
2016-01-30 14:58:25 +01:00
parent 3181f5df5d
commit 173e43e270
4 changed files with 72 additions and 44 deletions
+15 -3
View File
@@ -29,7 +29,6 @@ class DomainManager(Manager):
@python_2_unicode_compatible
class Domain(AdminObject):
"""Mail domain."""
name = models.CharField(ugettext_lazy('name'), max_length=100, unique=True,
@@ -53,6 +52,12 @@ class Domain(AdminObject):
ordering = ["name"]
app_label = "admin"
def __init__(self, *args, **kwargs):
"""Save name for further use."""
super(Domain, self).__init__(*args, **kwargs)
self.old_mail_homes = None
self.oldname = self.name
@property
def domainalias_count(self):
return self.domainalias_set.count()
@@ -124,9 +129,16 @@ class Domain(AdminObject):
for al in self.alias_set.all():
ungrant_access_to_object(al, account)
def save(self, *args, **kwargs):
"""Store current data if domain is renamed."""
if self.oldname != self.name:
self.old_mail_homes = (
dict((mb.id, mb.mail_home) for mb in self.mailbox_set.all())
)
super(Domain, self).save(*args, **kwargs)
def delete(self, fromuser, keepdir=False):
"""Custom delete method.
"""
"""Custom delete method."""
from modoboa.lib.permissions import ungrant_access_to_objects
from .mailbox import Quota