Selaa lähdekoodia

Expand parameter list for workflow execution

Currently one generic field "Input" is shown when executing a workflow.
This patch checks list of parameters for a workflow and generates
a Django form according to the results, also prefilling any default
value.

In case default value for a parameter is none, field is not marked
as required.

Closes-bug: #1712322
Change-Id: I702d2b196f87e46bc39da00cad509d2f08f5d24c
tags/6.0.0.0b3
Mateusz Kowalski 2 vuotta sitten
vanhempi
commit
b42b2c4f25
2 muutettua tiedostoa jossa 28 lisäystä ja 7 poistoa
  1. 25
    6
      mistraldashboard/workflows/forms.py
  2. 3
    1
      mistraldashboard/workflows/views.py

+ 25
- 6
mistraldashboard/workflows/forms.py Näytä tiedosto

@@ -30,21 +30,40 @@ class ExecuteForm(forms.SelfHandlingForm):
required=True,
widget=forms.TextInput(attrs={'readonly': 'readonly'})
)
workflow_input = forms.CharField(
label=_("Input"),
required=False,
initial="{}",
widget=forms.widgets.Textarea()
)
task_name = forms.CharField(
label=_("Task name"),
required=False,
widget=forms.TextInput()
)

def __init__(self, *args, **kwargs):
super(ExecuteForm, self).__init__(*args, **kwargs)
self._generate_parameter_fields(kwargs["initial"]["parameter_list"])

def _generate_parameter_fields(self, list):
self.workflow_parameters = []
for entry in list.split(","):
label, _, default = entry.partition("=")
label = label.strip()
self.workflow_parameters.append(label)
if default == "None":
default = None
required = False
else:
required = True
self.fields[label] = forms.CharField(label=label,
required=required,
initial=default)

def handle(self, request, data):
try:
data['workflow_identifier'] = data.pop('workflow_name')
data['workflow_input'] = {}
for param in self.workflow_parameters:
value = data.pop(param)
if value == "":
value = None
data['workflow_input'][param] = value
ex = api.execution_create(request, **data)

msg = _('Execution has been created with id "%s".') % ex.id

+ 3
- 1
mistraldashboard/workflows/views.py Näytä tiedosto

@@ -107,7 +107,9 @@ class ExecuteView(forms.ModalFormView):
return context

def get_initial(self, **kwargs):
return {'workflow_name': self.kwargs['workflow_name']}
workflow = get_single_data(self.request, self.kwargs['workflow_name'])
return {'workflow_name': self.kwargs['workflow_name'],
'parameter_list': workflow.input}


class SelectDefinitionView(forms.ModalFormView):

Loading…
Peruuta
Tallenna