Merge "Make update status dialog less confusing"

This commit is contained in:
Zuul 2018-12-03 14:53:32 +00:00 committed by Gerrit Code Review
commit fb1a129ee2
4 changed files with 14 additions and 33 deletions

View File

@ -33,23 +33,25 @@ STATUS_CHOICES = tuple(
def populate_status_choices(current_status, status_choices): def populate_status_choices(current_status, status_choices):
status_choices = [status for status in status_choices choices = []
if status[0] != current_status] for status in status_choices:
status_choices.insert(0, ("", _("Select a new status"))) if status[0] == current_status:
choices.append((status[0], _("%s (current)") % status[1]))
else:
choices.append(status)
return status_choices choices.insert(0, ("", _("Select a new status")))
return choices
class UpdateStatus(forms.SelfHandlingForm): class UpdateStatus(forms.SelfHandlingForm):
status = forms.ThemableChoiceField(label=_("Status")) status = forms.ThemableChoiceField(label=_("Status"))
def __init__(self, request, *args, **kwargs): def __init__(self, request, *args, **kwargs):
# Obtain the localized status to use as initial value, has to be done # Initial values have to be operated before super() otherwise the
# before super() otherwise the initial value will get overwritten back # initial values will get overwritten back to the raw value
# to the raw value
current_status = kwargs['initial']['status'] current_status = kwargs['initial']['status']
choices = dict(STATUS_CHOICES) kwargs['initial'].pop('status')
kwargs['initial']['status'] = choices[current_status]
super(UpdateStatus, self).__init__(request, *args, **kwargs) super(UpdateStatus, self).__init__(request, *args, **kwargs)

View File

@ -20,7 +20,6 @@ from openstack_dashboard.api import cinder
from openstack_dashboard.api import keystone from openstack_dashboard.api import keystone
from openstack_dashboard.test import helpers as test from openstack_dashboard.test import helpers as test
from openstack_dashboard.dashboards.admin.snapshots import forms
from openstack_dashboard.dashboards.admin.snapshots import tables from openstack_dashboard.dashboards.admin.snapshots import tables
INDEX_URL = 'horizon:admin:snapshots:index' INDEX_URL = 'horizon:admin:snapshots:index'
@ -223,14 +222,6 @@ class VolumeSnapshotsViewTests(test.BaseAdminViewTests):
self.mock_volume_snapshot_get.assert_called_once_with( self.mock_volume_snapshot_get.assert_called_once_with(
test.IsHttpRequest(), snapshot.id) test.IsHttpRequest(), snapshot.id)
def test_get_snapshot_status_choices_without_current(self):
current_status = 'available'
status_choices = forms.populate_status_choices(current_status,
forms.STATUS_CHOICES)
self.assertEqual(len(status_choices), len(forms.STATUS_CHOICES))
self.assertNotIn(current_status,
[status[0] for status in status_choices])
@test.create_mocks({cinder: ('volume_snapshot_get',)}) @test.create_mocks({cinder: ('volume_snapshot_get',)})
def test_update_volume_status_get(self): def test_update_volume_status_get(self):
snapshot = self.cinder_volume_snapshots.first() snapshot = self.cinder_volume_snapshots.first()

View File

@ -217,12 +217,10 @@ class UpdateStatus(forms.SelfHandlingForm):
status = forms.ThemableChoiceField(label=_("Status")) status = forms.ThemableChoiceField(label=_("Status"))
def __init__(self, request, *args, **kwargs): def __init__(self, request, *args, **kwargs):
# Obtain the localized status to use as initial value, has to be done # Initial values have to be operated before super() otherwise the
# before super() otherwise the initial value will get overwritten back # initial values will get overwritten back to the raw value
# to the raw value
current_status = kwargs['initial']['status'] current_status = kwargs['initial']['status']
choices = dict(STATUS_CHOICES) kwargs['initial'].pop('status')
kwargs['initial']['status'] = choices[current_status]
super(UpdateStatus, self).__init__(request, *args, **kwargs) super(UpdateStatus, self).__init__(request, *args, **kwargs)

View File

@ -24,8 +24,6 @@ from openstack_dashboard.dashboards.project.volumes \
import tables as volume_tables import tables as volume_tables
from openstack_dashboard.test import helpers as test from openstack_dashboard.test import helpers as test
from openstack_dashboard.dashboards.admin.snapshots import forms
DETAIL_URL = ('horizon:admin:volumes:detail') DETAIL_URL = ('horizon:admin:volumes:detail')
INDEX_URL = reverse('horizon:admin:volumes:index') INDEX_URL = reverse('horizon:admin:volumes:index')
@ -365,14 +363,6 @@ class VolumeTests(test.BaseAdminViewTests):
test.IsHttpRequest(), volume.id, host, False) test.IsHttpRequest(), volume.id, host, False)
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
def test_get_volume_status_choices_without_current(self):
current_status = 'available'
status_choices = forms.populate_status_choices(current_status,
forms.STATUS_CHOICES)
self.assertEqual(len(status_choices), len(forms.STATUS_CHOICES))
self.assertNotIn(current_status,
[status[0] for status in status_choices])
@test.create_mocks({api.cinder: ['volume_get']}) @test.create_mocks({api.cinder: ['volume_get']})
def test_update_volume_status_get(self): def test_update_volume_status_get(self):
volume = self.cinder_volumes.get(name='v2_volume') volume = self.cinder_volumes.get(name='v2_volume')