rough, untested, port of SensLabMap
[myslice.git] / trash / sliceview.py
1 # Create your views here.
2
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5
6 from django.contrib.auth.decorators import login_required
7
8 from unfold.page import Page
9 from manifold.manifoldquery import ManifoldQuery
10
11 from plugins.stack.stack import Stack
12 from plugins.tabs.tabs import Tabs
13 from plugins.hazelnut.hazelnut import Hazelnut 
14 from plugins.googlemap.googlemap import GoogleMap 
15 from plugins.senslabmap.senslabmap import SensLabMap
16 from plugins.lists.slicelist import SliceList
17 from plugins.querycode.querycode import QueryCode
18 from plugins.quickfilter.quickfilter import QuickFilter
19
20 from myslice.viewutils import quickfilter_criterias
21
22 from myslice.viewutils import topmenu_items, the_user
23
24 tmp_default_slice='ple.inria.sfatest'
25
26 @login_required
27 def slice_view (request, slicename=tmp_default_slice):
28     
29     page = Page(request)
30
31     main_query = ManifoldQuery (action='get',
32                                 subject='resource',
33                                 timestamp='latest',
34                                 fields=['network','type','hrn','hostname'],
35                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
36                                 )
37     page.enqueue_query (main_query)
38
39     main_plugin = Stack (
40         page=page,
41         title="Slice view for %s"%slicename,
42         domid='thestack',
43         togglable=False,
44         sons=[Tabs (
45                 page=page,
46                 title="2 tabs : w/ and w/o checkboxes",
47                 domid='thetabs',
48                 # active_domid='checkboxes',
49                 active_domid='gmap',
50                 sons=[
51                     Hazelnut ( 
52                         page=page,
53                         title='a sample and simple hazelnut',
54                         domid='simple',
55                         # tab's sons preferably turn this off
56                         togglable=False,
57                         # this is the query at the core of the slice list
58                         query=main_query,
59                         ),
60                     Hazelnut ( 
61                         page=page,
62                         title='with checkboxes',
63                         domid='checkboxes',
64                         # tab's sons preferably turn this off
65                         togglable=False,
66                         # this is the query at the core of the slice list
67                         query=main_query,
68                         checkboxes=True,
69                         datatables_options = { 
70                             # for now we turn off sorting on the checkboxes columns this way
71                             # this of course should be automatic in hazelnut
72                             'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
73                             'iDisplayLength' : 25,
74                             'bLengthChange' : True,
75                             },
76                         ),
77                     GoogleMap (
78                         page=page,
79                         title='geographic view',
80                         domid='gmap',
81                         # tab's sons preferably turn this off
82                         togglable=False,
83                         query=main_query,
84                         ),
85                     SensLabMap (
86                         page=page,
87                         title='3D view',
88                         domid='smap',
89                         # tab's sons preferably turn this off
90                         togglable=False,
91                         query=main_query,
92                         ),
93                     ]),
94               Hazelnut ( 
95                 page=page,
96                 title='not in tabs',
97                 domid='standalone',
98                 # this is the query at the core of the slice list
99                 query=main_query,
100                 columns=['hrn','hostname'],
101                 ),
102               # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
103               # because domid is the key for storing toggle status in the browser
104               QueryCode (
105                 page=page,
106                 title='xmlrpc code (toggled=False)',
107                 query=main_query,
108 #                domid='xmlrpc',
109                 toggled=False,
110                 ),
111               QuickFilter (
112                 page=page,
113                 title="QuickFilter - requires metadata (toggled=False)",
114                 criterias=quickfilter_criterias,
115                 domid='filters',
116                 toggled=False,
117                 ),
118               ])
119
120     # variables that will get passed to the view-unfold1.html template
121     template_env = {}
122     
123     # define 'unfold1_main' to the template engine - the main contents
124     template_env [ 'unfold1_main' ] = main_plugin.render(request)
125
126     # more general variables expected in the template
127     template_env [ 'title' ] = 'Test view for hazelnut'
128     # the menu items on the top
129     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
130     # so we can sho who is logged
131     template_env [ 'username' ] = the_user (request) 
132
133     # don't forget to run the requests
134     page.exec_queue_asynchroneously ()
135
136     # xxx create another plugin with the same query and a different layout (with_datatables)
137     # show that it worls as expected, one single api call to backend and 2 refreshed views
138
139     # the prelude object in page contains a summary of the requirements() for all plugins
140     # define {js,css}_{files,chunks}
141     prelude_env = page.prelude_env()
142     template_env.update(prelude_env)
143     result=render_to_response ('view-unfold1.html',template_env,
144                                context_instance=RequestContext(request))
145     return result