1 # Create your views here.
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
6 from django.contrib.auth.decorators import login_required
7 from django.http import HttpResponseRedirect
9 from unfold.page import Page
10 #from manifold.manifoldquery import ManifoldQuery
11 from manifold.core.query import Query, AnalyzedQuery
13 from plugins.raw.raw import Raw
14 from plugins.stack.stack import Stack
15 from plugins.tabs.tabs import Tabs
16 from plugins.lists.slicelist import SliceList
17 from plugins.hazelnut.hazelnut import Hazelnut
18 from plugins.googlemap.googlemap import GoogleMap
19 from plugins.senslabmap.senslabmap import SensLabMap
20 from plugins.querycode.querycode import QueryCode
21 from plugins.quickfilter.quickfilter import QuickFilter
22 from plugins.messages.messages import Messages
24 from manifold.manifoldresult import ManifoldException
26 from myslice.viewutils import quickfilter_criterias
27 from myslice.viewutils import topmenu_items, the_user
30 from manifold.metadata import MetaData as Metadata
32 tmp_default_slice='ple.inria.heartbeat'
36 def slice_view (request, slicename=tmp_default_slice):
37 # xxx Thierry - ugly hack
38 # fetching metadata here might fail - e.g. with an expired session..
39 # let's catch this early on and log out our user if needed
40 # it should of course be handled in a more generic way
42 return _slice_view(request,slicename)
43 except ManifoldException, manifold_result:
44 # xxx needs a means to display this message to user...
45 from django.contrib.auth import logout
47 return HttpResponseRedirect ('/')
49 # xxx we need to sugarcoat this error message in some error template...
50 print "Unexpected exception",e
55 def _slice_view (request, slicename):
58 page.expose_js_metadata()
60 # TODO The query to run is embedded in the URL
61 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
63 # Get default fields from metadata unless specified
64 if not main_query.fields:
65 metadata = page.get_metadata()
66 md_fields = metadata.details_by_object('slice')
68 print "METADATA", md_fields
69 # TODO Get default fields
72 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority',
74 # 'application.measurement_point.counter'
77 aq = AnalyzedQuery(main_query)
78 page.enqueue_query(main_query, analyzed_query=aq)
80 # Prepare the display according to all metadata
81 # (some parts will be pending, others can be triggered by users).
83 # For example slice measurements will not be requested by default...
85 # Create the base layout (Stack)...
88 title="Slice view for %s"%slicename,
94 # ... responsible for the slice properties...
98 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename))
101 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
105 # ... and for the relations
106 # XXX Let's hardcode resources for now
107 sq = aq.subquery('resource')
109 tab_resources = Tabs (
113 # activeid = 'checkboxes',
114 active_domid = 'gmap',
116 main_plugin.insert(tab_resources)
118 tab_resources.insert(
122 domid = 'checkboxes',
123 # tab's sons preferably turn this off
125 # this is the query at the core of the slice list
128 datatables_options = {
129 # for now we turn off sorting on the checkboxes columns this way
130 # this of course should be automatic in hazelnut
131 'aoColumns' : [None, None, None, None, {'bSortable': False}],
132 'iDisplayLength' : 25,
133 'bLengthChange' : True,
137 tab_resources.insert(
140 title = 'Geographic view',
142 # tab's sons preferably turn this off
152 # XXX Let's hardcode users also for now
153 sq = aq.subquery('user')
159 # activeid = 'checkboxes',
160 active_domid = 'checkboxes2',
162 main_plugin.insert(tab_users)
168 domid = 'checkboxes2',
169 # tab's sons preferably turn this off
171 # this is the query at the core of the slice list
174 datatables_options = {
175 # for now we turn off sorting on the checkboxes columns this way
176 # this of course should be automatic in hazelnut
177 'aoColumns' : [None, None, None, None, {'bSortable': False}],
178 'iDisplayLength' : 25,
179 'bLengthChange' : True,
184 # XXX Let's hardcode measurements also for now
185 sq = aq.subquery('measurement')
189 title = 'Measurements',
191 # activeid = 'checkboxes',
192 active_domid = 'checkboxes3',
194 main_plugin.insert(tab_users)
200 domid = 'checkboxes3',
201 # tab's sons preferably turn this off
203 # this is the query at the core of the slice list
206 datatables_options = {
207 # for now we turn off sorting on the checkboxes columns this way
208 # this of course should be automatic in hazelnut
209 'aoColumns' : [None, None, None, None, {'bSortable': False}],
210 'iDisplayLength' : 25,
211 'bLengthChange' : True,
219 title="Runtime messages for slice %s"%slicename,
225 # END OF JORDAN's CODE
227 #old# main_plugin = Stack (
229 #old# title="Slice view for %s"%slicename,
230 #old# domid='thestack',
231 #old# togglable=False,
233 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
236 #old# title="Runtime messages for slice %s"%slicename,
237 #old# domid="msgs-pre",
242 #old# title="2 tabs : w/ and w/o checkboxes",
243 #old# domid='thetabs',
244 #old# # active_domid='checkboxes',
245 #old# active_domid='gmap',
249 #old# title='a sample and simple hazelnut',
250 #old# domid='simple',
251 #old# # tab's sons preferably turn this off
252 #old# togglable=False,
253 #old# # this is the query at the core of the slice list
254 #old# query=main_query,
258 #old# title='with checkboxes',
259 #old# domid='checkboxes',
260 #old# # tab's sons preferably turn this off
261 #old# togglable=False,
262 #old# # this is the query at the core of the slice list
263 #old# query=main_query,
264 #old# checkboxes=True,
265 #old# datatables_options = {
266 #old# # for now we turn off sorting on the checkboxes columns this way
267 #old# # this of course should be automatic in hazelnut
268 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
269 #old# 'iDisplayLength' : 25,
270 #old# 'bLengthChange' : True,
275 #old# title='geographic view',
277 #old# # tab's sons preferably turn this off
278 #old# togglable=False,
279 #old# query=main_query,
280 #old# # center on Paris
288 #old# title='3D view (disabled)',
290 #old## # tab's sons preferably turn this off
291 #old# togglable=False,
292 #old## query=main_query,
293 #old# html="""<p class='well'>
294 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
295 #old# although rudimentarily ported to the django framework,
296 #old#causes a weird behaviour especially wrt scrolling.
297 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
298 #old#if I keep this active, so for now it's disabled
304 #old# title='a hazelnut not in tabs',
305 #old# domid='standalone',
306 #old# # this is the query at the core of the slice list
307 #old# query=main_query,
308 #old# columns=['hrn','hostname'],
310 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
311 #old# # because domid is the key for storing toggle status in the browser
314 #old# title='xmlrpc code (toggled=False)',
315 #old# query=main_query,
316 #old## domid='xmlrpc',
321 #old# title="QuickFilter - requires metadata (toggled=False)",
322 #old# criterias=quickfilter_criterias,
323 #old# domid='filters',
328 #old# title="Runtime messages (again)",
329 #old# domid="msgs-post",
333 # variables that will get passed to the view-unfold1.html template
336 # define 'unfold1_main' to the template engine - the main contents
337 template_env [ 'unfold1_main' ] = main_plugin.render(request)
339 # more general variables expected in the template
340 template_env [ 'title' ] = 'Test view that combines various plugins'
341 # the menu items on the top
342 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
343 # so we can sho who is logged
344 template_env [ 'username' ] = the_user (request)
346 # don't forget to run the requests
347 page.expose_queries ()
349 # xxx create another plugin with the same query and a different layout (with_datatables)
350 # show that it worls as expected, one single api call to backend and 2 refreshed views
352 # the prelude object in page contains a summary of the requirements() for all plugins
353 # define {js,css}_{files,chunks}
354 prelude_env = page.prelude_env()
355 template_env.update(prelude_env)
356 result=render_to_response ('view-unfold1.html',template_env,
357 context_instance=RequestContext(request))