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.db.models import Q
16 from datetime import datetime
19 from account.models import Lab
20 from booking.models import Booking
22 from resource_inventory.models import Image, ResourceProfile, ResourceQuery
23 from workflow.workflow_manager import ManagerTracker
25 from laas_dashboard import settings
28 def lab_list_view(request):
29 labs = Lab.objects.all()
30 context = {"labs": labs, 'title': 'Labs'}
32 return render(request, "dashboard/lab_list.html", context)
35 def lab_detail_view(request, lab_name):
37 if request.user.is_authenticated:
40 lab = get_object_or_404(Lab, name=lab_name)
42 images = Image.objects.filter(from_lab=lab).filter(public=True)
44 images = images | Image.objects.filter(from_lab=lab).filter(owner=user)
46 hosts = ResourceQuery.filter(lab=lab)
50 "dashboard/lab_detail.html",
52 'title': "Lab Overview",
54 'hostprofiles': ResourceProfile.objects.filter(labs=lab),
61 def host_profile_detail_view(request):
65 "dashboard/host_profile_detail.html",
67 'title': "Host Types",
72 def landing_view(request):
73 manager = ManagerTracker.managers.get(request.session.get('manager_session'))
75 if not user.is_anonymous:
76 bookings = Booking.objects.filter(
77 Q(owner=user) | Q(collaborators=user),
78 end__gte=datetime.now(pytz.utc)
83 LFID = True if settings.AUTH_SETTING == 'LFID' else False
86 'dashboard/landing.html',
88 'manager': manager is not None,
89 'title': "Welcome to the Lab as a Service Dashboard",
96 class LandingView(TemplateView):
97 template_name = "dashboard/landing.html"
99 def get_context_data(self, **kwargs):
100 context = super(LandingView, self).get_context_data(**kwargs)
104 for host_profile in ResourceProfile.objects.all():
105 name = host_profile.name
106 description = host_profile.description
107 in_labs = host_profile.labs
109 interfaces = host_profile.interfaceprofile
110 storage = host_profile.storageprofile
111 cpu = host_profile.cpuprofile
112 ram = host_profile.ramprofile
114 host = (name, description, in_labs, interfaces, storage, cpu, ram)
117 context.update({'hosts': hosts})