1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
12 from django.shortcuts import get_object_or_404
13 from django.views.generic import TemplateView
14 from django.shortcuts import render
15 from django.http import HttpResponseRedirect
17 from account.models import Lab
19 from resource_inventory.models import Image, HostProfile
20 from workflow.views import create_session
21 from workflow.workflow_manager import ManagerTracker
24 def lab_list_view(request):
25 labs = Lab.objects.all()
26 context = {"labs": labs}
28 return render(request, "dashboard/lab_list.html", context)
31 def lab_detail_view(request, lab_name):
33 if request.user.is_authenticated:
36 lab = get_object_or_404(Lab, name=lab_name)
38 images = Image.objects.filter(from_lab=lab).filter(public=True)
40 images = images | Image.objects.filter(from_lab=lab).filter(owner=user)
44 "dashboard/lab_detail.html",
46 'title': "Lab Overview",
48 'hostprofiles': lab.hostprofiles.all(),
54 def host_profile_detail_view(request):
58 "dashboard/host_profile_detail.html",
60 'title': "Host Types",
65 def landing_view(request):
67 manager_detected = False
68 if 'manager_session' in request.session:
71 manager = ManagerTracker.managers[request.session['manager_session']]
76 if manager is not None:
77 # no manager detected, don't display continue button
78 manager_detected = True
80 if request.method == 'GET':
81 return render(request, 'dashboard/landing.html', {'manager': manager_detected, 'title': "Welcome to the Lab as a Service Dashboard"})
83 if request.method == 'POST':
85 create = request.POST['create']
87 if manager is not None:
90 mgr_uuid = create_session(create, request=request,)
91 request.session['manager_session'] = mgr_uuid
92 return HttpResponseRedirect('/wf/')
98 class LandingView(TemplateView):
99 template_name = "dashboard/landing.html"
101 def get_context_data(self, **kwargs):
102 context = super(LandingView, self).get_context_data(**kwargs)
106 for host_profile in HostProfile.objects.all():
107 name = host_profile.name
108 description = host_profile.description
109 in_labs = host_profile.labs
111 interfaces = host_profile.interfaceprofile
112 storage = host_profile.storageprofile
113 cpu = host_profile.cpuprofile
114 ram = host_profile.ramprofile
116 host = (name, description, in_labs, interfaces, storage, cpu, ram)
119 context.update({'hosts': hosts})