aboutsummaryrefslogtreecommitdiffstats
path: root/src/dashboard/views.py
blob: 498bd9d3d74e4ef8580dbbaa8950f78ac2a8c071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##############################################################################
# Copyright (c) 2016 Max Breitenfeldt and others.
# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################


from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView
from django.shortcuts import render

from account.models import Lab

from resource_inventory.models import Image, ResourceProfile
from workflow.workflow_manager import ManagerTracker


def lab_list_view(request):
    labs = Lab.objects.all()
    context = {"labs": labs, 'title': 'Labs'}

    return render(request, "dashboard/lab_list.html", context)


def lab_detail_view(request, lab_name):
    user = None
    if request.user.is_authenticated:
        user = request.user

    lab = get_object_or_404(Lab, name=lab_name)

    images = Image.objects.filter(from_lab=lab).filter(public=True)
    if user:
        images = images | Image.objects.filter(from_lab=lab).filter(owner=user)

    return render(
        request,
        "dashboard/lab_detail.html",
        {
            'title': "Lab Overview",
            'lab': lab,
            'hostprofiles': lab.hostprofiles.all(),
            'images': images,
        }
    )


def host_profile_detail_view(request):

    return render(
        request,
        "dashboard/host_profile_detail.html",
        {
            'title': "Host Types",
        }
    )


def landing_view(request):
    manager = ManagerTracker.managers.get(request.session.get('manager_session'))
    return render(
        request,
        'dashboard/landing.html',
        {
            'manager': manager is not None,
            'title': "Welcome to the Lab as a Service Dashboard"
        }
    )


class LandingView(TemplateView):
    template_name = "dashboard/landing.html"

    def get_context_data(self, **kwargs):
        context = super(LandingView, self).get_context_data(**kwargs)

        hosts = []

        for host_profile in ResourceProfile.objects.all():
            name = host_profile.name
            description = host_profile.description
            in_labs = host_profile.labs

            interfaces = host_profile.interfaceprofile
            storage = host_profile.storageprofile
            cpu = host_profile.cpuprofile
            ram = host_profile.ramprofile

            host = (name, description, in_labs, interfaces, storage, cpu, ram)
            hosts.append(host)

        context.update({'hosts': hosts})

        return context