def clean(self):
    cleaned_data = super(AdvancedAction, self).clean()
    initial_state = cleaned_data.get('initial_state')
    if (initial_state == 'backup'):
        backup = self.cleaned_data['backup']
        if backup:
            try:
                bkup = api.trove.backup_get(self.request, backup)
                self.cleaned_data['backup'] = bkup.id
            except Exception:
                raise forms.ValidationError(_('Unable to find backup!'))
        else:
            raise forms.ValidationError(_('A backup must be selected!'))
        cleaned_data['master'] = None
    elif (initial_state == 'master'):
        master = self.cleaned_data['master']
        if master:
            try:
                api.trove.instance_get(self.request, master)
            except Exception:
                raise forms.ValidationError(_('Unable to find master instance!'))
        else:
            raise forms.ValidationError(_('A master instance must be selected!'))
        cleaned_data['backup'] = None
    else:
        cleaned_data['master'] = None
        cleaned_data['backup'] = None
    return cleaned_data
def clean(self):
    cleaned_data = super(AdvancedAction, self).clean()
    initial_state = cleaned_data.get('initial_state')
    if (initial_state == 'backup'):
        backup = self.cleaned_data['backup']
        if backup:
            try:
                bkup = api.trove.backup_get(self.request, backup)
                self.cleaned_data['backup'] = bkup.id
            except Exception:
                raise forms.ValidationError(_('Unable to find backup!'))
        else:
            raise forms.ValidationError(_('A backup must be selected!'))
        cleaned_data['master'] = None
    elif (initial_state == 'master'):
        master = self.cleaned_data['master']
        if master:
            try:
                api.trove.instance_get(self.request, master)
            except Exception:
                raise forms.ValidationError(_('Unable to find master instance!'))
        else:
            raise forms.ValidationError(_('A master instance must be selected!'))
        cleaned_data['backup'] = None
    else:
        cleaned_data['master'] = None
        cleaned_data['backup'] = None
    return cleaned_data