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
8 from unfold.page import Page
9 #from manifold.manifoldquery import ManifoldQuery
10 from manifold.core.query import Query, AnalyzedQuery
12 from plugins.raw.raw import Raw
13 from plugins.stack.stack import Stack
14 from plugins.tabs.tabs import Tabs
15 from plugins.lists.slicelist import SliceList
16 from plugins.hazelnut.hazelnut import Hazelnut
17 from plugins.googlemap.googlemap import GoogleMap
18 from plugins.senslabmap.senslabmap import SensLabMap
19 from plugins.querycode.querycode import QueryCode
20 from plugins.quickfilter.quickfilter import QuickFilter
21 from plugins.messages.messages import Messages
23 from myslice.viewutils import quickfilter_criterias
25 from myslice.viewutils import topmenu_items, the_user
28 from manifold.metadata import MetaData as Metadata
30 tmp_default_slice='ple.inria.heartbeat'
34 def slice_view (request, slicename=tmp_default_slice):
37 page.expose_js_metadata()
40 # TODO The query to run is embedded in the URL
41 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
43 # Get default fields from metadata unless specified
44 if not main_query.fields:
45 md_fields = page.get_metadata()
46 md_fields = md_fields.details_by_object('slice')
48 print "METADATA", md_fields
49 # TODO Get default fields
52 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority',
54 # 'application.measurement_point.counter'
57 aq = AnalyzedQuery(main_query)
58 page.enqueue_query(main_query, analyzed_query=aq)
60 # Prepare the display according to all metadata
61 # (some parts will be pending, others can be triggered by users).
63 # For example slice measurements will not be requested by default...
65 # Create the base layout (Stack)...
68 title="Slice view for %s"%slicename,
74 title="Runtime messages for slice %s"%slicename,
78 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
82 # ... responsible for the slice properties...
85 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
89 # ... and for the relations
90 # XXX Let's hardcode resources for now
91 sq = aq.subquery('resource')
93 tab_resources = Tabs (
97 # activeid = 'checkboxes',
98 active_domid = 'gmap',
100 main_plugin.insert(tab_resources)
102 tab_resources.insert(
106 domid = 'checkboxes',
107 # tab's sons preferably turn this off
109 # this is the query at the core of the slice list
112 datatables_options = {
113 # for now we turn off sorting on the checkboxes columns this way
114 # this of course should be automatic in hazelnut
115 'aoColumns' : [None, None, None, None, {'bSortable': False}],
116 'iDisplayLength' : 25,
117 'bLengthChange' : True,
121 tab_resources.insert(
124 title = 'Geographic view',
126 # tab's sons preferably turn this off
136 # XXX Let's hardcode users also for now
137 sq = aq.subquery('user')
143 # activeid = 'checkboxes',
144 active_domid = 'checkboxes2',
146 main_plugin.insert(tab_users)
152 domid = 'checkboxes2',
153 # tab's sons preferably turn this off
155 # this is the query at the core of the slice list
158 datatables_options = {
159 # for now we turn off sorting on the checkboxes columns this way
160 # this of course should be automatic in hazelnut
161 'aoColumns' : [None, None, None, None, {'bSortable': False}],
162 'iDisplayLength' : 25,
163 'bLengthChange' : True,
168 # XXX Let's hardcode measurements also for now
169 sq = aq.subquery('measurement')
173 title = 'Measurements',
175 # activeid = 'checkboxes',
176 active_domid = 'checkboxes3',
178 main_plugin.insert(tab_users)
184 domid = 'checkboxes3',
185 # tab's sons preferably turn this off
187 # this is the query at the core of the slice list
190 datatables_options = {
191 # for now we turn off sorting on the checkboxes columns this way
192 # this of course should be automatic in hazelnut
193 'aoColumns' : [None, None, None, None, {'bSortable': False}],
194 'iDisplayLength' : 25,
195 'bLengthChange' : True,
200 # END OF JORDAN's CODE
202 #old# main_plugin = Stack (
204 #old# title="Slice view for %s"%slicename,
205 #old# domid='thestack',
206 #old# togglable=False,
208 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
211 #old# title="Runtime messages for slice %s"%slicename,
212 #old# domid="msgs-pre",
217 #old# title="2 tabs : w/ and w/o checkboxes",
218 #old# domid='thetabs',
219 #old# # active_domid='checkboxes',
220 #old# active_domid='gmap',
224 #old# title='a sample and simple hazelnut',
225 #old# domid='simple',
226 #old# # tab's sons preferably turn this off
227 #old# togglable=False,
228 #old# # this is the query at the core of the slice list
229 #old# query=main_query,
233 #old# title='with checkboxes',
234 #old# domid='checkboxes',
235 #old# # tab's sons preferably turn this off
236 #old# togglable=False,
237 #old# # this is the query at the core of the slice list
238 #old# query=main_query,
239 #old# checkboxes=True,
240 #old# datatables_options = {
241 #old# # for now we turn off sorting on the checkboxes columns this way
242 #old# # this of course should be automatic in hazelnut
243 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
244 #old# 'iDisplayLength' : 25,
245 #old# 'bLengthChange' : True,
250 #old# title='geographic view',
252 #old# # tab's sons preferably turn this off
253 #old# togglable=False,
254 #old# query=main_query,
255 #old# # center on Paris
263 #old# title='3D view (disabled)',
265 #old## # tab's sons preferably turn this off
266 #old# togglable=False,
267 #old## query=main_query,
268 #old# html="""<p class='well'>
269 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
270 #old# although rudimentarily ported to the django framework,
271 #old#causes a weird behaviour especially wrt scrolling.
272 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
273 #old#if I keep this active, so for now it's disabled
279 #old# title='a hazelnut not in tabs',
280 #old# domid='standalone',
281 #old# # this is the query at the core of the slice list
282 #old# query=main_query,
283 #old# columns=['hrn','hostname'],
285 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
286 #old# # because domid is the key for storing toggle status in the browser
289 #old# title='xmlrpc code (toggled=False)',
290 #old# query=main_query,
291 #old## domid='xmlrpc',
296 #old# title="QuickFilter - requires metadata (toggled=False)",
297 #old# criterias=quickfilter_criterias,
298 #old# domid='filters',
303 #old# title="Runtime messages (again)",
304 #old# domid="msgs-post",
308 # variables that will get passed to the view-unfold1.html template
311 # define 'unfold1_main' to the template engine - the main contents
312 template_env [ 'unfold1_main' ] = main_plugin.render(request)
314 # more general variables expected in the template
315 template_env [ 'title' ] = 'Test view that combines various plugins'
316 # the menu items on the top
317 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
318 # so we can sho who is logged
319 template_env [ 'username' ] = the_user (request)
321 # don't forget to run the requests
322 page.expose_queries ()
324 # xxx create another plugin with the same query and a different layout (with_datatables)
325 # show that it worls as expected, one single api call to backend and 2 refreshed views
327 # the prelude object in page contains a summary of the requirements() for all plugins
328 # define {js,css}_{files,chunks}
329 prelude_env = page.prelude_env()
330 template_env.update(prelude_env)
331 result=render_to_response ('view-unfold1.html',template_env,
332 context_instance=RequestContext(request))