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