52f8c75e50b1a5abea8a3d5e6f72d8f13643384b
[laas.git] / src / resource_inventory / views.py
1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron, Parker Berberian, and others.
3 #
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 ##############################################################################
9
10
11 from django.views.generic import TemplateView
12 from django.shortcuts import get_object_or_404
13 from django.shortcuts import render
14
15 from resource_inventory.models import ResourceProfile, ResourceQuery
16
17
18 class HostView(TemplateView):
19     template_name = "resource/hosts.html"
20
21     def get_context_data(self, **kwargs):
22         context = super(HostView, self).get_context_data(**kwargs)
23         hosts = ResourceQuery.filter(working=True)
24         context.update({'hosts': hosts, 'title': "Hardware Resources"})
25         return context
26
27
28 def hostprofile_detail_view(request, hostprofile_id):
29     hostprofile = get_object_or_404(ResourceProfile, id=hostprofile_id)
30
31     return render(
32         request,
33         "resource/hostprofile_detail.html",
34         {
35             'title': "Host Type: " + str(hostprofile.name),
36             'hostprofile': hostprofile
37         }
38     )