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