2014-06-10 18:41:02 +07:00
|
|
|
# Copyright 2014 - StackStorm, Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2018-05-15 03:41:17 +09:00
|
|
|
from django.urls import reverse
|
|
|
|
from django.urls import reverse_lazy
|
2022-07-10 23:54:02 +09:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2015-07-09 23:30:57 +08:00
|
|
|
from django.views import generic
|
|
|
|
|
|
|
|
from horizon import exceptions
|
2015-07-15 15:05:08 +08:00
|
|
|
from horizon import forms
|
2014-06-10 18:41:02 +07:00
|
|
|
from horizon import tables
|
|
|
|
|
2014-06-23 14:54:57 +07:00
|
|
|
from mistraldashboard import api
|
2015-07-15 15:05:08 +08:00
|
|
|
from mistraldashboard.workbooks import forms as mistral_forms
|
2016-09-08 15:25:30 +07:00
|
|
|
from mistraldashboard.workbooks import tables as mistral_tables
|
2014-06-10 18:41:02 +07:00
|
|
|
|
|
|
|
|
|
|
|
class IndexView(tables.DataTableView):
|
2016-09-08 15:25:30 +07:00
|
|
|
table_class = mistral_tables.WorkbooksTable
|
2014-06-10 18:41:02 +07:00
|
|
|
template_name = 'mistral/workbooks/index.html'
|
|
|
|
|
|
|
|
def get_data(self):
|
2015-07-03 18:00:51 +08:00
|
|
|
return api.workbook_list(self.request)
|
2015-07-09 23:30:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DetailView(generic.TemplateView):
|
|
|
|
template_name = 'mistral/workbooks/detail.html'
|
|
|
|
page_title = _("Workbook Definition")
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(DetailView, self).get_context_data(**kwargs)
|
|
|
|
workbook = self.get_data(self.request, **kwargs)
|
2016-11-23 10:35:46 +00:00
|
|
|
breadcrumb = [(workbook.name, reverse(
|
|
|
|
'horizon:mistral:workbooks:detail',
|
|
|
|
args=[workbook.name]
|
|
|
|
))]
|
|
|
|
|
|
|
|
context["custom_breadcrumb"] = breadcrumb
|
2015-07-09 23:30:57 +08:00
|
|
|
context['definition'] = workbook.definition
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get_data(self, request, **kwargs):
|
|
|
|
try:
|
|
|
|
workbook_name = kwargs['workbook_name']
|
|
|
|
workbook = api.workbook_get(request, workbook_name)
|
|
|
|
except Exception:
|
|
|
|
msg = _('Unable to get workbook "%s".') % workbook_name
|
|
|
|
redirect = reverse('horizon:mistral:workbooks:index')
|
|
|
|
exceptions.handle(self.request, msg, redirect=redirect)
|
|
|
|
|
|
|
|
return workbook
|
2015-07-15 15:05:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SelectDefinitionView(forms.ModalFormView):
|
|
|
|
template_name = 'mistral/workbooks/select_definition.html'
|
2015-09-27 10:02:29 +05:30
|
|
|
modal_header = _("Create Workbook")
|
2015-07-15 15:05:08 +08:00
|
|
|
form_id = "select_definition"
|
|
|
|
form_class = mistral_forms.DefinitionForm
|
2017-03-31 12:24:01 +05:30
|
|
|
submit_label = _("Validate")
|
2015-07-15 15:05:08 +08:00
|
|
|
submit_url = reverse_lazy("horizon:mistral:workbooks:select_definition")
|
|
|
|
success_url = reverse_lazy('horizon:mistral:workbooks:create')
|
|
|
|
page_title = _("Select Definition")
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(SelectDefinitionView, self).get_form_kwargs()
|
|
|
|
kwargs['next_view'] = CreateView
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
2015-07-20 16:42:15 +08:00
|
|
|
class ChangeDefinitionView(SelectDefinitionView):
|
2015-09-27 10:02:29 +05:30
|
|
|
modal_header = _("Update Workbook")
|
2015-07-20 16:42:15 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2015-07-15 15:05:08 +08:00
|
|
|
class CreateView(forms.ModalFormView):
|
|
|
|
template_name = 'mistral/workbooks/create.html'
|
|
|
|
modal_header = _("Create Workbook")
|
|
|
|
form_id = "create_workbook"
|
|
|
|
form_class = mistral_forms.CreateForm
|
|
|
|
submit_label = _("Create")
|
|
|
|
submit_url = reverse_lazy("horizon:mistral:workbooks:create")
|
|
|
|
success_url = reverse_lazy('horizon:mistral:workbooks:index')
|
|
|
|
page_title = _("Create Workbook")
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
initial = {}
|
|
|
|
|
|
|
|
if 'definition' in self.kwargs:
|
|
|
|
initial['definition'] = self.kwargs['definition']
|
|
|
|
|
|
|
|
return initial
|
2015-07-20 16:42:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
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")
|