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 portal.templateviews import LoginRequiredAutoLogoutView
9 from unfold.page import Page
10 from manifold.core.query import Query, AnalyzedQuery
11 from manifold.manifoldresult import ManifoldException
12 from manifold.metadata import MetaData as Metadata
14 from myslice.viewutils import topmenu_items, the_user
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 class SliceView (LoginRequiredAutoLogoutView):
36 # def __init__ (self, slicename=None):
37 # self.slicename = slicename or tmp_default_slice
39 def get (self,request, slicename=tmp_default_slice):
42 page.expose_js_metadata()
44 metadata = page.get_metadata()
45 resource_md = metadata.details_by_object('resource')
46 resource_fields = [column['name'] for column in resource_md['column']]
48 user_md = metadata.details_by_object('user')
49 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
51 # TODO The query to run is embedded in the URL
52 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
55 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn',
58 #'application.measurement_point.counter'
61 query_resource_all = Query.get('resource').select(resource_fields)
62 query_user_all = Query.get('user').select(user_fields)
64 aq = AnalyzedQuery(main_query, metadata=metadata)
65 page.enqueue_query(main_query, analyzed_query=aq)
66 page.enqueue_query(query_resource_all)
67 page.enqueue_query(query_user_all)
69 # Prepare the display according to all metadata
70 # (some parts will be pending, others can be triggered by users).
72 # For example slice measurements will not be requested by default...
74 # Create the base layout (Stack)...
77 title="Slice !!view for %s"%slicename,
81 # ... responsible for the slice properties...
85 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename)
89 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
94 title="Slice view for %s"%slicename,
100 # ... and for the relations
101 # XXX Let's hardcode resources for now
102 sq_resource = aq.subquery('resource')
103 sq_user = aq.subquery('user')
104 sq_lease = aq.subquery('lease')
105 sq_measurement = aq.subquery('measurement')
108 ############################################################################
111 # A stack inserted in the subquery tab that will hold all operations
112 # related to resources
115 stack_resources = Stack(
121 resource_query_editor = QueryEditor(
125 stack_resources.insert(resource_query_editor)
127 resource_active_filters = ActiveFilters(
131 stack_resources.insert(resource_active_filters)
133 # --------------------------------------------------------------------------
134 # Different displays = DataTables + GoogleMaps
136 tab_resource_plugins = Tabs(
141 tab_resource_plugins.insert(Hazelnut(
144 domid = 'checkboxes',
145 # this is the query at the core of the slice list
147 query_all = query_resource_all,
149 datatables_options = {
150 # for now we turn off sorting on the checkboxes columns this way
151 # this of course should be automatic in hazelnut
152 'aoColumns' : [None, None, None, None, {'bSortable': False}],
153 'iDisplayLength' : 25,
154 'bLengthChange' : True,
158 tab_resource_plugins.insert(GoogleMaps(
160 title = 'Geographic view',
162 # tab's sons preferably turn this off
165 query_all = query_resource_all,
173 stack_resources.insert(tab_resource_plugins)
175 sq_plugin.insert(stack_resources)
177 ############################################################################
185 # activeid = 'checkboxes',
186 active_domid = 'checkboxes2',
188 sq_plugin.insert(tab_users)
190 tab_users.insert(Hazelnut(
193 domid = 'checkboxes2',
194 # tab's sons preferably turn this off
196 # this is the query at the core of the slice list
198 query_all = query_user_all,
200 datatables_options = {
201 # for now we turn off sorting on the checkboxes columns this way
202 # this of course should be automatic in hazelnut
203 'aoColumns' : [None, None, None, None, {'bSortable': False}],
204 'iDisplayLength' : 25,
205 'bLengthChange' : True,
209 tab_measurements = Tabs (
211 title = 'Measurements',
213 # activeid = 'checkboxes',
214 active_domid = 'checkboxes3',
216 sq_plugin.insert(tab_measurements)
218 tab_measurements.insert(Hazelnut(
221 domid = 'checkboxes3',
222 # tab's sons preferably turn this off
224 # this is the query at the core of the slice list
225 query = sq_measurement,
227 datatables_options = {
228 # for now we turn off sorting on the checkboxes columns this way
229 # this of course should be automatic in hazelnut
230 'aoColumns' : [None, None, None, None, {'bSortable': False}],
231 'iDisplayLength' : 25,
232 'bLengthChange' : True,
236 main_plugin.insert(sq_plugin)
238 # --------------------------------------------------------------------------
241 main_plugin.insert(ResourcesSelected(
243 title = 'Pending operations',
248 main_plugin.insert(Messages(
250 title = "Runtime messages for slice %s"%slicename,
254 # main_plugin.insert(Updater(
256 # title = "wont show up as non togglable by default",
257 # query = main_query,
258 # label = "Update slice",
263 # variables that will get passed to the view-unfold1.html template
266 # define 'unfold1_main' to the template engine - the main contents
267 template_env [ 'unfold1_main' ] = main_plugin.render(request)
269 # more general variables expected in the template
270 template_env [ 'title' ] = '%(slicename)s'%locals()
271 # the menu items on the top
272 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
273 # so we can sho who is logged
274 template_env [ 'username' ] = the_user (request)
276 # don't forget to run the requests
277 page.expose_queries ()
279 # xxx create another plugin with the same query and a different layout (with_datatables)
280 # show that it worls as expected, one single api call to backend and 2 refreshed views
282 # the prelude object in page contains a summary of the requirements() for all plugins
283 # define {js,css}_{files,chunks}
284 prelude_env = page.prelude_env()
285 template_env.update(prelude_env)
286 result=render_to_response ('view-unfold1.html',template_env,
287 context_instance=RequestContext(request))