in prevision for django-1.7, rename our local auth module into localauth to avoid...
[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             print "%s = %s" % (key, value)       
26             if key == "urn":
27                 resource_urn=value
28                 
29         resource_query  = Query().get('resource')\
30             .filter_by('urn', '==', resource_urn)\
31             .select('hostname','type','hrn','urn', 'latitude', 'longitude', 'country')
32         page.enqueue_query(resource_query)
33
34         page.expose_js_metadata()
35
36         resourcelist = QueryTable(
37             page  = page,
38             title = 'List',
39             domid = 'checkboxes',
40             # this is the query at the core of the slice list
41             query = resource_query,
42             query_all = resource_query,
43             checkboxes = False,
44             datatables_options = {
45             'iDisplayLength' : 25,
46             'bLengthChange'  : True,
47             },
48         )
49         resource_as_map = GoogleMap(
50             page       = page,
51             title      = 'Geographic view',
52             domid      = 'resources-map',
53             # tab's sons preferably turn this off
54             togglable  = True,
55             query      = resource_query,
56             query_all  = resource_query,
57             googlemap_api_key = ConfigEngine().googlemap_api_key(),
58             checkboxes = False,
59             # center on Paris
60             #latitude   = 49.,
61             #longitude  = 9,
62             #zoom       = 4,
63         )
64 #        resourcelist = SimpleList(
65 #            title = None,
66 #            page  = page,
67 #            key   = 'hrn',
68 #            query = resource_query,
69 #        )
70
71         resource_stats = SliceStat(
72             title = None,
73             page  = page,
74             stats = 'node',
75             key   = 'hrn',
76             query = resource_query
77         )
78
79         context = super(ResourceView, self).get_context_data(**kwargs)
80         context['person']   = self.request.user
81         context['resource'] = resourcelist.render(self.request)
82         context['resource_as_map'] = resource_as_map.render(self.request)
83         context['resource_stats'] = resource_stats.render(self.request)
84
85         # XXX This is repeated in all pages
86         # more general variables expected in the template
87         context['title'] = 'Information about a resource'
88         # the menu items on the top
89         context['topmenu_items'] = topmenu_items_live(None, page)
90         # so we can sho who is logged
91         context['username'] = the_user(self.request)
92         context['theme'] = self.theme
93         context.update(page.prelude_env())
94
95         return context
96
97
98