Merge "UI: Execution update - table actions"
This commit is contained in:
commit
9eb73b650b
@ -66,6 +66,23 @@ def execution_get(request, execution_id):
|
||||
return mistralclient(request).executions.get(execution_id)
|
||||
|
||||
|
||||
def execution_update(request, execution_id, field, value):
|
||||
|
||||
"""update specific execution field, either state or description
|
||||
|
||||
:param request: Request data
|
||||
:param execution_id: Execution ID
|
||||
:param field: flag - either Execution state or description
|
||||
:param value: new update value
|
||||
"""
|
||||
if field == "state":
|
||||
return mistralclient(request).\
|
||||
executions.update(execution_id, value)
|
||||
elif field == "description":
|
||||
return mistralclient(request).\
|
||||
executions.update(execution_id, None, value)
|
||||
|
||||
|
||||
def execution_delete(request, execution_name):
|
||||
"""Delete execution.
|
||||
|
||||
|
@ -22,7 +22,8 @@ TYPES = {
|
||||
'SUCCESS': 'label-success',
|
||||
'ERROR': 'label-danger',
|
||||
'DELAYED': 'label-default',
|
||||
'RUNNING': 'label-info'
|
||||
'RUNNING': 'label-info',
|
||||
'PAUSED': 'label-warning'
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,6 +45,91 @@ class DeleteExecution(tables.DeleteAction):
|
||||
api.execution_delete(request, execution_name)
|
||||
|
||||
|
||||
class CancelExecution(tables.BatchAction):
|
||||
name = "cancel execution"
|
||||
classes = ("btn-danger",)
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Cancel Execution",
|
||||
u"Cancel Executions",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Canceled Execution",
|
||||
u"Canceled Executions",
|
||||
count
|
||||
)
|
||||
|
||||
def allowed(self, request, instance):
|
||||
if instance.state == "RUNNING":
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, obj_id):
|
||||
api.execution_update(request, obj_id, "state", "ERROR")
|
||||
|
||||
|
||||
class PauseExecution(tables.BatchAction):
|
||||
name = "pause execution"
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Pause Execution",
|
||||
u"Pause Executions",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Paused Execution",
|
||||
u"Paused Executions",
|
||||
count
|
||||
)
|
||||
|
||||
def allowed(self, request, instance):
|
||||
if instance.state == "RUNNING":
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, obj_id):
|
||||
api.execution_update(request, obj_id, "state", "PAUSED")
|
||||
|
||||
|
||||
class ResumeExecution(tables.BatchAction):
|
||||
name = "resume execution"
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Resume Execution",
|
||||
u"Resume Executions",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Resumed Execution",
|
||||
u"Resumed Executions",
|
||||
count
|
||||
)
|
||||
|
||||
def allowed(self, request, instance):
|
||||
if instance.state == "PAUSED":
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, obj_id):
|
||||
api.execution_update(request, obj_id, "state", "RUNNING")
|
||||
|
||||
|
||||
class ExecutionsTable(tables.DataTable):
|
||||
id = tables.Column(
|
||||
"id",
|
||||
@ -100,4 +185,5 @@ class ExecutionsTable(tables.DataTable):
|
||||
name = "executions"
|
||||
verbose_name = _("Executions")
|
||||
table_actions = (DeleteExecution, tables.FilterAction)
|
||||
row_actions = (DeleteExecution,)
|
||||
row_actions = (DeleteExecution, PauseExecution,
|
||||
CancelExecution, ResumeExecution, DeleteExecution)
|
||||
|
@ -87,7 +87,6 @@ class DetailView(generic.TemplateView):
|
||||
context = super(DetailView, self).get_context_data(**kwargs)
|
||||
task = {}
|
||||
execution = {}
|
||||
|
||||
if 'caller' in kwargs:
|
||||
if kwargs['caller'] == 'task':
|
||||
kwargs['task_id'] = kwargs['execution_id']
|
||||
@ -135,20 +134,18 @@ class CodeView(forms.ModalFormView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CodeView, self).get_context_data(**kwargs)
|
||||
column = self.kwargs['column']
|
||||
execution = get_single_data(
|
||||
self.request,
|
||||
self.kwargs['execution_id'],
|
||||
)
|
||||
column = self.kwargs['column']
|
||||
io = {}
|
||||
|
||||
if column == 'input':
|
||||
io['name'] = _('Input')
|
||||
io['value'] = execution.input = prettyprint(execution.input)
|
||||
elif column == 'output':
|
||||
io['name'] = _('Output')
|
||||
io['value'] = execution.output = prettyprint(execution.output)
|
||||
|
||||
context['io'] = io
|
||||
|
||||
return context
|
||||
|
Loading…
Reference in New Issue
Block a user