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
18 from myslice.theme import ThemeView
20 # View for 1 platform and its details
21 class PlatformView(FreeAccessView, ThemeView):
22 template_name = "platform.html"
24 def get_context_data(self, **kwargs):
25 page = Page(self.request)
26 page.add_js_files ( [ "js/common.functions.js" ] )
28 for key, value in kwargs.iteritems():
29 print "%s = %s" % (key, value)
30 if key == "platformname":
33 network_query = Query().get('local:platform')\
34 .filter_by('platform', '==', platformname)\
35 .select('platform','platform_longname','gateway_type')
36 page.enqueue_query(network_query)
38 # ListResources of the platform
39 metadata = page.get_metadata()
40 resource_md = metadata.details_by_object('resource')
41 resource_fields = [column['name'] for column in resource_md['column']]
42 resources = platformname + ':resource'
43 query_resource_all = Query.get(resources).select(resource_fields)
44 page.enqueue_query(query_resource_all)
45 query_resource_default_fields = Query.get(resources).select('hrn','hostname', 'type','country')
46 page.enqueue_query(query_resource_default_fields)
48 page.expose_js_metadata()
49 networklist = QueryTable(
53 # this is the query at the core of the slice list
54 query = network_query,
55 query_all = network_query,
57 datatables_options = {
58 'iDisplayLength' : 25,
59 'bLengthChange' : True,
63 # networklist = SimpleList(
67 # query = network_query,
70 # --------------------------------------------------------------------------
72 # for internal use in the querytable plugin;
73 # needs to be a unique column present for each returned record
74 main_query_init_key = 'hrn'
76 # the resources part is made of a Tabs (Geographic, List),
77 resources_as_gmap = GoogleMap(
79 title = 'Geographic view',
80 domid = 'resources-map',
81 # tab's sons preferably turn this off
83 query = query_resource_default_fields,
84 query_all = query_resource_all,
85 # this key is the one issued by google
86 googlemap_api_key = ConfigEngine().googlemap_api_key(),
87 # the key to use at init-time
88 init_key = main_query_init_key,
95 resources_as_3dmap = SensLabMap(
99 query = query_resource_default_fields,
100 query_all = query_resource_all,
102 resources_as_list = QueryTable(
104 domid = 'resources-list',
106 # this is the query at the core of the slice list
107 query = query_resource_default_fields,
108 query_all = query_resource_all,
109 init_key = main_query_init_key,
111 datatables_options = {
112 'iDisplayLength': 25,
113 'bLengthChange' : True,
122 resources_area = Tabs ( page=page,
126 outline_complete=True,
127 sons= resources_sons,
128 active_domid = 'resources-map',
129 persistent_active=True,
132 context = super(PlatformView, self).get_context_data(**kwargs)
133 context['person'] = self.request.user
134 context['networks'] = networklist.render(self.request)
135 context['resources'] = resources_area.render(self.request)
137 # XXX This is repeated in all pages
138 # more general variables expected in the template
139 context['title'] = 'Platforms connected to MySlice'
140 # the menu items on the top
141 context['topmenu_items'] = topmenu_items_live('Platforms', page)
142 # so we can sho who is logged
143 context['username'] = the_user(self.request)
144 context['theme'] = self.theme
145 context.update(page.prelude_env())