added slicestat plugin
[myslice.git] / portal / resourceview.py
1 from django.views.generic.base   import TemplateView
2
3 from manifold.core.query         import Query
4 from unfold.page                 import Page
5
6 from ui.topmenu                  import topmenu_items, the_user
7
8 from plugins.googlemap           import GoogleMap
9 from plugins.hazelnut            import Hazelnut
10 from plugins.lists.simplelist    import SimpleList
11 from plugins.slicestat           import Slicestat
12
13 # View for 1 platform and its details
14 class ResourceView(TemplateView):
15     template_name = "resource.html"
16
17     def get_context_data(self, **kwargs):
18         page = Page(self.request)
19
20         for key, value in kwargs.iteritems():
21             print "%s = %s" % (key, value)       
22             if key == "urn":
23                 resource_urn=value
24                 
25         resource_query  = Query().get('resource')\
26             .filter_by('urn', '==', resource_urn)\
27             .select('hostname','type','hrn','urn', 'latitude', 'longitude', 'country')
28         page.enqueue_query(resource_query)
29
30         page.expose_js_metadata()
31         page.expose_queries()
32
33         resourcelist = Hazelnut(
34             page  = page,
35             title = 'List',
36             domid = 'checkboxes',
37             # this is the query at the core of the slice list
38             query = resource_query,
39             query_all = resource_query,
40             checkboxes = False,
41             datatables_options = {
42             'iDisplayLength' : 25,
43             'bLengthChange'  : True,
44             },
45         )
46         resource_as_map = GoogleMap(
47             page       = page,
48             title      = 'Geographic view',
49             domid      = 'resources-map',
50             # tab's sons preferably turn this off
51             togglable  = False,
52             query      = resource_query,
53             query_all  = resource_query,
54             checkboxes = False,
55             # center on Paris
56             #latitude   = 49.,
57             #longitude  = 9,
58             #zoom       = 4,
59         )
60 #        resourcelist = SimpleList(
61 #            title = None,
62 #            page  = page,
63 #            key   = 'hrn',
64 #            query = resource_query,
65 #        )
66
67         resource_stats = Slicestat(
68             title = None,
69             page  = page,
70             key   = 'hrn',
71             query = resource_query
72         )
73
74         context = super(ResourceView, self).get_context_data(**kwargs)
75         context['person']   = self.request.user
76         context['resource'] = resourcelist.render(self.request)
77         context['resource_as_map'] = resource_as_map.render(self.request)
78         context['resource_stats'] = resource_stats.render(self.request)
79
80         # XXX This is repeated in all pages
81         # more general variables expected in the template
82         context['title'] = 'Information about a resource'
83         # the menu items on the top
84         context['topmenu_items'] = topmenu_items('Dashboard', self.request)
85         # so we can sho who is logged
86         context['username'] = the_user(self.request)
87
88         context.update(page.prelude_env())
89
90         return context
91
92
93