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.py101
1 files changed, 34 insertions, 67 deletions
diff --git a/src/workflow/views.py b/src/workflow/views.py
index 7ed9031..9ff444d 100644
--- a/src/workflow/views.py
+++ b/src/workflow/views.py
@@ -8,14 +8,12 @@
##############################################################################
-from django.http import HttpResponseGone, JsonResponse
+from django.http import HttpResponse
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__)
@@ -31,77 +29,38 @@ 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):
+def remove_workflow(request):
manager = attempt_auth(request)
if not manager:
- return HttpResponseGone("No session found that relates to current request")
+ return no_workflow(request)
- not_last_workflow, result = manager.pop_workflow()
+ has_more_workflows, result = manager.pop_workflow()
- if not_last_workflow: # this was not the last workflow, so don't redirect away
- return JsonResponse({})
- else:
+ if not has_more_workflows: # this was the last workflow, so delete the reference to it in the tracker
del ManagerTracker.managers[request.session['manager_session']]
- return JsonResponse(get_redirect_response(result))
+ return manager.render(request)
-def step_view(request):
+def add_workflow(request):
manager = attempt_auth(request)
if not manager:
- # no manager found, redirect to "lost" page
return no_workflow(request)
- if request.GET.get('step') is not None:
- if request.GET.get('step') == 'next':
- manager.go_next()
- elif request.GET.get('step') == 'prev':
- manager.go_prev()
- else:
- raise Exception("requested action for new step had malformed contents: " + request.GET.get('step'))
- return manager.render(request)
+ try:
+ workflow_type = int(request.POST.get('workflow_type'))
+ except ValueError:
+ return HttpResponse(status=400)
+
+ manager.add_workflow(workflow_type=workflow_type)
+ return manager.render(request) # do we want this?
def manager_view(request):
manager = attempt_auth(request)
-
if not manager:
- return HttpResponseGone("No session found that relates to current request")
-
- if request.method == 'GET':
- # no need for this statement if only intercepting post requests
-
- # return general context for viewport page
- return manager.status(request)
-
- if request.method == 'POST':
- if request.POST.get('add') is not None:
- logger.debug("add found")
- target_id = None
- if 'target' in request.POST:
- target_id = int(request.POST.get('target'))
- manager.add_workflow(workflow_type=int(request.POST.get('add')), target_id=target_id)
- elif request.POST.get('edit') is not None and request.POST.get('edit_id') is not None:
- logger.debug("edit found")
- manager.add_workflow(workflow_type=request.POST.get('edit'), edit_object=int(request.POST.get('edit_id')))
- elif request.POST.get('cancel') is not None:
- if not manager.pop_workflow():
- del ManagerTracker.managers[request.session['manager_session']]
+ return no_workflow(request)
- return manager.status(request)
+ return manager.handle_request(request)
def viewport_view(request):
@@ -112,16 +71,27 @@ def viewport_view(request):
if manager is None:
return no_workflow(request)
- if request.method == 'GET':
- return render(request, 'workflow/viewport-base.html')
- else:
- pass
+ if request.method != 'GET':
+ return HttpResponse(status=405)
+ return render(request, 'workflow/viewport-base.html')
+
+
+def create_workflow(request):
+ if request.method != 'POST':
+ return HttpResponse(status=405)
+ workflow_type = request.POST.get('workflow_type')
+ try:
+ workflow_type = int(workflow_type)
+ except Exception:
+ return HttpResponse(status=400)
+ mgr_uuid = create_session(workflow_type, request=request,)
+ request.session['manager_session'] = mgr_uuid
+ return HttpResponse()
def create_session(wf_type, request):
- wf = int(wf_type)
smgr = SessionManager(request=request)
- smgr.add_workflow(workflow_type=wf, target_id=request.POST.get("target"))
+ smgr.add_workflow(workflow_type=wf_type, target_id=request.POST.get("target"))
manager_uuid = uuid.uuid4().hex
ManagerTracker.getInstance().managers[manager_uuid] = smgr
@@ -129,10 +99,7 @@ def create_session(wf_type, request):
def no_workflow(request):
-
- logger.debug("There is no active workflow")
-
- return render(request, 'workflow/no_workflow.html', {'title': "Not Found"})
+ return render(request, 'workflow/no_workflow.html', {'title': "Not Found"}, status=404)
def login(request):