1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Views for node commissioning results."""
6
from __future__ import (
16
'NodeCommissionResultListView',
19
from django.shortcuts import get_object_or_404
20
from django.views.generic import DetailView
21
from maasserver.models import Node
22
from maasserver.views import PaginatedListView
23
from metadataserver.models import NodeCommissionResult
26
class NodeCommissionResultListView(PaginatedListView):
28
template_name = 'maasserver/nodecommissionresult-list.html'
29
context_object_name = 'results_list'
31
def get_filter_system_ids(self):
32
"""Return the list of nodes that were selected for filtering."""
33
return self.request.GET.getlist('node')
35
def get_context_data(self, **kwargs):
36
context = super(NodeCommissionResultListView, self).get_context_data(
38
system_ids = self.get_filter_system_ids()
39
if system_ids is not None and len(system_ids) > 0:
40
nodes = Node.objects.filter(system_id__in=system_ids)
41
context['nodes_filter'] = ', '.join(
42
sorted(node.hostname for node in nodes))
45
def get_queryset(self):
46
results = NodeCommissionResult.objects.all()
47
system_ids = self.get_filter_system_ids()
48
if system_ids is not None and len(system_ids) > 0:
49
results = results.filter(node__system_id__in=system_ids)
50
return results.order_by('node', '-created', 'name')
53
class NodeCommissionResultView(DetailView):
55
template_name = 'metadataserver/nodecommissionresult.html'
58
result_id = self.kwargs.get('id')
59
return get_object_or_404(NodeCommissionResult, id=result_id)