diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-08-25 12:10:55 +0200 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2016-08-25 12:10:55 +0200 |
commit | 2a634c9262e7f51a7802b69b9ba51641711f2ad4 (patch) | |
tree | 9243b3f065cc140f862be5bb6f7bc4f06905a309 /pharos-dashboard/dashboard/views.py | |
parent | e040d30e0a61077f2777beba5853103f327ec130 (diff) |
Add a Resource detail view
JIRA: RELENG-12
The resource page contains an utilization diagram, future bookings with
their jira tickets and a list of servers.
Change-Id: I2123ccbe96cde29a56af32b933ebbf6ba2668ed1
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/dashboard/views.py')
-rw-r--r-- | pharos-dashboard/dashboard/views.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/pharos-dashboard/dashboard/views.py b/pharos-dashboard/dashboard/views.py index 56b3a51..ef1845c 100644 --- a/pharos-dashboard/dashboard/views.py +++ b/pharos-dashboard/dashboard/views.py @@ -1,12 +1,12 @@ from datetime import timedelta -from django.contrib.auth.models import User +from django.shortcuts import get_object_or_404 from django.utils import timezone from django.views.generic import TemplateView from booking.models import Booking from dashboard.models import Resource -from jenkins.models import JenkinsSlave, JenkinsStatistic +from jenkins.models import JenkinsSlave class JenkinsSlavesView(TemplateView): @@ -51,25 +51,27 @@ class DevelopmentPodsView(TemplateView): return context +class ResourceView(TemplateView): + template_name = "dashboard/resource.html" + + def get_context_data(self, **kwargs): + resource = get_object_or_404(Resource, id=self.kwargs['resource_id']) + utilization = resource.slave.get_utilization(timedelta(days=7)) + bookings = Booking.objects.filter(resource=resource, end__gt=timezone.now()) + context = super(ResourceView, self).get_context_data(**kwargs) + context.update({'title': str(resource), 'resource': resource, 'utilization': utilization, 'bookings': bookings}) + return context + + class LabOwnerView(TemplateView): - template_name = "dashboard/lab_owner.html" + template_name = "dashboard/resource_all.html" def get_context_data(self, **kwargs): resources = Resource.objects.filter(slave__dev_pod=True) pods = [] for resource in resources: - utilization = {'idle': 0, 'online': 0, 'offline': 0} - # query measurement points for the last week - statistics = JenkinsStatistic.objects.filter(slave=resource.slave, - timestamp__gte=timezone.now() - timedelta( - days=7)) - - utilization['idle'] = statistics.filter(idle=True).count() - utilization['online'] = statistics.filter(online=True).count() - utilization['offline'] = statistics.filter(offline=True).count() - + utilization = resource.slave.get_utilization(timedelta(days=7)) bookings = Booking.objects.filter(resource=resource, end__gt=timezone.now()) - pods.append((resource, utilization, bookings)) context = super(LabOwnerView, self).get_context_data(**kwargs) context.update({'title': "Overview", 'pods': pods}) |