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):
38 # TODO The query to run is embedded in the URL
39 main_query = Query({'action': 'get', 'object': 'slice'}).filter_by('slice_hrn', '=', slicename)
41 # Get default fields from metadata unless specified
42 if not main_query.fields:
43 md_fields = page.get_metadata()
44 md_fields = md_fields.details_by_subject('slice')
46 print "METADATA", md_fields
47 # TODO Get default fields
48 main_query.fields = ['slice_hrn', 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority']
50 #old# main_query = ManifoldQuery (action='get',
51 #old# subject='resource',
52 #old# timestamp='latest',
53 #old# fields=['network','type','hrn','hostname'],
54 #old# filters= [ [ 'slice_hrn', '=', slicename, ] ],
56 page.enqueue_query(main_query)
58 # Prepare the display according to all metadata
59 # (some parts will be pending, others can be triggered by users).
61 # For example slice measurements will not be requested by default...
63 # Create the base layout (Stack)...
66 title="Slice view for %s"%slicename,
72 title="Runtime messages for slice %s"%slicename,
76 Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
80 # ... responsible for the slice properties...
83 Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
87 # ... and for the relations
88 # XXX Let's hardcode resources for now
89 aq = AnalyzedQuery(main_query)
90 sq = aq.subquery('resource')
92 tab_resources = Tabs (
96 # activeid = 'checkboxes',
97 active_domid = 'gmap',
99 main_plugin.insert(tab_resources)
101 tab_resources.insert(
105 domid = 'checkboxes',
106 # tab's sons preferably turn this off
108 # this is the query at the core of the slice list
111 datatables_options = {
112 # for now we turn off sorting on the checkboxes columns this way
113 # this of course should be automatic in hazelnut
114 'aoColumns' : [None, None, None, None, {'bSortable': False}],
115 'iDisplayLength' : 25,
116 'bLengthChange' : True,
120 tab_resources.insert(
123 title = 'Geographic view',
125 # tab's sons preferably turn this off
135 # END OF JORDAN's CODE
137 #old# main_plugin = Stack (
139 #old# title="Slice view for %s"%slicename,
140 #old# domid='thestack',
141 #old# togglable=False,
143 #old# Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
146 #old# title="Runtime messages for slice %s"%slicename,
147 #old# domid="msgs-pre",
152 #old# title="2 tabs : w/ and w/o checkboxes",
153 #old# domid='thetabs',
154 #old# # active_domid='checkboxes',
155 #old# active_domid='gmap',
159 #old# title='a sample and simple hazelnut',
160 #old# domid='simple',
161 #old# # tab's sons preferably turn this off
162 #old# togglable=False,
163 #old# # this is the query at the core of the slice list
164 #old# query=main_query,
168 #old# title='with checkboxes',
169 #old# domid='checkboxes',
170 #old# # tab's sons preferably turn this off
171 #old# togglable=False,
172 #old# # this is the query at the core of the slice list
173 #old# query=main_query,
174 #old# checkboxes=True,
175 #old# datatables_options = {
176 #old# # for now we turn off sorting on the checkboxes columns this way
177 #old# # this of course should be automatic in hazelnut
178 #old# 'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
179 #old# 'iDisplayLength' : 25,
180 #old# 'bLengthChange' : True,
185 #old# title='geographic view',
187 #old# # tab's sons preferably turn this off
188 #old# togglable=False,
189 #old# query=main_query,
190 #old# # center on Paris
198 #old# title='3D view (disabled)',
200 #old## # tab's sons preferably turn this off
201 #old# togglable=False,
202 #old## query=main_query,
203 #old# html="""<p class='well'>
204 #old#Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
205 #old# although rudimentarily ported to the django framework,
206 #old#causes a weird behaviour especially wrt scrolling.
207 #old#On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
208 #old#if I keep this active, so for now it's disabled
214 #old# title='a hazelnut not in tabs',
215 #old# domid='standalone',
216 #old# # this is the query at the core of the slice list
217 #old# query=main_query,
218 #old# columns=['hrn','hostname'],
220 #old# # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
221 #old# # because domid is the key for storing toggle status in the browser
224 #old# title='xmlrpc code (toggled=False)',
225 #old# query=main_query,
226 #old## domid='xmlrpc',
231 #old# title="QuickFilter - requires metadata (toggled=False)",
232 #old# criterias=quickfilter_criterias,
233 #old# domid='filters',
238 #old# title="Runtime messages (again)",
239 #old# domid="msgs-post",
243 # variables that will get passed to the view-unfold1.html template
246 # define 'unfold1_main' to the template engine - the main contents
247 template_env [ 'unfold1_main' ] = main_plugin.render(request)
249 # more general variables expected in the template
250 template_env [ 'title' ] = 'Test view that combines various plugins'
251 # the menu items on the top
252 template_env [ 'topmenu_items' ] = topmenu_items('slice', request)
253 # so we can sho who is logged
254 template_env [ 'username' ] = the_user (request)
256 # don't forget to run the requests
257 page.expose_queries ()
259 # xxx create another plugin with the same query and a different layout (with_datatables)
260 # show that it worls as expected, one single api call to backend and 2 refreshed views
262 # the prelude object in page contains a summary of the requirements() for all plugins
263 # define {js,css}_{files,chunks}
264 prelude_env = page.prelude_env()
265 template_env.update(prelude_env)
266 result=render_to_response ('view-unfold1.html',template_env,
267 context_instance=RequestContext(request))