~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/maasserver/views/nodecommissionresult.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-02-16 22:56:36 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20140216225636-28dc7e3r1z4tu37u
Tags: upstream-1.5+bzr1976
ImportĀ upstreamĀ versionĀ 1.5+bzr1976

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Views for node commissioning results."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = [
 
16
    'NodeCommissionResultListView',
 
17
    ]
 
18
 
 
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
 
24
 
 
25
 
 
26
class NodeCommissionResultListView(PaginatedListView):
 
27
 
 
28
    template_name = 'maasserver/nodecommissionresult-list.html'
 
29
    context_object_name = 'results_list'
 
30
 
 
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')
 
34
 
 
35
    def get_context_data(self, **kwargs):
 
36
        context = super(NodeCommissionResultListView, self).get_context_data(
 
37
            **kwargs)
 
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))
 
43
        return context
 
44
 
 
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')
 
51
 
 
52
 
 
53
class NodeCommissionResultView(DetailView):
 
54
 
 
55
    template_name = 'metadataserver/nodecommissionresult.html'
 
56
 
 
57
    def get_object(self):
 
58
        result_id = self.kwargs.get('id')
 
59
        return get_object_or_404(NodeCommissionResult, id=result_id)