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
6 from django.http import HttpResponseRedirect
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
12 # need to remove this dep.
13 from trash.trashutils import quickfilter_criterias
14 from myslice.viewutils import topmenu_items, the_user, logout_on_manifold_exception
16 from plugins.raw.raw import Raw
17 from plugins.stack.stack import Stack
18 from plugins.tabs.tabs import Tabs
19 from plugins.lists.slicelist import SliceList
20 from plugins.hazelnut import Hazelnut
21 from plugins.resources_selected import ResourcesSelected
22 from plugins.googlemaps import GoogleMaps
23 from plugins.senslabmap.senslabmap import SensLabMap
24 from plugins.querycode.querycode import QueryCode
25 from plugins.query_editor import QueryEditor
26 from plugins.active_filters import ActiveFilters
27 from plugins.quickfilter.quickfilter import QuickFilter
28 from plugins.messages.messages import Messages
29 #from plugins.updater import Updater
31 tmp_default_slice='ple.upmc.myslicedemo'
34 @logout_on_manifold_exception
36 def slice_view (request, slicename=tmp_default_slice):
39 page.expose_js_metadata()
41 metadata = page.get_metadata()
42 resource_md = metadata.details_by_object('resource')
43 resource_fields = [column['name'] for column in resource_md['column']]
45 user_md = metadata.details_by_object('user')
46 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
48 # TODO The query to run is embedded in the URL
49 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
52 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn',
55 #'application.measurement_point.counter'
58 query_resource_all = Query.get('resource').select(resource_fields)
59 query_user_all = Query.get('user').select(user_fields)
61 aq = AnalyzedQuery(main_query, metadata=metadata)
62 page.enqueue_query(main_query, analyzed_query=aq)
63 page.enqueue_query(query_resource_all)
64 page.enqueue_query(query_user_all)
66 # Prepare the display according to all metadata
67 # (some parts will be pending, others can be triggered by users).
69 # For example slice measurements will not be requested by default...
71 # Create the base layout (Stack)...
74 title="Slice !!view for %s"%slicename,
78 # ... responsible for the slice properties...
82 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename)
86 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
91 title="Slice view for %s"%slicename,
97 # ... and for the relations
98 # XXX Let's hardcode resources for now
99 sq_resource = aq.subquery('resource')
100 sq_user = aq.subquery('user')
101 sq_lease = aq.subquery('lease')
102 sq_measurement = aq.subquery('measurement')
105 ############################################################################
108 # A stack inserted in the subquery tab that will hold all operations
109 # related to resources
112 stack_resources = Stack(
118 resource_query_editor = QueryEditor(
122 stack_resources.insert(resource_query_editor)
124 resource_active_filters = ActiveFilters(
128 stack_resources.insert(resource_active_filters)
130 # --------------------------------------------------------------------------
131 # Different displays = DataTables + GoogleMaps
133 tab_resource_plugins = Tabs(
138 tab_resource_plugins.insert(Hazelnut(
141 domid = 'checkboxes',
142 # this is the query at the core of the slice list
144 query_all = query_resource_all,
146 datatables_options = {
147 # for now we turn off sorting on the checkboxes columns this way
148 # this of course should be automatic in hazelnut
149 'aoColumns' : [None, None, None, None, {'bSortable': False}],
150 'iDisplayLength' : 25,
151 'bLengthChange' : True,
155 tab_resource_plugins.insert(GoogleMaps(
157 title = 'Geographic view',
159 # tab's sons preferably turn this off
162 query_all = query_resource_all,
170 stack_resources.insert(tab_resource_plugins)
172 sq_plugin.insert(stack_resources)
174 ############################################################################
182 # activeid = 'checkboxes',
183 active_domid = 'checkboxes2',
185 sq_plugin.insert(tab_users)
187 tab_users.insert(Hazelnut(
190 domid = 'checkboxes2',
191 # tab's sons preferably turn this off
193 # this is the query at the core of the slice list
195 query_all = query_user_all,
197 datatables_options = {
198 # for now we turn off sorting on the checkboxes columns this way
199 # this of course should be automatic in hazelnut
200 'aoColumns' : [None, None, None, None, {'bSortable': False}],
201 'iDisplayLength' : 25,
202 'bLengthChange' : True,
206 tab_measurements = Tabs (
208 title = 'Measurements',
210 # activeid = 'checkboxes',
211 active_domid = 'checkboxes3',
213 sq_plugin.insert(tab_measurements)
215 tab_measurements.insert(Hazelnut(
218 domid = 'checkboxes3',
219 # tab's sons preferably turn this off
221 # this is the query at the core of the slice list
222 query = sq_measurement,
224 datatables_options = {
225 # for now we turn off sorting on the checkboxes columns this way
226 # this of course should be automatic in hazelnut
227 'aoColumns' : [None, None, None, None, {'bSortable': False}],
228 'iDisplayLength' : 25,
229 'bLengthChange' : True,
233 main_plugin.insert(sq_plugin)
235 # --------------------------------------------------------------------------
238 main_plugin.insert(ResourcesSelected(
240 title = 'Pending operations',
245 main_plugin.insert(Messages(
247 title = "Runtime messages for slice %s"%slicename,
251 # main_plugin.insert(Updater(
253 # title = "wont show up as non togglable by default",
254 # query = main_query,
255 # label = "Update slice",
260 # variables that will get passed to the view-unfold1.html template
263 # define 'unfold1_main' to the template engine - the main contents
264 template_env [ 'unfold1_main' ] = main_plugin.render(request)
266 # more general variables expected in the template
267 template_env [ 'title' ] = '%(slicename)s (test view that combines various plugins)'%locals()
268 # the menu items on the top
269 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
270 # so we can sho who is logged
271 template_env [ 'username' ] = the_user (request)
273 # don't forget to run the requests
274 page.expose_queries ()
276 # xxx create another plugin with the same query and a different layout (with_datatables)
277 # show that it worls as expected, one single api call to backend and 2 refreshed views
279 # the prelude object in page contains a summary of the requirements() for all plugins
280 # define {js,css}_{files,chunks}
281 prelude_env = page.prelude_env()
282 template_env.update(prelude_env)
283 result=render_to_response ('view-unfold1.html',template_env,
284 context_instance=RequestContext(request))