aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/workflow_manager.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-07-01 12:55:19 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2019-07-02 10:44:48 -0400
commite3389d42758feef5dad48e0bbcd5a0a3f6af4206 (patch)
tree1976362f474f206bbabf096f211e5fdc3216471f /src/workflow/workflow_manager.py
parent939f90eabd3fd6ac17b0a1a0646962ead88d5e99 (diff)
Refactor Workflow Manager
Refactors wf manager according to: https://jira.opnfv.org/browse/LAAS-31 Change-Id: I72b4b0b808bb77846f44787fdd146f1053c047b5 Signed-off-by: Parker Berberian <pberberian@iol.unh.edu> Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/workflow/workflow_manager.py')
-rw-r--r--src/workflow/workflow_manager.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/workflow/workflow_manager.py b/src/workflow/workflow_manager.py
index 80b8a67..605eee7 100644
--- a/src/workflow/workflow_manager.py
+++ b/src/workflow/workflow_manager.py
@@ -9,6 +9,7 @@
from django.http import JsonResponse
+from django.http.request import QueryDict
from booking.models import Booking
from workflow.workflow_factory import WorkflowFactory
@@ -19,6 +20,7 @@ from resource_inventory.models import (
HostConfiguration,
OPNFVConfig
)
+from workflow.forms import ManagerForm
import logging
logger = logging.getLogger(__name__)
@@ -45,10 +47,7 @@ class SessionManager():
else:
step.disable()
- def add_workflow(self, workflow_type=None, target_id=None, **kwargs):
- if target_id is not None:
- self.prefill_repo(target_id, workflow_type)
-
+ def add_workflow(self, workflow_type=None, **kwargs):
repo = Repository()
if(len(self.workflows) >= 1):
defaults = self.workflows[-1].repository.get_child_defaults()
@@ -75,24 +74,37 @@ class SessionManager():
return (multiple_wfs, current_repo.el[current_repo.RESULT])
def status(self, request):
- try:
- meta_json = []
- for step in self.active_workflow().steps:
- meta_json.append(step.to_json())
- responsejson = {}
- responsejson["steps"] = meta_json
- responsejson["active"] = self.active_workflow().repository.el['active_step']
- responsejson["workflow_count"] = len(self.workflows)
- return JsonResponse(responsejson, safe=False)
- except Exception:
- pass
+ return {
+ "steps": [step.to_json() for step in self.active_workflow().steps],
+ "active": self.active_workflow().repository.el['active_step'],
+ "workflow_count": len(self.workflows)
+ }
+
+ def handle_post(self, request):
+ form = ManagerForm(request.POST)
+ if form.is_valid:
+ self.get_active_step().post(
+ QueryDict(form.cleaned_data['step_form']),
+ user=request.user
+ )
+ # change step
+ if form.cleaned_data['step'] == 'prev':
+ self.go_prev()
+ if form.cleaned_data['step'] == 'next':
+ self.go_next()
+ else:
+ pass # Exception?
+
+ def handle_request(self, request):
+ if request.method == 'POST':
+ self.handle_post(request)
+ return self.render()
def render(self, request, **kwargs):
- # filter out when a step needs to handle post/form data
- # if 'workflow' in post data, this post request was meant for me, not step
- if request.method == 'POST' and request.POST.get('workflow', None) is None:
- return self.active_workflow().steps[self.active_workflow().active_index].post_render(request)
- return self.active_workflow().steps[self.active_workflow().active_index].render(request)
+ return JsonResponse({
+ "meta": self.status(),
+ "content": self.get_active_step().render_to_string(request)
+ })
def post_render(self, request):
return self.active_workflow().steps[self.active_workflow().active_index].post_render(request)