Browse Source

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 years ago
parent
commit
b42b2c4f25
2 changed files with 28 additions and 7 deletions
  1. 25
    6
      mistraldashboard/workflows/forms.py
  2. 3
    1
      mistraldashboard/workflows/views.py

+ 25
- 6
mistraldashboard/workflows/forms.py View File

@@ -30,21 +30,40 @@ class ExecuteForm(forms.SelfHandlingForm):
30 30
         required=True,
31 31
         widget=forms.TextInput(attrs={'readonly': 'readonly'})
32 32
     )
33
-    workflow_input = forms.CharField(
34
-        label=_("Input"),
35
-        required=False,
36
-        initial="{}",
37
-        widget=forms.widgets.Textarea()
38
-    )
39 33
     task_name = forms.CharField(
40 34
         label=_("Task name"),
41 35
         required=False,
42 36
         widget=forms.TextInput()
43 37
     )
44 38
 
39
+    def __init__(self, *args, **kwargs):
40
+        super(ExecuteForm, self).__init__(*args, **kwargs)
41
+        self._generate_parameter_fields(kwargs["initial"]["parameter_list"])
42
+
43
+    def _generate_parameter_fields(self, list):
44
+        self.workflow_parameters = []
45
+        for entry in list.split(","):
46
+            label, _, default = entry.partition("=")
47
+            label = label.strip()
48
+            self.workflow_parameters.append(label)
49
+            if default == "None":
50
+                default = None
51
+                required = False
52
+            else:
53
+                required = True
54
+            self.fields[label] = forms.CharField(label=label,
55
+                                                 required=required,
56
+                                                 initial=default)
57
+
45 58
     def handle(self, request, data):
46 59
         try:
47 60
             data['workflow_identifier'] = data.pop('workflow_name')
61
+            data['workflow_input'] = {}
62
+            for param in self.workflow_parameters:
63
+                value = data.pop(param)
64
+                if value == "":
65
+                    value = None
66
+                data['workflow_input'][param] = value
48 67
             ex = api.execution_create(request, **data)
49 68
 
50 69
             msg = _('Execution has been created with id "%s".') % ex.id

+ 3
- 1
mistraldashboard/workflows/views.py View File

@@ -107,7 +107,9 @@ class ExecuteView(forms.ModalFormView):
107 107
         return context
108 108
 
109 109
     def get_initial(self, **kwargs):
110
-        return {'workflow_name': self.kwargs['workflow_name']}
110
+        workflow = get_single_data(self.request, self.kwargs['workflow_name'])
111
+        return {'workflow_name': self.kwargs['workflow_name'],
112
+                'parameter_list': workflow.input}
111 113
 
112 114
 
113 115
 class SelectDefinitionView(forms.ModalFormView):

Loading…
Cancel
Save