1 # Create your views here.
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
6 from portal.templateviews import LoginRequiredAutoLogoutView
8 from unfold.page import Page
9 from manifold.core.query import Query, AnalyzedQuery
10 from manifold.manifoldresult import ManifoldException
11 from manifold.metadata import MetaData as Metadata
13 from myslice.viewutils import topmenu_items, the_user
15 from plugins.raw.raw import Raw
16 from plugins.stack.stack import Stack
17 from plugins.tabs.tabs import Tabs
18 from plugins.lists.slicelist import SliceList
19 from plugins.hazelnut import Hazelnut
20 from plugins.resources_selected import ResourcesSelected
21 from plugins.googlemaps import GoogleMaps
22 from plugins.senslabmap.senslabmap import SensLabMap
23 from plugins.querycode.querycode import QueryCode
24 from plugins.query_editor import QueryEditor
25 from plugins.active_filters import ActiveFilters
26 from plugins.quickfilter.quickfilter import QuickFilter
27 from plugins.messages.messages import Messages
28 #from plugins.updater import Updater
30 tmp_default_slice='ple.upmc.myslicedemo'
33 class SliceView (LoginRequiredAutoLogoutView):
35 # def __init__ (self, slicename=None):
36 # self.slicename = slicename or tmp_default_slice
38 def get (self,request, slicename=tmp_default_slice):
41 page.expose_js_metadata()
43 metadata = page.get_metadata()
44 resource_md = metadata.details_by_object('resource')
45 resource_fields = [column['name'] for column in resource_md['column']]
47 user_md = metadata.details_by_object('user')
48 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
50 # TODO The query to run is embedded in the URL
51 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
54 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn',
57 #'application.measurement_point.counter'
60 query_resource_all = Query.get('resource').select(resource_fields)
61 query_user_all = Query.get('user').select(user_fields)
63 aq = AnalyzedQuery(main_query, metadata=metadata)
64 page.enqueue_query(main_query, analyzed_query=aq)
65 page.enqueue_query(query_resource_all)
66 page.enqueue_query(query_user_all)
68 # Prepare the display according to all metadata
69 # (some parts will be pending, others can be triggered by users).
71 # For example slice measurements will not be requested by default...
73 # Create the base layout (Stack)...
76 title="Slice !!view for %s"%slicename,
80 # ... responsible for the slice properties...
84 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename)
88 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
93 title="Slice view for %s"%slicename,
99 # ... and for the relations
100 # XXX Let's hardcode resources for now
101 sq_resource = aq.subquery('resource')
102 sq_user = aq.subquery('user')
103 sq_lease = aq.subquery('lease')
104 sq_measurement = aq.subquery('measurement')
107 ############################################################################
110 # A stack inserted in the subquery tab that will hold all operations
111 # related to resources
114 stack_resources = Stack(
120 resource_query_editor = QueryEditor(
124 stack_resources.insert(resource_query_editor)
126 resource_active_filters = ActiveFilters(
130 stack_resources.insert(resource_active_filters)
132 # --------------------------------------------------------------------------
133 # Different displays = DataTables + GoogleMaps
135 tab_resource_plugins = Tabs(
140 tab_resource_plugins.insert(Hazelnut(
143 domid = 'checkboxes',
144 # this is the query at the core of the slice list
146 query_all = query_resource_all,
148 datatables_options = {
149 # for now we turn off sorting on the checkboxes columns this way
150 # this of course should be automatic in hazelnut
151 'aoColumns' : [None, None, None, None, {'bSortable': False}],
152 'iDisplayLength' : 25,
153 'bLengthChange' : True,
157 tab_resource_plugins.insert(GoogleMaps(
159 title = 'Geographic view',
161 # tab's sons preferably turn this off
164 query_all = query_resource_all,
172 stack_resources.insert(tab_resource_plugins)
174 sq_plugin.insert(stack_resources)
176 ############################################################################
184 # activeid = 'checkboxes',
185 active_domid = 'checkboxes2',
187 sq_plugin.insert(tab_users)
189 tab_users.insert(Hazelnut(
192 domid = 'checkboxes2',
193 # tab's sons preferably turn this off
195 # this is the query at the core of the slice list
197 query_all = query_user_all,
199 datatables_options = {
200 # for now we turn off sorting on the checkboxes columns this way
201 # this of course should be automatic in hazelnut
202 'aoColumns' : [None, None, None, None, {'bSortable': False}],
203 'iDisplayLength' : 25,
204 'bLengthChange' : True,
208 tab_measurements = Tabs (
210 title = 'Measurements',
212 # activeid = 'checkboxes',
213 active_domid = 'checkboxes3',
215 sq_plugin.insert(tab_measurements)
217 tab_measurements.insert(Hazelnut(
220 domid = 'checkboxes3',
221 # tab's sons preferably turn this off
223 # this is the query at the core of the slice list
224 query = sq_measurement,
226 datatables_options = {
227 # for now we turn off sorting on the checkboxes columns this way
228 # this of course should be automatic in hazelnut
229 'aoColumns' : [None, None, None, None, {'bSortable': False}],
230 'iDisplayLength' : 25,
231 'bLengthChange' : True,
235 main_plugin.insert(sq_plugin)
237 # --------------------------------------------------------------------------
240 main_plugin.insert(ResourcesSelected(
242 title = 'Pending operations',
247 main_plugin.insert(Messages(
249 title = "Runtime messages for slice %s"%slicename,
253 # main_plugin.insert(Updater(
255 # title = "wont show up as non togglable by default",
256 # query = main_query,
257 # label = "Update slice",
262 # variables that will get passed to the view-unfold1.html template
265 # define 'unfold1_main' to the template engine - the main contents
266 template_env [ 'unfold1_main' ] = main_plugin.render(request)
268 # more general variables expected in the template
269 template_env [ 'title' ] = '%(slicename)s'%locals()
270 # the menu items on the top
271 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
272 # so we can sho who is logged
273 template_env [ 'username' ] = the_user (request)
275 # don't forget to run the requests
276 page.expose_queries ()
278 # xxx create another plugin with the same query and a different layout (with_datatables)
279 # show that it worls as expected, one single api call to backend and 2 refreshed views
281 # the prelude object in page contains a summary of the requirements() for all plugins
282 # define {js,css}_{files,chunks}
283 prelude_env = page.prelude_env()
284 template_env.update(prelude_env)
285 result=render_to_response ('view-unfold1.html',template_env,
286 context_instance=RequestContext(request))