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
53 def _slice_view (request, slicename):
56 page.expose_js_metadata()
58 # TODO The query to run is embedded in the URL
59 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
61 # Get default fields from metadata unless specified
62 if not main_query.fields:
63 metadata = page.get_metadata()
64 md_fields = metadata.details_by_object('slice')
66 print "METADATA", md_fields
67 # TODO Get default fields
70 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority',
72 # 'application.measurement_point.counter'
75 aq = AnalyzedQuery(main_query)
76 page.enqueue_query(main_query, analyzed_query=aq)
78 # Prepare the display according to all metadata
79 # (some parts will be pending, others can be triggered by users).
81 # For example slice measurements will not be requested by default...
83 # Create the base layout (Stack)...
86 title="Slice view for %s"%slicename,
92 # ... responsible for the slice properties...
96 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename))
99 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
103 # ... and for the relations
104 # XXX Let's hardcode resources for now
105 sq = aq.subquery('resource')
107 tab_resources = Tabs (
111 # activeid = 'checkboxes',
112 active_domid = 'gmap',
114 main_plugin.insert(tab_resources)
116 tab_resources.insert(
120 domid = 'checkboxes',
121 # tab's sons preferably turn this off
123 # this is the query at the core of the slice list
126 datatables_options = {
127 # for now we turn off sorting on the checkboxes columns this way
128 # this of course should be automatic in hazelnut
129 'aoColumns' : [None, None, None, None, {'bSortable': False}],
130 'iDisplayLength' : 25,
131 'bLengthChange' : True,
135 tab_resources.insert(
138 title = 'Geographic view',
140 # tab's sons preferably turn this off
150 # XXX Let's hardcode users also for now
151 sq = aq.subquery('user')
157 # activeid = 'checkboxes',
158 active_domid = 'checkboxes2',
160 main_plugin.insert(tab_users)
166 domid = 'checkboxes2',
167 # tab's sons preferably turn this off
169 # this is the query at the core of the slice list
172 datatables_options = {
173 # for now we turn off sorting on the checkboxes columns this way
174 # this of course should be automatic in hazelnut
175 'aoColumns' : [None, None, None, None, {'bSortable': False}],
176 'iDisplayLength' : 25,
177 'bLengthChange' : True,
182 # XXX Let's hardcode measurements also for now
183 sq = aq.subquery('measurement')
187 title = 'Measurements',
189 # activeid = 'checkboxes',
190 active_domid = 'checkboxes3',
192 main_plugin.insert(tab_users)
198 domid = 'checkboxes3',
199 # tab's sons preferably turn this off
201 # this is the query at the core of the slice list
204 datatables_options = {
205 # for now we turn off sorting on the checkboxes columns this way
206 # this of course should be automatic in hazelnut
207 'aoColumns' : [None, None, None, None, {'bSortable': False}],
208 'iDisplayLength' : 25,
209 'bLengthChange' : True,
217 title="Runtime messages for slice %s"%slicename,
223 # END OF JORDAN's CODE
225 #old# main_plugin = Stack (
227 #old# title="Slice view for %s"%slicename,
228 #old# domid='thestack',
229 #old# togglable=False,
231 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
234 #old# title="Runtime messages for slice %s"%slicename,
235 #old# domid="msgs-pre",
240 #old# title="2 tabs : w/ and w/o checkboxes",
241 #old# domid='thetabs',
242 #old# # active_domid='checkboxes',
243 #old# active_domid='gmap',
247 #old# title='a sample and simple hazelnut',
248 #old# domid='simple',
249 #old# # tab's sons preferably turn this off
250 #old# togglable=False,
251 #old# # this is the query at the core of the slice list
252 #old# query=main_query,
256 #old# title='with checkboxes',
257 #old# domid='checkboxes',
258 #old# # tab's sons preferably turn this off
259 #old# togglable=False,
260 #old# # this is the query at the core of the slice list
261 #old# query=main_query,
262 #old# checkboxes=True,
263 #old# datatables_options = {
264 #old# # for now we turn off sorting on the checkboxes columns this way
265 #old# # this of course should be automatic in hazelnut
266 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
267 #old# 'iDisplayLength' : 25,
268 #old# 'bLengthChange' : True,
273 #old# title='geographic view',
275 #old# # tab's sons preferably turn this off
276 #old# togglable=False,
277 #old# query=main_query,
278 #old# # center on Paris
286 #old# title='3D view (disabled)',
288 #old## # tab's sons preferably turn this off
289 #old# togglable=False,
290 #old## query=main_query,
291 #old# html="""<p class='well'>
292 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
293 #old# although rudimentarily ported to the django framework,
294 #old#causes a weird behaviour especially wrt scrolling.
295 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
296 #old#if I keep this active, so for now it's disabled
302 #old# title='a hazelnut not in tabs',
303 #old# domid='standalone',
304 #old# # this is the query at the core of the slice list
305 #old# query=main_query,
306 #old# columns=['hrn','hostname'],
308 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
309 #old# # because domid is the key for storing toggle status in the browser
312 #old# title='xmlrpc code (toggled=False)',
313 #old# query=main_query,
314 #old## domid='xmlrpc',
319 #old# title="QuickFilter - requires metadata (toggled=False)",
320 #old# criterias=quickfilter_criterias,
321 #old# domid='filters',
326 #old# title="Runtime messages (again)",
327 #old# domid="msgs-post",
331 # variables that will get passed to the view-unfold1.html template
334 # define 'unfold1_main' to the template engine - the main contents
335 template_env [ 'unfold1_main' ] = main_plugin.render(request)
337 # more general variables expected in the template
338 template_env [ 'title' ] = 'Test view that combines various plugins'
339 # the menu items on the top
340 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
341 # so we can sho who is logged
342 template_env [ 'username' ] = the_user (request)
344 # don't forget to run the requests
345 page.expose_queries ()
347 # xxx create another plugin with the same query and a different layout (with_datatables)
348 # show that it worls as expected, one single api call to backend and 2 refreshed views
350 # the prelude object in page contains a summary of the requirements() for all plugins
351 # define {js,css}_{files,chunks}
352 prelude_env = page.prelude_env()
353 template_env.update(prelude_env)
354 result=render_to_response ('view-unfold1.html',template_env,
355 context_instance=RequestContext(request))