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({'action': 'get', 'object': '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_subject('slice')
48 print "METADATA", md_fields
49 # TODO Get default fields
50 main_query.fields = ['slice_hrn', 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority']
52 #old# main_query = ManifoldQuery (action='get',
53 #old# subject='resource',
54 #old# timestamp='latest',
55 #old# fields=['network','type','hrn','hostname'],
56 #old# filters= [ [ 'slice_hrn', '=', slicename, ] ],
59 aq = AnalyzedQuery(main_query)
60 page.enqueue_query(main_query, analyzed_query=aq)
62 # Prepare the display according to all metadata
63 # (some parts will be pending, others can be triggered by users).
65 # For example slice measurements will not be requested by default...
67 # Create the base layout (Stack)...
70 title="Slice view for %s"%slicename,
76 title="Runtime messages for slice %s"%slicename,
80 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
84 # ... responsible for the slice properties...
87 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
91 # ... and for the relations
92 # XXX Let's hardcode resources for now
93 sq = aq.subquery('resource')
95 tab_resources = Tabs (
99 # activeid = 'checkboxes',
100 active_domid = 'gmap',
102 main_plugin.insert(tab_resources)
108 tab_resources.insert(
112 domid = 'checkboxes',
113 # tab's sons preferably turn this off
115 # this is the query at the core of the slice list
118 datatables_options = {
119 # for now we turn off sorting on the checkboxes columns this way
120 # this of course should be automatic in hazelnut
121 'aoColumns' : [None, None, None, None, {'bSortable': False}],
122 'iDisplayLength' : 25,
123 'bLengthChange' : True,
127 tab_resources.insert(
130 title = 'Geographic view',
132 # tab's sons preferably turn this off
142 # END OF JORDAN's CODE
144 #old# main_plugin = Stack (
146 #old# title="Slice view for %s"%slicename,
147 #old# domid='thestack',
148 #old# togglable=False,
150 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
153 #old# title="Runtime messages for slice %s"%slicename,
154 #old# domid="msgs-pre",
159 #old# title="2 tabs : w/ and w/o checkboxes",
160 #old# domid='thetabs',
161 #old# # active_domid='checkboxes',
162 #old# active_domid='gmap',
166 #old# title='a sample and simple hazelnut',
167 #old# domid='simple',
168 #old# # tab's sons preferably turn this off
169 #old# togglable=False,
170 #old# # this is the query at the core of the slice list
171 #old# query=main_query,
175 #old# title='with checkboxes',
176 #old# domid='checkboxes',
177 #old# # tab's sons preferably turn this off
178 #old# togglable=False,
179 #old# # this is the query at the core of the slice list
180 #old# query=main_query,
181 #old# checkboxes=True,
182 #old# datatables_options = {
183 #old# # for now we turn off sorting on the checkboxes columns this way
184 #old# # this of course should be automatic in hazelnut
185 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
186 #old# 'iDisplayLength' : 25,
187 #old# 'bLengthChange' : True,
192 #old# title='geographic view',
194 #old# # tab's sons preferably turn this off
195 #old# togglable=False,
196 #old# query=main_query,
197 #old# # center on Paris
205 #old# title='3D view (disabled)',
207 #old## # tab's sons preferably turn this off
208 #old# togglable=False,
209 #old## query=main_query,
210 #old# html="""<p class='well'>
211 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
212 #old# although rudimentarily ported to the django framework,
213 #old#causes a weird behaviour especially wrt scrolling.
214 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
215 #old#if I keep this active, so for now it's disabled
221 #old# title='a hazelnut not in tabs',
222 #old# domid='standalone',
223 #old# # this is the query at the core of the slice list
224 #old# query=main_query,
225 #old# columns=['hrn','hostname'],
227 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
228 #old# # because domid is the key for storing toggle status in the browser
231 #old# title='xmlrpc code (toggled=False)',
232 #old# query=main_query,
233 #old## domid='xmlrpc',
238 #old# title="QuickFilter - requires metadata (toggled=False)",
239 #old# criterias=quickfilter_criterias,
240 #old# domid='filters',
245 #old# title="Runtime messages (again)",
246 #old# domid="msgs-post",
250 # variables that will get passed to the view-unfold1.html template
253 # define 'unfold1_main' to the template engine - the main contents
254 template_env [ 'unfold1_main' ] = main_plugin.render(request)
256 # more general variables expected in the template
257 template_env [ 'title' ] = 'Test view that combines various plugins'
258 # the menu items on the top
259 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
260 # so we can sho who is logged
261 template_env [ 'username' ] = the_user (request)
263 # don't forget to run the requests
264 page.expose_queries ()
266 # xxx create another plugin with the same query and a different layout (with_datatables)
267 # show that it worls as expected, one single api call to backend and 2 refreshed views
269 # the prelude object in page contains a summary of the requirements() for all plugins
270 # define {js,css}_{files,chunks}
271 prelude_env = page.prelude_env()
272 template_env.update(prelude_env)
273 result=render_to_response ('view-unfold1.html',template_env,
274 context_instance=RequestContext(request))