Merge "Remove current consumer in QoS spec edit"
This commit is contained in:
@@ -218,8 +218,12 @@ class ManageQosSpecAssociation(forms.SelfHandlingForm):
|
|||||||
|
|
||||||
|
|
||||||
class EditQosSpecConsumer(forms.SelfHandlingForm):
|
class EditQosSpecConsumer(forms.SelfHandlingForm):
|
||||||
|
current_consumer = forms.CharField(label=_("Current consumer"),
|
||||||
|
widget=forms.TextInput(
|
||||||
|
attrs={'readonly': 'readonly'}),
|
||||||
|
required=False)
|
||||||
consumer_choice = forms.ChoiceField(
|
consumer_choice = forms.ChoiceField(
|
||||||
label=_("QoS Spec Consumer"),
|
label=_("New QoS Spec Consumer"),
|
||||||
choices=cinder.CONSUMER_CHOICES,
|
choices=cinder.CONSUMER_CHOICES,
|
||||||
help_text=_("Choose consumer for this QoS Spec."))
|
help_text=_("Choose consumer for this QoS Spec."))
|
||||||
|
|
||||||
@@ -227,19 +231,11 @@ class EditQosSpecConsumer(forms.SelfHandlingForm):
|
|||||||
super(EditQosSpecConsumer, self).__init__(request, *args, **kwargs)
|
super(EditQosSpecConsumer, self).__init__(request, *args, **kwargs)
|
||||||
consumer_field = self.fields['consumer_choice']
|
consumer_field = self.fields['consumer_choice']
|
||||||
qos_spec = self.initial["qos_spec"]
|
qos_spec = self.initial["qos_spec"]
|
||||||
consumer_field.initial = qos_spec.consumer
|
self.fields['current_consumer'].initial = qos_spec.consumer
|
||||||
|
choices = [choice for choice in cinder.CONSUMER_CHOICES
|
||||||
def clean_consumer_choice(self):
|
if choice[0] != qos_spec.consumer]
|
||||||
# ensure that new consumer isn't the same as current consumer
|
choices.insert(0, ("", _("Select a new consumer")))
|
||||||
qos_spec = self.initial['qos_spec']
|
consumer_field.choices = choices
|
||||||
cleaned_new_consumer = self.cleaned_data.get('consumer_choice')
|
|
||||||
old_consumer = qos_spec.consumer
|
|
||||||
|
|
||||||
if cleaned_new_consumer == old_consumer:
|
|
||||||
raise forms.ValidationError(
|
|
||||||
_('QoS Spec consumer value must be different than '
|
|
||||||
'the current consumer value.'))
|
|
||||||
return cleaned_new_consumer
|
|
||||||
|
|
||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
qos_spec_id = self.initial['qos_spec_id']
|
qos_spec_id = self.initial['qos_spec_id']
|
||||||
|
Reference in New Issue
Block a user