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 title="Runtime messages for slice %s"%slicename,
96 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
100 # ... responsible for the slice properties...
103 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
107 # ... and for the relations
108 # XXX Let's hardcode resources for now
109 sq = aq.subquery('resource')
111 tab_resources = Tabs (
115 # activeid = 'checkboxes',
116 active_domid = 'gmap',
118 main_plugin.insert(tab_resources)
120 tab_resources.insert(
124 domid = 'checkboxes',
125 # tab's sons preferably turn this off
127 # this is the query at the core of the slice list
130 datatables_options = {
131 # for now we turn off sorting on the checkboxes columns this way
132 # this of course should be automatic in hazelnut
133 'aoColumns' : [None, None, None, None, {'bSortable': False}],
134 'iDisplayLength' : 25,
135 'bLengthChange' : True,
139 tab_resources.insert(
142 title = 'Geographic view',
144 # tab's sons preferably turn this off
154 # XXX Let's hardcode users also for now
155 sq = aq.subquery('user')
161 # activeid = 'checkboxes',
162 active_domid = 'checkboxes2',
164 main_plugin.insert(tab_users)
170 domid = 'checkboxes2',
171 # tab's sons preferably turn this off
173 # this is the query at the core of the slice list
176 datatables_options = {
177 # for now we turn off sorting on the checkboxes columns this way
178 # this of course should be automatic in hazelnut
179 'aoColumns' : [None, None, None, None, {'bSortable': False}],
180 'iDisplayLength' : 25,
181 'bLengthChange' : True,
186 # XXX Let's hardcode measurements also for now
187 sq = aq.subquery('measurement')
191 title = 'Measurements',
193 # activeid = 'checkboxes',
194 active_domid = 'checkboxes3',
196 main_plugin.insert(tab_users)
202 domid = 'checkboxes3',
203 # tab's sons preferably turn this off
205 # this is the query at the core of the slice list
208 datatables_options = {
209 # for now we turn off sorting on the checkboxes columns this way
210 # this of course should be automatic in hazelnut
211 'aoColumns' : [None, None, None, None, {'bSortable': False}],
212 'iDisplayLength' : 25,
213 'bLengthChange' : True,
218 # END OF JORDAN's CODE
220 #old# main_plugin = Stack (
222 #old# title="Slice view for %s"%slicename,
223 #old# domid='thestack',
224 #old# togglable=False,
226 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
229 #old# title="Runtime messages for slice %s"%slicename,
230 #old# domid="msgs-pre",
235 #old# title="2 tabs : w/ and w/o checkboxes",
236 #old# domid='thetabs',
237 #old# # active_domid='checkboxes',
238 #old# active_domid='gmap',
242 #old# title='a sample and simple hazelnut',
243 #old# domid='simple',
244 #old# # tab's sons preferably turn this off
245 #old# togglable=False,
246 #old# # this is the query at the core of the slice list
247 #old# query=main_query,
251 #old# title='with checkboxes',
252 #old# domid='checkboxes',
253 #old# # tab's sons preferably turn this off
254 #old# togglable=False,
255 #old# # this is the query at the core of the slice list
256 #old# query=main_query,
257 #old# checkboxes=True,
258 #old# datatables_options = {
259 #old# # for now we turn off sorting on the checkboxes columns this way
260 #old# # this of course should be automatic in hazelnut
261 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
262 #old# 'iDisplayLength' : 25,
263 #old# 'bLengthChange' : True,
268 #old# title='geographic view',
270 #old# # tab's sons preferably turn this off
271 #old# togglable=False,
272 #old# query=main_query,
273 #old# # center on Paris
281 #old# title='3D view (disabled)',
283 #old## # tab's sons preferably turn this off
284 #old# togglable=False,
285 #old## query=main_query,
286 #old# html="""<p class='well'>
287 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
288 #old# although rudimentarily ported to the django framework,
289 #old#causes a weird behaviour especially wrt scrolling.
290 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
291 #old#if I keep this active, so for now it's disabled
297 #old# title='a hazelnut not in tabs',
298 #old# domid='standalone',
299 #old# # this is the query at the core of the slice list
300 #old# query=main_query,
301 #old# columns=['hrn','hostname'],
303 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
304 #old# # because domid is the key for storing toggle status in the browser
307 #old# title='xmlrpc code (toggled=False)',
308 #old# query=main_query,
309 #old## domid='xmlrpc',
314 #old# title="QuickFilter - requires metadata (toggled=False)",
315 #old# criterias=quickfilter_criterias,
316 #old# domid='filters',
321 #old# title="Runtime messages (again)",
322 #old# domid="msgs-post",
326 # variables that will get passed to the view-unfold1.html template
329 # define 'unfold1_main' to the template engine - the main contents
330 template_env [ 'unfold1_main' ] = main_plugin.render(request)
332 # more general variables expected in the template
333 template_env [ 'title' ] = 'Test view that combines various plugins'
334 # the menu items on the top
335 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
336 # so we can sho who is logged
337 template_env [ 'username' ] = the_user (request)
339 # don't forget to run the requests
340 page.expose_queries ()
342 # xxx create another plugin with the same query and a different layout (with_datatables)
343 # show that it worls as expected, one single api call to backend and 2 refreshed views
345 # the prelude object in page contains a summary of the requirements() for all plugins
346 # define {js,css}_{files,chunks}
347 prelude_env = page.prelude_env()
348 template_env.update(prelude_env)
349 result=render_to_response ('view-unfold1.html',template_env,
350 context_instance=RequestContext(request))