From 47e602eb318674396fd3a9b35be13bf745b6a19c Mon Sep 17 00:00:00 2001 From: Kirill Izotov Date: Wed, 30 Apr 2014 13:07:06 +0700 Subject: [PATCH] Replace Task text field with drop-down list Change-Id: I6b73bbff181dcae93aea435b8efa172b3bbebf57 --- .../dashboards/mistral/workbooks/forms.py | 16 +++++++++++++--- .../dashboards/mistral/workbooks/urls.py | 4 ++-- horizon_dashboard/requirements.txt | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/forms.py b/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/forms.py index 38846027..90925043 100644 --- a/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/forms.py +++ b/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/forms.py @@ -1,5 +1,6 @@ from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse +import yaml from horizon import exceptions from horizon import forms @@ -13,9 +14,9 @@ class ExecuteForm(forms.SelfHandlingForm): required=True, widget=forms.TextInput( attrs={'readonly': 'readonly'})) - task = forms.CharField(label=_("Task"), - required=True, - help_text=_("Name of the task to stop")) + task = forms.ChoiceField(label=_("Task"), + required=True, + help_text=_("Task to start the execution")) context = forms.CharField(label=_("Context"), required=False, initial="{}", @@ -23,6 +24,15 @@ class ExecuteForm(forms.SelfHandlingForm): def __init__(self, request, *args, **kwargs): super(ExecuteForm, self).__init__(request, *args, **kwargs) + client = api.mistralclient(request) + workbook_definition = client.workbooks.get_definition( + kwargs['initial']['workbook_name']) + workbook = yaml.safe_load(workbook_definition) + + task_choices = [('', _("Select a task"))] + for task in workbook['Workflow']['tasks']: + task_choices.append((task, task)) + self.fields['task'].choices = task_choices def handle(self, request, data): try: diff --git a/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/urls.py b/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/urls.py index 098ff193..55bbffb7 100644 --- a/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/urls.py +++ b/horizon_dashboard/demo_dashboard/dashboards/mistral/workbooks/urls.py @@ -1,8 +1,8 @@ from django.conf.urls import patterns # noqa from django.conf.urls import url # noqa -from demo_dashboard.dashboards.mistral.workbooks.views \ - import IndexView, ExecuteView +from demo_dashboard.dashboards.mistral.workbooks.views import IndexView +from demo_dashboard.dashboards.mistral.workbooks.views import ExecuteView WORKBOOKS = r'^(?P[^/]+)/%s$' diff --git a/horizon_dashboard/requirements.txt b/horizon_dashboard/requirements.txt index 0434414f..d7a5f48a 100644 --- a/horizon_dashboard/requirements.txt +++ b/horizon_dashboard/requirements.txt @@ -1,3 +1,3 @@ -e git+https://github.com/openstack/horizon.git#egg=horizon -# -e ../python-mistralclient -e git+https://github.com/stackforge/python-mistralclient.git#egg=mistralclient +PyYAML>=3.1.0 \ No newline at end of file