aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/workflow/views.py')
-rw-r--r--src/workflow/views.py32
1 files changed, 22 insertions, 10 deletions
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):