1 from manifold.core.query import Query
2 from unfold.page import Page
4 from unfold.loginrequired import FreeAccessView
5 from ui.topmenu import topmenu_items_live, the_user
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
12 from myslice.configengine import ConfigEngine
13 from myslice.theme import ThemeView
15 # View for 1 platform and its details
16 class ResourceView(FreeAccessView, ThemeView):
17 template_name = "resource.html"
19 def get_context_data(self, **kwargs):
20 page = Page(self.request)
22 page.add_js_files ( [ "js/common.functions.js" ] )
24 for key, value in kwargs.iteritems():
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)
33 page.expose_js_metadata()
35 resourcelist = QueryTable(
39 # this is the query at the core of the slice list
40 query = resource_query,
41 query_all = resource_query,
43 datatables_options = {
44 'iDisplayLength' : 25,
45 'bLengthChange' : True,
48 resource_as_map = GoogleMap(
50 title = 'Geographic view',
51 domid = 'resources-map',
52 # tab's sons preferably turn this off
54 query = resource_query,
55 query_all = resource_query,
56 googlemap_api_key = ConfigEngine().googlemap_api_key(),
63 # resourcelist = SimpleList(
67 # query = resource_query,
70 resource_stats = SliceStat(
75 query = resource_query
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)
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())