Add update workflow support

Partially implements blueprint mistral-dashboard-crud-operations

Change-Id: Idcd728fd5788ff126026628899c3c232eee8470f
This commit is contained in:
Zhenguo Niu 2015-07-15 11:29:51 +08:00
parent b4b3edad18
commit 85a20944cc
7 changed files with 73 additions and 1 deletions

View File

@ -110,6 +110,15 @@ def workflow_delete(request, workflow_name):
return mistralclient(request).workflows.delete(workflow_name)
def workflow_update(request, workflows_definition):
"""Update workflow.
:param workflows_definition: Workflows definition
"""
return mistralclient(request).workflows.update(workflows_definition)
@handle_errors(_("Unable to retrieve workbooks."), [])
def workbook_list(request):
"""Returns all workbooks."""

View File

@ -143,3 +143,18 @@ class CreateForm(forms.SelfHandlingForm):
msg = _('Failed to create workflow.')
redirect = reverse('horizon:mistral:workflows:index')
exceptions.handle(request, msg, redirect=redirect)
class UpdateForm(CreateForm):
def handle(self, request, data):
try:
api.workflow_update(request, data['definition'])
msg = _('Successfully updated workflow.')
messages.success(request, msg)
return True
except Exception:
msg = _('Failed to update workflow.')
redirect = reverse('horizon:mistral:workflows:index')
exceptions.handle(request, msg, redirect=redirect)

View File

@ -31,6 +31,14 @@ class CreateWorkflow(tables.LinkAction):
icon = "plus"
class UpdateWorkflow(tables.LinkAction):
name = "update"
verbose_name = _("Update Workflow")
url = "horizon:mistral:workflows:change_definition"
classes = ("ajax-modal",)
icon = "pencil"
class DeleteWorkflow(tables.DeleteAction):
@staticmethod
def action_present(count):
@ -103,5 +111,5 @@ class WorkflowsTable(tables.DataTable):
class Meta:
name = "workflows"
verbose_name = _("Workflows")
table_actions = (CreateWorkflow, DeleteWorkflow)
table_actions = (CreateWorkflow, UpdateWorkflow, DeleteWorkflow)
row_actions = (ExecuteWorkflow, DeleteWorkflow)

View File

@ -0,0 +1,6 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Update workflows with the provided definition." %}</p>
{% endblock %}

View File

@ -0,0 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Update Workflow" %}{% endblock %}
{% block main %}
{% include 'mistral/workflows/_update.html' %}
{% endblock %}

View File

@ -27,7 +27,11 @@ urlpatterns = patterns(
url(r'^select_definition$',
views.SelectDefinitionView.as_view(),
name='select_definition'),
url(r'^change_definition$',
views.ChangeDefinitionView.as_view(),
name='change_definition'),
url(r'^create$', views.CreateView.as_view(), name='create'),
url(r'^update$', views.UpdateView.as_view(), name='update'),
url(WORKFLOWS % 'execute', views.ExecuteView.as_view(), name='execute'),
url(WORKFLOWS % 'detail', views.DetailView.as_view(), name='detail'),
)

View File

@ -94,6 +94,19 @@ class SelectDefinitionView(forms.ModalFormView):
return kwargs
class ChangeDefinitionView(SelectDefinitionView):
modal_header = _("Update Definition")
submit_url = reverse_lazy("horizon:mistral:workflows:change_definition")
success_url = reverse_lazy('horizon:mistral:workflows:update')
page_title = _("Update Definition")
def get_form_kwargs(self):
kwargs = super(ChangeDefinitionView, self).get_form_kwargs()
kwargs['next_view'] = UpdateView
return kwargs
class CreateView(forms.ModalFormView):
template_name = 'mistral/workflows/create.html'
modal_header = _("Create Workflow")
@ -111,3 +124,13 @@ class CreateView(forms.ModalFormView):
initial['definition'] = self.kwargs['definition']
return initial
class UpdateView(CreateView):
template_name = 'mistral/workflows/update.html'
modal_header = _("Update Workflow")
form_id = "update_workflow"
form_class = mistral_forms.UpdateForm
submit_label = _("Update")
submit_url = reverse_lazy("horizon:mistral:workflows:update")
page_title = _("Update Workflow")