コード例 #1
0
ファイル: forms.py プロジェクト: rapacides/modoboa
    def save(self, user, commit=True):
        d = super(DomainFormGeneral, self).save(commit=False)
        if commit:
            old_mail_homes = None
            hm = parameters.get_admin("HANDLE_MAILBOXES", raise_error=False)
            if hm == "yes":
                if self.oldname is not None and d.name != self.oldname:
                    for q in Quota.objects.filter(username__contains="@%s" % self.oldname):
                        q.username = q.username.replace("@%s" % self.oldname, "@%s" % d.name)
                        q.save()
                    old_mail_homes = dict((mb.id, mb.mail_home) for mb in d.mailbox_set.all())
            d.save()
            Mailbox.objects.filter(domain=d, use_domain_quota=True).update(quota=d.quota)
            if old_mail_homes is not None:
                for mb in d.mailbox_set.all():
                    mb.rename_dir(old_mail_homes[mb.id])
            for k, v in self.cleaned_data.iteritems():
                if not k.startswith("aliases"):
                    continue
                if v in ["", None]:
                    continue
                try:
                    d.domainalias_set.get(name=v)
                except DomainAlias.DoesNotExist:
                    pass
                else:
                    continue
                events.raiseEvent("CanCreate", user, "domain_aliases")
                al = DomainAlias(name=v, target=d, enabled=d.enabled)
                al.save(creator=user)

            for dalias in d.domainalias_set.all():
                if not len(filter(lambda name: self.cleaned_data[name] == dalias.name, self.cleaned_data.keys())):
                    dalias.delete()
        return d
コード例 #2
0
ファイル: forms.py プロジェクト: Tdey/modoboa
    def save(self, user, commit=True):
        """Custom save method

        Updating a domain may have consequences on other objects
        (domain alias, mailbox, quota). The most tricky part concerns
        quotas update.

        """
        d = super(DomainFormGeneral, self).save(commit=False)
        if commit:
            old_mail_homes = None
            if self.oldname is not None and d.name != self.oldname:
                d.name = self.oldname
                old_mail_homes = \
                    dict((mb.id, mb.mail_home) for mb in d.mailbox_set.all())
                d.name = self.cleaned_data['name']
            d.save()
            Mailbox.objects.filter(domain=d, use_domain_quota=True) \
                .update(quota=d.quota)
            for k, v in self.cleaned_data.iteritems():
                if not k.startswith("aliases"):
                    continue
                if v in ["", None]:
                    continue
                try:
                    d.domainalias_set.get(name=v)
                except DomainAlias.DoesNotExist:
                    pass
                else:
                    continue
                events.raiseEvent("CanCreate", user, "domain_aliases")
                al = DomainAlias(name=v, target=d, enabled=d.enabled)
                al.save(creator=user)

            for dalias in d.domainalias_set.all():
                if not len(filter(lambda name: self.cleaned_data[name] == dalias.name,
                                  self.cleaned_data.keys())):
                    dalias.delete()

            if old_mail_homes is not None:
                self.update_mailbox_quotas(d)
                for mb in d.mailbox_set.all():
                    mb.rename_dir(old_mail_homes[mb.id])

        return d