1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from django.http import HttpResponse, HttpRequest, HttpResponseGone
12 from django.urls import reverse
13 from django.shortcuts import render, redirect
14 from django import forms
18 from workflow.forms import *
19 from workflow.workflow_manager import *
22 logger = logging.getLogger(__name__)
25 def attempt_auth(request):
27 manager = ManagerTracker.managers[request.session['manager_session']]
34 def delete_session(request):
36 manager = ManagerTracker.managers[request.session['manager_session']]
37 del ManagerTracker.managers[request.session['manager_session']]
38 return HttpResponse('')
42 def step_view(request):
43 manager = attempt_auth(request)
45 #no manager found, redirect to "lost" page
46 return no_workflow(request)
47 if request.GET.get('step') is not None:
48 manager.goto(int(request.GET.get('step')))
49 return manager.render(request)
51 def manager_view(request):
52 manager = attempt_auth(request)
55 return HttpResponseGone("No session found that relates to current request")
57 if request.method == 'GET': #no need for this statement if only intercepting post requests
59 #return general context for viewport page
60 return manager.status(request)
62 if request.method == 'POST':
63 if request.POST.get('add') is not None:
64 logger.debug("add found")
66 if 'target' in request.POST:
67 target_id=int(request.POST.get('target'))
68 manager.add_workflow(workflow_type=int(request.POST.get('add')), target_id=target_id)
69 elif request.POST.get('edit') is not None and request.POST.get('edit_id') is not None:
70 logger.debug("edit found")
71 manager.add_workflow(workflow_type=request.POST.get('edit'), edit_object=int(request.POST.get('edit_id')))
72 elif request.POST.get('cancel') is not None:
73 mgr = ManagerTracker.managers[request.session['manager_session']]
74 del ManagerTracker.managers[request.session['manager_session']]
77 return manager.status(request)
79 def viewport_view(request):
80 if not request.user.is_authenticated:
83 manager = attempt_auth(request)
85 return no_workflow(request)
87 if request.method == 'GET':
88 return render(request, 'workflow/viewport-base.html')
92 def create_session(wf_type, request):
94 smgr = SessionManager(request=request)
95 smgr.add_workflow(workflow_type=wf, target_id=request.POST.get("target"))
96 manager_uuid = uuid.uuid4().hex
97 ManagerTracker.getInstance().managers[manager_uuid] = smgr
101 def no_workflow(request):
103 logger.debug("There is no active workflow")
105 return render(request, 'workflow/no_workflow.html', {'title': "Not Found"})
108 return render(request, "dashboard/login.html", {'title': 'Authentication Required'})