Added better support for domain account migration

This commit is contained in:
Marc 2014-10-24 11:25:05 +00:00
parent 86745f16e7
commit 1b9007a1f1
3 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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'
)
@ -112,5 +112,11 @@ class DomainAdmin(ChangeListDefaultFilter, AccountAdminMixin, ExtendedModelAdmin
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)

View File

@ -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()