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():
25 print "%s = %s" % (key, value)
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)
34 page.expose_js_metadata()
36 resourcelist = QueryTable(
40 # this is the query at the core of the slice list
41 query = resource_query,
42 query_all = resource_query,
44 datatables_options = {
45 'iDisplayLength' : 25,
46 'bLengthChange' : True,
49 resource_as_map = GoogleMap(
51 title = 'Geographic view',
52 domid = 'resources-map',
53 # tab's sons preferably turn this off
55 query = resource_query,
56 query_all = resource_query,
57 googlemap_api_key = ConfigEngine().googlemap_api_key(),
64 # resourcelist = SimpleList(
68 # query = resource_query,
71 resource_stats = SliceStat(
76 query = resource_query
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)
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())