aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/views.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sbergeron@iol.unh.edu>2019-06-06 12:45:32 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2019-06-12 11:39:59 -0400
commitec2f0d1340d0548aedc5773788e241d1558fa1ed (patch)
tree45959a60d910a8d76e7cfc7130a972356245e8ff /src/workflow/views.py
parent48e42996ef463ca03664fbeafa047b1338998686 (diff)
redirect to booking detail on creation
Change-Id: I4e27f6a4a64314639b9ac83750b5b6add069399b Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
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):