diff --git a/TODO.md b/TODO.md index a0dc9c21..50da2191 100644 --- a/TODO.md +++ b/TODO.md @@ -179,3 +179,5 @@ Remember that, as always with QuerySets, any subsequent chained methods which im * Subdomain saving should not trigger bind slave + +* Domain account change, unselected checkbox: migrate subdomains diff --git a/orchestra/apps/domains/admin.py b/orchestra/apps/domains/admin.py index ebd069d9..06efcff2 100644 --- a/orchestra/apps/domains/admin.py +++ b/orchestra/apps/domains/admin.py @@ -55,7 +55,7 @@ class DomainInline(admin.TabularInline): class DomainAdmin(ChangeListDefaultFilter, AccountAdminMixin, ExtendedModelAdmin): # TODO name link - fields = ('name', 'account') + fields = ('name', ('account', 'migrate_subdomains'),) list_display = ( 'structured_name', 'display_is_top', 'websites', 'account_link' ) @@ -111,6 +111,12 @@ class DomainAdmin(ChangeListDefaultFilter, AccountAdminMixin, ExtendedModelAdmin if apps.isinstalled('orchestra.apps.websites'): qs = qs.prefetch_related('websites') return qs + + def save_related(self, request, form, formsets, change): + super(DomainAdmin, self).save_related(request, form, formsets, change) + if form.cleaned_data['migrate_subdomains']: + domain = form.instance + domain.subdomains.update(account_id=domain.account_id) admin.site.register(Domain, DomainAdmin) diff --git a/orchestra/apps/domains/forms.py b/orchestra/apps/domains/forms.py index 0c46670d..b13429a6 100644 --- a/orchestra/apps/domains/forms.py +++ b/orchestra/apps/domains/forms.py @@ -8,6 +8,9 @@ from .models import Domain class DomainAdminForm(forms.ModelForm): + migrate_subdomains = forms.BooleanField(label=_("Migrate subdomains"), required=False, + initial=False, help_text=_("Propagate the account owner change to subdomains.")) + def clean(self): """ inherit related top domain account, when exists """ cleaned_data = super(DomainAdminForm, self).clean()