diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/templates/workflow/confirm.html | 13 | ||||
-rw-r--r-- | src/templates/workflow/exit_redirect.html | 6 | ||||
-rw-r--r-- | src/workflow/models.py | 10 | ||||
-rw-r--r-- | src/workflow/views.py | 32 | ||||
-rw-r--r-- | src/workflow/workflow_manager.py | 18 |
5 files changed, 53 insertions, 26 deletions
diff --git a/src/templates/workflow/confirm.html b/src/templates/workflow/confirm.html index 2510204..a234a71 100644 --- a/src/templates/workflow/confirm.html +++ b/src/templates/workflow/confirm.html @@ -58,6 +58,17 @@ <script> var select = document.getElementById("id_confirm"); + function processResponseText(json) + { + var dict = JSON.parse(json); + + if( !dict["redir_url"] ) { + window.top.refresh_iframe(); + } else { + top.window.location.href = dict["redir_url"]; + } + } + function delete_manager() { var form = $("#manager_delete_form"); @@ -67,7 +78,7 @@ req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.onerror = function() { alert("problem with cleaning up session"); } req.onreadystatechange = function() { if(req.readyState === 4 ) { - window.top.refresh_iframe(); + processResponseText(req.responseText); }} req.send(formData); } diff --git a/src/templates/workflow/exit_redirect.html b/src/templates/workflow/exit_redirect.html deleted file mode 100644 index b08df78..0000000 --- a/src/templates/workflow/exit_redirect.html +++ /dev/null @@ -1,6 +0,0 @@ -<!DOCTYPE html> -<html> - <script> - top.window.location.href='/'; - </script> -</html> diff --git a/src/workflow/models.py b/src/workflow/models.py index 43a9bf2..6c6bd9a 100644 --- a/src/workflow/models.py +++ b/src/workflow/models.py @@ -490,6 +490,9 @@ class Repository(): pass JobFactory.makeSnapshotTask(image, booking, host) + self.el[self.RESULT] = image + self.el[self.HAS_RESULT] = True + def make_generic_resource_bundle(self): owner = self.el[self.SESSION_USER] if self.GRESOURCE_BUNDLE_MODELS in self.el: @@ -556,6 +559,7 @@ class Repository(): return "GRB no models given. CODE:0x0001" self.el[self.RESULT] = bundle + self.el[self.HAS_RESULT] = True return False def make_software_config_bundle(self): @@ -667,6 +671,9 @@ class Repository(): except Exception as e: return "BOOK, saving booking generated exception: " + str(e) + " CODE:0x0016" + self.el[self.RESULT] = booking + self.el[self.HAS_RESULT] = True + def make_opnfv_config(self): opnfv_models = self.el[self.OPNFV_MODELS] config_bundle = self.el[self.SELECTED_CONFIG_BUNDLE] @@ -713,10 +720,13 @@ class Repository(): ) self.el[self.RESULT] = opnfv_config + self.el[self.HAS_RESULT] = True def __init__(self): self.el = {} self.el[self.CONFIRMATION] = {} self.el["active_step"] = 0 + self.el[self.HAS_RESULT] = False + self.el[self.RESULT] = None self.get_history = {} self.put_history = {} diff --git a/src/workflow/views.py b/src/workflow/views.py index f2e37ef..7ed9031 100644 --- a/src/workflow/views.py +++ b/src/workflow/views.py @@ -8,12 +8,14 @@ ############################################################################## -from django.http import HttpResponse, HttpResponseGone +from django.http import HttpResponseGone, JsonResponse from django.shortcuts import render +from django.urls import reverse import uuid from workflow.workflow_manager import ManagerTracker, SessionManager +from booking.models import Booking import logging logger = logging.getLogger(__name__) @@ -29,23 +31,33 @@ def attempt_auth(request): return None +def get_redirect_response(result): + if not result: + return {} + + # need to get type of result, and switch on the type + # since has_result, result must be populated with a valid object + if isinstance(result, Booking): + return { + 'redir_url': reverse('booking:booking_detail', kwargs={'booking_id': result.id}) + } + else: + return {} + + def delete_session(request): manager = attempt_auth(request) if not manager: return HttpResponseGone("No session found that relates to current request") - if manager.pop_workflow(): - return HttpResponse('') - else: - del ManagerTracker.managers[request.session['manager_session']] - return render(request, 'workflow/exit_redirect.html') + not_last_workflow, result = manager.pop_workflow() - try: + if not_last_workflow: # this was not the last workflow, so don't redirect away + return JsonResponse({}) + else: del ManagerTracker.managers[request.session['manager_session']] - return HttpResponse('') - except Exception: - return None + return JsonResponse(get_redirect_response(result)) def step_view(request): diff --git a/src/workflow/workflow_manager.py b/src/workflow/workflow_manager.py index 525aa6f..26f926e 100644 --- a/src/workflow/workflow_manager.py +++ b/src/workflow/workflow_manager.py @@ -64,15 +64,15 @@ class SessionManager(): ) def pop_workflow(self): - if(len(self.workflows) <= 1): - return False - - if self.workflows[-1].repository.el[self.workflows[-1].repository.HAS_RESULT]: - key = self.workflows[-1].repository.el[self.workflows[-1].repository.RESULT_KEY] - result = self.workflows[-1].repository.el[self.workflows[-1].repository.RESULT] - self.workflows[-2].repository.el[key] = result - self.workflows.pop() - return True + multiple_wfs = len(self.workflows) > 1 + if multiple_wfs: + if self.workflows[-1].repository.el[Repository.RESULT]: # move result + key = self.workflows[-1].repository.el[Repository.RESULT_KEY] + result = self.workflows[-1].repository.el[Repository.RESULT] + self.workflows[-2].repository.el[key] = result + self.workflows.pop() + current_repo = self.workflows[-1].repository + return (multiple_wfs, current_repo.el[current_repo.RESULT]) def status(self, request): try: |