Merge "Add update workbook support"
This commit is contained in:
commit
054f579494
@ -178,3 +178,12 @@ def workbook_delete(request, workbook_definition):
|
||||
"""
|
||||
|
||||
return mistralclient(request).workbooks.delete(workbook_definition)
|
||||
|
||||
|
||||
def workbook_update(request, workbook_definition):
|
||||
"""Update workbook.
|
||||
|
||||
:param workbook_definition: Workbook definition
|
||||
"""
|
||||
|
||||
return mistralclient(request).workbooks.update(workbook_definition)
|
||||
|
@ -109,3 +109,18 @@ class CreateForm(forms.SelfHandlingForm):
|
||||
msg = _('Failed to create workbook.')
|
||||
redirect = reverse('horizon:mistral:workbooks:index')
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class UpdateForm(CreateForm):
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
api.workbook_update(request, data['definition'])
|
||||
msg = _('Successfully updated workbook.')
|
||||
messages.success(request, msg)
|
||||
|
||||
return True
|
||||
except Exception:
|
||||
msg = _('Failed to update workbook.')
|
||||
redirect = reverse('horizon:mistral:workbooks:index')
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
@ -31,6 +31,14 @@ class CreateWorkbook(tables.LinkAction):
|
||||
icon = "plus"
|
||||
|
||||
|
||||
class UpdateWorkbook(tables.LinkAction):
|
||||
name = "update"
|
||||
verbose_name = _("Update Workbook")
|
||||
url = "horizon:mistral:workbooks:change_definition"
|
||||
classes = ("ajax-modal",)
|
||||
icon = "pencil"
|
||||
|
||||
|
||||
class DeleteWorkbook(tables.DeleteAction):
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
@ -86,5 +94,5 @@ class WorkbooksTable(tables.DataTable):
|
||||
class Meta(object):
|
||||
name = "workbooks"
|
||||
verbose_name = _("Workbooks")
|
||||
table_actions = (CreateWorkbook, DeleteWorkbook)
|
||||
table_actions = (CreateWorkbook, UpdateWorkbook, DeleteWorkbook)
|
||||
row_actions = (DeleteWorkbook,)
|
||||
|
@ -0,0 +1,6 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "Update workbooks with the provided definition." %}</p>
|
||||
{% endblock %}
|
@ -0,0 +1,7 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Update Workbook" %}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'mistral/workbooks/_update.html' %}
|
||||
{% endblock %}
|
@ -27,6 +27,10 @@ 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(WORKBOOKS % 'detail', views.DetailView.as_view(), name='detail'),
|
||||
)
|
||||
|
@ -76,6 +76,19 @@ class SelectDefinitionView(forms.ModalFormView):
|
||||
return kwargs
|
||||
|
||||
|
||||
class ChangeDefinitionView(SelectDefinitionView):
|
||||
modal_header = _("Update Definition")
|
||||
submit_url = reverse_lazy("horizon:mistral:workbooks:change_definition")
|
||||
success_url = reverse_lazy('horizon:mistral:workbooks: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/workbooks/create.html'
|
||||
modal_header = _("Create Workbook")
|
||||
@ -93,3 +106,13 @@ class CreateView(forms.ModalFormView):
|
||||
initial['definition'] = self.kwargs['definition']
|
||||
|
||||
return initial
|
||||
|
||||
|
||||
class UpdateView(CreateView):
|
||||
template_name = 'mistral/workbooks/update.html'
|
||||
modal_header = _("Update Workbook")
|
||||
form_id = "update_workbook"
|
||||
form_class = mistral_forms.UpdateForm
|
||||
submit_label = _("Update")
|
||||
submit_url = reverse_lazy("horizon:mistral:workbooks:update")
|
||||
page_title = _("Update Workbook")
|
||||
|
Loading…
Reference in New Issue
Block a user