From a0262daa0554126e86204cf10d9a8372bf0b829f Mon Sep 17 00:00:00 2001 From: Gal Margalit Date: Mon, 19 Dec 2016 16:10:30 +0000 Subject: [PATCH] Workflow list - added missing fields Screenshots: http://pho.to/AZ4L6 Change-Id: I1947e0c4c65eac2204354ac753275ee1016f68f8 --- .../default/templates/default/_preprint.html | 3 + mistraldashboard/default/utils.py | 6 ++ mistraldashboard/workflows/tables.py | 24 +++++++- mistraldashboard/workflows/urls.py | 4 ++ mistraldashboard/workflows/views.py | 58 ++++++++++++++----- 5 files changed, 78 insertions(+), 17 deletions(-) create mode 100644 mistraldashboard/default/templates/default/_preprint.html diff --git a/mistraldashboard/default/templates/default/_preprint.html b/mistraldashboard/default/templates/default/_preprint.html new file mode 100644 index 0000000..df2d085 --- /dev/null +++ b/mistraldashboard/default/templates/default/_preprint.html @@ -0,0 +1,3 @@ +
+    {{ pre }}
+
diff --git a/mistraldashboard/default/utils.py b/mistraldashboard/default/utils.py index 44b2a48..6cc0d22 100644 --- a/mistraldashboard/default/utils.py +++ b/mistraldashboard/default/utils.py @@ -71,6 +71,12 @@ def prettyprint(x): {"full": full, "short": short}) +def htmlpre(pre): + + return render_to_string("mistral/default/_preprint.html", + {"pre": pre}) + + def convert_empty_string_to_none(str): """Returns None if given string is empty. diff --git a/mistraldashboard/workflows/tables.py b/mistraldashboard/workflows/tables.py index 1c0695d..c100a62 100644 --- a/mistraldashboard/workflows/tables.py +++ b/mistraldashboard/workflows/tables.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from django.template.defaultfilters import title from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy @@ -69,7 +70,7 @@ def tags_to_string(workflow): return ', '.join(workflow.tags) if workflow.tags else None -def cut(workflow, length=100): +def cut(workflow, length=50): inputs = workflow.input if inputs and len(inputs) > length: @@ -84,13 +85,32 @@ class WorkflowsTable(tables.DataTable): verbose_name=_("Name"), link="horizon:mistral:workflows:detail" ) + id = tables.Column( + "id", + verbose_name=_("ID"), + ) + scope = tables.Column( + "scope", + verbose_name=_("Scope"), + filters=[title], + ) + definition = tables.Column( + "", + verbose_name=_("Definition"), + empty_value=_("View"), + link="horizon:mistral:workflows:definition", + link_classes=("ajax-modal",) + ) + tags = tables.Column( tags_to_string, verbose_name=_("Tags") ) inputs = tables.Column( cut, - verbose_name=_("Input") + verbose_name=_("Input"), + link="horizon:mistral:workflows:input", + link_classes=("ajax-modal",) ) created = tables.Column( "created_at", diff --git a/mistraldashboard/workflows/urls.py b/mistraldashboard/workflows/urls.py index 4db21a6..4ed4117 100644 --- a/mistraldashboard/workflows/urls.py +++ b/mistraldashboard/workflows/urls.py @@ -32,4 +32,8 @@ urlpatterns = [ 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'), + url(WORKFLOWS % 'definition', views.CodeView.as_view(), + {'column': 'definition'}, name='definition'), + url(WORKFLOWS % 'input', views.CodeView.as_view(), + {'column': 'input'}, name='input'), ] diff --git a/mistraldashboard/workflows/views.py b/mistraldashboard/workflows/views.py index 4b979cf..7406125 100644 --- a/mistraldashboard/workflows/views.py +++ b/mistraldashboard/workflows/views.py @@ -24,10 +24,23 @@ from horizon import forms from horizon import tables from mistraldashboard import api -from mistraldashboard.workflows import forms as mistral_forms +from mistraldashboard.default import utils +from mistraldashboard import forms as mistral_forms +from mistraldashboard.workflows import forms as workflow_forms from mistraldashboard.workflows import tables as workflows_tables +def get_single_data(request, workflow_name): + try: + workflow = api.workflow_get(request, workflow_name) + except Exception: + msg = _('Unable to get workflow "%s".') % workflow_name + redirect = reverse('horizon:mistral:workflows:index') + exceptions.handle(request, msg, redirect=redirect) + + return workflow + + class IndexView(tables.DataTableView): table_class = workflows_tables.WorkflowsTable template_name = 'mistral/workflows/index.html' @@ -42,7 +55,7 @@ class DetailView(generic.TemplateView): def get_context_data(self, **kwargs): context = super(DetailView, self).get_context_data(**kwargs) - workflow = self.get_data(self.request, **kwargs) + workflow = get_single_data(self.request, kwargs['workflow_name']) breadcrumb = [(workflow.name, reverse( 'horizon:mistral:workflows:detail', args=[workflow.name] @@ -56,20 +69,35 @@ class DetailView(generic.TemplateView): return context - def get_data(self, request, **kwargs): - try: - workflow_name = kwargs['workflow_name'] - workflow = api.workflow_get(request, workflow_name) - except Exception: - msg = _('Unable to get workflow "%s".') % workflow_name - redirect = reverse('horizon:mistral:workflows:index') - exceptions.handle(self.request, msg, redirect=redirect) - return workflow +class CodeView(forms.ModalFormView): + template_name = 'mistral/default/code.html' + modal_header = _("Code view") + form_id = "code_view" + form_class = mistral_forms.EmptyForm + cancel_label = "OK" + cancel_url = reverse_lazy("horizon:mistral:workflows:index") + page_title = _("Code view") + + def get_context_data(self, **kwargs): + context = super(CodeView, self).get_context_data(**kwargs) + workflow = get_single_data(self.request, self.kwargs['workflow_name']) + io = {} + column = self.kwargs['column'] + if column == 'definition': + io['name'] = _('Workflow Definition') + io['value'] = utils.htmlpre(workflow.definition) + elif column == 'input': + io['name'] = _('Workflow Input') + io['value'] = workflow.input + + context['io'] = io + + return context class ExecuteView(forms.ModalFormView): - form_class = mistral_forms.ExecuteForm + form_class = workflow_forms.ExecuteForm template_name = 'mistral/workflows/execute.html' success_url = reverse_lazy("horizon:mistral:executions:index") @@ -88,7 +116,7 @@ class SelectDefinitionView(forms.ModalFormView): template_name = 'mistral/workflows/select_definition.html' modal_header = _("Create Workflow") form_id = "select_definition" - form_class = mistral_forms.DefinitionForm + form_class = workflow_forms.DefinitionForm submit_label = _("Next") submit_url = reverse_lazy("horizon:mistral:workflows:select_definition") success_url = reverse_lazy('horizon:mistral:workflows:create') @@ -118,7 +146,7 @@ class CreateView(forms.ModalFormView): template_name = 'mistral/workflows/create.html' modal_header = _("Create Workflow") form_id = "create_workflow" - form_class = mistral_forms.CreateForm + form_class = workflow_forms.CreateForm submit_label = _("Create") submit_url = reverse_lazy("horizon:mistral:workflows:create") success_url = reverse_lazy('horizon:mistral:workflows:index') @@ -137,7 +165,7 @@ class UpdateView(CreateView): template_name = 'mistral/workflows/update.html' modal_header = _("Update Workflow") form_id = "update_workflow" - form_class = mistral_forms.UpdateForm + form_class = workflow_forms.UpdateForm submit_label = _("Update") submit_url = reverse_lazy("horizon:mistral:workflows:update") page_title = _("Update Workflow")