1 from django.template import RequestContext
2 from django.shortcuts import render_to_response
4 from manifold.core.query import Query
5 from unfold.page import Page
6 from plugins.raw import Raw
7 from plugins.stack import Stack
8 from plugins.tabs import Tabs
9 from plugins.googlemap import GoogleMap
10 from plugins.senslabmap import SensLabMap
12 from unfold.loginrequired import FreeAccessView
13 from ui.topmenu import topmenu_items_live, the_user
15 from plugins.querytable import QueryTable
17 from myslice.configengine import ConfigEngine
19 # View for 1 platform and its details
20 class PlatformView(FreeAccessView):
21 template_name = "platform.html"
23 def get_context_data(self, **kwargs):
24 page = Page(self.request)
25 page.add_js_files ( [ "js/common.functions.js" ] )
27 for key, value in kwargs.iteritems():
28 print "%s = %s" % (key, value)
29 if key == "platformname":
32 network_query = Query().get('local:platform')\
33 .filter_by('platform', '==', platformname)\
34 .select('platform','platform_longname','gateway_type')
35 page.enqueue_query(network_query)
37 # ListResources of the platform
38 metadata = page.get_metadata()
39 resource_md = metadata.details_by_object('resource')
40 resource_fields = [column['name'] for column in resource_md['column']]
41 resources = platformname + ':resource'
42 query_resource_all = Query.get(resources).select(resource_fields)
43 page.enqueue_query(query_resource_all)
44 query_resource_default_fields = Query.get(resources).select('hrn','hostname', 'type','country')
45 page.enqueue_query(query_resource_default_fields)
47 page.expose_js_metadata()
48 networklist = QueryTable(
52 # this is the query at the core of the slice list
53 query = network_query,
54 query_all = network_query,
56 datatables_options = {
57 'iDisplayLength' : 25,
58 'bLengthChange' : True,
62 # networklist = SimpleList(
66 # query = network_query,
69 # --------------------------------------------------------------------------
71 # for internal use in the querytable plugin;
72 # needs to be a unique column present for each returned record
73 main_query_init_key = 'hrn'
75 # the resources part is made of a Tabs (Geographic, List),
76 resources_as_gmap = GoogleMap(
78 title = 'Geographic view',
79 domid = 'resources-map',
80 # tab's sons preferably turn this off
82 query = query_resource_default_fields,
83 query_all = query_resource_all,
84 # this key is the one issued by google
85 googlemap_api_key = Config().googlemap_api_key(),
86 # the key to use at init-time
87 init_key = main_query_init_key,
94 resources_as_3dmap = SensLabMap(
98 query = query_resource_default_fields,
99 query_all = query_resource_all,
101 resources_as_list = QueryTable(
103 domid = 'resources-list',
105 # this is the query at the core of the slice list
106 query = query_resource_default_fields,
107 query_all = query_resource_all,
108 init_key = main_query_init_key,
110 datatables_options = {
111 'iDisplayLength': 25,
112 'bLengthChange' : True,
121 resources_area = Tabs ( page=page,
125 outline_complete=True,
126 sons= resources_sons,
127 active_domid = 'resources-map',
128 persistent_active=True,
131 context = super(PlatformView, self).get_context_data(**kwargs)
132 context['person'] = self.request.user
133 context['networks'] = networklist.render(self.request)
134 context['resources'] = resources_area.render(self.request)
136 # XXX This is repeated in all pages
137 # more general variables expected in the template
138 context['title'] = 'Platforms connected to MySlice'
139 # the menu items on the top
140 context['topmenu_items'] = topmenu_items_live('Platforms', page)
141 # so we can sho who is logged
142 context['username'] = the_user(self.request)
144 context.update(page.prelude_env())