1 # Create your views here.
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5 from django.contrib.auth.decorators import login_required
7 from unfold.page import Page
8 from manifold.core.query import Query, AnalyzedQuery
9 from manifold.manifoldresult import ManifoldException
10 from manifold.metadata import MetaData as Metadata
11 # need to remove this dep.
12 from trash.trashutils import quickfilter_criterias
13 from myslice.viewutils import topmenu_items, the_user, logout_on_manifold_exception
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 @logout_on_manifold_exception
35 def slice_view (request, slicename=tmp_default_slice):
38 page.expose_js_metadata()
40 metadata = page.get_metadata()
41 resource_md = metadata.details_by_object('resource')
42 resource_fields = [column['name'] for column in resource_md['column']]
44 user_md = metadata.details_by_object('user')
45 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
47 # TODO The query to run is embedded in the URL
48 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
51 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn',
54 #'application.measurement_point.counter'
57 query_resource_all = Query.get('resource').select(resource_fields)
58 query_user_all = Query.get('user').select(user_fields)
60 aq = AnalyzedQuery(main_query, metadata=metadata)
61 page.enqueue_query(main_query, analyzed_query=aq)
62 page.enqueue_query(query_resource_all)
63 page.enqueue_query(query_user_all)
65 # Prepare the display according to all metadata
66 # (some parts will be pending, others can be triggered by users).
68 # For example slice measurements will not be requested by default...
70 # Create the base layout (Stack)...
73 title="Slice !!view for %s"%slicename,
77 # ... responsible for the slice properties...
81 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename)
85 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
90 title="Slice view for %s"%slicename,
96 # ... and for the relations
97 # XXX Let's hardcode resources for now
98 sq_resource = aq.subquery('resource')
99 sq_user = aq.subquery('user')
100 sq_lease = aq.subquery('lease')
101 sq_measurement = aq.subquery('measurement')
104 ############################################################################
107 # A stack inserted in the subquery tab that will hold all operations
108 # related to resources
111 stack_resources = Stack(
117 resource_query_editor = QueryEditor(
121 stack_resources.insert(resource_query_editor)
123 resource_active_filters = ActiveFilters(
127 stack_resources.insert(resource_active_filters)
129 # --------------------------------------------------------------------------
130 # Different displays = DataTables + GoogleMaps
132 tab_resource_plugins = Tabs(
137 tab_resource_plugins.insert(Hazelnut(
140 domid = 'checkboxes',
141 # this is the query at the core of the slice list
143 query_all = query_resource_all,
145 datatables_options = {
146 # for now we turn off sorting on the checkboxes columns this way
147 # this of course should be automatic in hazelnut
148 'aoColumns' : [None, None, None, None, {'bSortable': False}],
149 'iDisplayLength' : 25,
150 'bLengthChange' : True,
154 tab_resource_plugins.insert(GoogleMaps(
156 title = 'Geographic view',
158 # tab's sons preferably turn this off
161 query_all = query_resource_all,
169 stack_resources.insert(tab_resource_plugins)
171 sq_plugin.insert(stack_resources)
173 ############################################################################
181 # activeid = 'checkboxes',
182 active_domid = 'checkboxes2',
184 sq_plugin.insert(tab_users)
186 tab_users.insert(Hazelnut(
189 domid = 'checkboxes2',
190 # tab's sons preferably turn this off
192 # this is the query at the core of the slice list
194 query_all = query_user_all,
196 datatables_options = {
197 # for now we turn off sorting on the checkboxes columns this way
198 # this of course should be automatic in hazelnut
199 'aoColumns' : [None, None, None, None, {'bSortable': False}],
200 'iDisplayLength' : 25,
201 'bLengthChange' : True,
205 tab_measurements = Tabs (
207 title = 'Measurements',
209 # activeid = 'checkboxes',
210 active_domid = 'checkboxes3',
212 sq_plugin.insert(tab_measurements)
214 tab_measurements.insert(Hazelnut(
217 domid = 'checkboxes3',
218 # tab's sons preferably turn this off
220 # this is the query at the core of the slice list
221 query = sq_measurement,
223 datatables_options = {
224 # for now we turn off sorting on the checkboxes columns this way
225 # this of course should be automatic in hazelnut
226 'aoColumns' : [None, None, None, None, {'bSortable': False}],
227 'iDisplayLength' : 25,
228 'bLengthChange' : True,
232 main_plugin.insert(sq_plugin)
234 # --------------------------------------------------------------------------
237 main_plugin.insert(ResourcesSelected(
239 title = 'Pending operations',
244 main_plugin.insert(Messages(
246 title = "Runtime messages for slice %s"%slicename,
250 # main_plugin.insert(Updater(
252 # title = "wont show up as non togglable by default",
253 # query = main_query,
254 # label = "Update slice",
259 # variables that will get passed to the view-unfold1.html template
262 # define 'unfold1_main' to the template engine - the main contents
263 template_env [ 'unfold1_main' ] = main_plugin.render(request)
265 # more general variables expected in the template
266 template_env [ 'title' ] = '%(slicename)s'%locals()
267 # the menu items on the top
268 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
269 # so we can sho who is logged
270 template_env [ 'username' ] = the_user (request)
272 # don't forget to run the requests
273 page.expose_queries ()
275 # xxx create another plugin with the same query and a different layout (with_datatables)
276 # show that it worls as expected, one single api call to backend and 2 refreshed views
278 # the prelude object in page contains a summary of the requirements() for all plugins
279 # define {js,css}_{files,chunks}
280 prelude_env = page.prelude_env()
281 template_env.update(prelude_env)
282 result=render_to_response ('view-unfold1.html',template_env,
283 context_instance=RequestContext(request))