From b820fba2fe793328c38e21b9768c52dce5af21a3 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Mon, 12 Mar 2012 19:02:37 -0700 Subject: [PATCH] Adds default text for keypair select widget on launch form. Fixes bug 953488. Change-Id: I089f281111203959995fb0ca5068cd2aabcd2b18 --- horizon/dashboards/nova/images_and_snapshots/images/forms.py | 4 ++++ horizon/dashboards/nova/images_and_snapshots/images/tests.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/forms.py b/horizon/dashboards/nova/images_and_snapshots/images/forms.py index 39b5d1c33..96ae043c1 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/forms.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/forms.py @@ -127,6 +127,10 @@ class LaunchForm(forms.SelfHandlingForm): def __init__(self, *args, **kwargs): flavor_list = kwargs.pop('flavor_list') keypair_list = kwargs.pop('keypair_list') + if keypair_list: + keypair_list.insert(0, ("", _("Select a keypair"))) + else: + keypair_list = (("", _("No keypairs available.")),) security_group_list = kwargs.pop('security_group_list') volume_list = kwargs.pop('volume_list') super(LaunchForm, self).__init__(*args, **kwargs) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/tests.py b/horizon/dashboards/nova/images_and_snapshots/images/tests.py index aeae615a8..dfbf1fb39 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/tests.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/tests.py @@ -62,7 +62,7 @@ class ImageViewTests(test.TestCase): self.assertIn(self.flavors.first().name, form.fields['flavor'].choices[0][1]) self.assertEqual(self.keypairs.first().name, - form.fields['keypair'].choices[0][0]) + form.fields['keypair'].choices[1][0]) def test_launch_post(self): flavor = self.flavors.first() @@ -166,7 +166,7 @@ class ImageViewTests(test.TestCase): res = self.client.get(url) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html') - self.assertEqual(len(res.context['form'].fields['keypair'].choices), 0) + self.assertEqual(len(res.context['form'].fields['keypair'].choices), 1) def test_launch_form_keystone_exception(self): flavor = self.flavors.first()