8f8a8baba542ee364080ab18a85f2b8a15787527
[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.raw.raw import Raw
12 from plugins.stack.stack import Stack
13 from plugins.tabs.tabs import Tabs
14 from plugins.lists.slicelist import SliceList
15 from plugins.hazelnut.hazelnut import Hazelnut 
16 from plugins.googlemap.googlemap import GoogleMap 
17 from plugins.senslabmap.senslabmap import SensLabMap
18 from plugins.querycode.querycode import QueryCode
19 from plugins.quickfilter.quickfilter import QuickFilter
20 from plugins.messages.messages import Messages
21
22 from myslice.viewutils import quickfilter_criterias
23
24 from myslice.viewutils import topmenu_items, the_user
25
26 tmp_default_slice='ple.inria.heartbeat'
27
28 @login_required
29 def slice_view (request, slicename=tmp_default_slice):
30     
31     page = Page(request)
32
33     main_query = ManifoldQuery (action='get',
34                                 subject='resource',
35                                 timestamp='latest',
36                                 fields=['network','type','hrn','hostname'],
37                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
38                                 )
39     page.enqueue_query (main_query)
40
41     main_plugin = Stack (
42         page=page,
43         title="Slice view for %s"%slicename,
44         domid='thestack',
45         togglable=False,
46         sons=[
47             Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename),
48             Messages (
49                 page=page,
50                 title="Runtime messages for slice %s"%slicename,
51                 domid="msgs-pre",
52                 levels="ALL",
53                 ),
54             Tabs (
55                 page=page,
56                 title="2 tabs : w/ and w/o checkboxes",
57                 domid='thetabs',
58                 # active_domid='checkboxes',
59                 active_domid='gmap',
60                 sons=[
61                     Hazelnut ( 
62                         page=page,
63                         title='a sample and simple hazelnut',
64                         domid='simple',
65                         # tab's sons preferably turn this off
66                         togglable=False,
67                         # this is the query at the core of the slice list
68                         query=main_query,
69                         ),
70                     Hazelnut ( 
71                         page=page,
72                         title='with checkboxes',
73                         domid='checkboxes',
74                         # tab's sons preferably turn this off
75                         togglable=False,
76                         # this is the query at the core of the slice list
77                         query=main_query,
78                         checkboxes=True,
79                         datatables_options = { 
80                             # for now we turn off sorting on the checkboxes columns this way
81                             # this of course should be automatic in hazelnut
82                             'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
83                             'iDisplayLength' : 25,
84                             'bLengthChange' : True,
85                             },
86                         ),
87                     GoogleMap (
88                         page=page,
89                         title='geographic view',
90                         domid='gmap',
91                         # tab's sons preferably turn this off
92                         togglable=False,
93                         query=main_query,
94                         # center on Paris
95                         latitude=49.,
96                         longitude=2.2,
97                         zoom=3,
98                         ),
99                     Raw (
100 #                    SensLabMap (
101                         page=page,
102                         title='3D view (disabled)',
103                         domid='smap',
104 #                        # tab's sons preferably turn this off
105                         togglable=False,
106 #                        query=main_query,
107                         html="""<p class='well'>
108 Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
109  although rudimentarily ported to the django framework, 
110 causes a weird behaviour especially wrt scrolling. 
111 On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
112 if I keep this active, so for now it's disabled
113 </p>""",
114                         ),
115                     ]),
116             Hazelnut ( 
117                 page=page,
118                 title='a hazelnut not in tabs',
119                 domid='standalone',
120                 # this is the query at the core of the slice list
121                 query=main_query,
122                 columns=['hrn','hostname'],
123                 ),
124               # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
125               # because domid is the key for storing toggle status in the browser
126             QueryCode (
127                 page=page,
128                 title='xmlrpc code (toggled=False)',
129                 query=main_query,
130 #                domid='xmlrpc',
131                 toggled=False,
132                 ),
133             QuickFilter (
134                 page=page,
135                 title="QuickFilter - requires metadata (toggled=False)",
136                 criterias=quickfilter_criterias,
137                 domid='filters',
138                 toggled=False,
139                 ),
140             Messages (
141                 page=page,
142                 title="Runtime messages (again)",
143                 domid="msgs-post",
144                 )
145               ])
146
147     # variables that will get passed to the view-unfold1.html template
148     template_env = {}
149     
150     # define 'unfold1_main' to the template engine - the main contents
151     template_env [ 'unfold1_main' ] = main_plugin.render(request)
152
153     # more general variables expected in the template
154     template_env [ 'title' ] = 'Test view that combines various plugins'
155     # the menu items on the top
156     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
157     # so we can sho who is logged
158     template_env [ 'username' ] = the_user (request) 
159
160     # don't forget to run the requests
161     page.expose_queries ()
162
163     # xxx create another plugin with the same query and a different layout (with_datatables)
164     # show that it worls as expected, one single api call to backend and 2 refreshed views
165
166     # the prelude object in page contains a summary of the requirements() for all plugins
167     # define {js,css}_{files,chunks}
168     prelude_env = page.prelude_env()
169     template_env.update(prelude_env)
170     result=render_to_response ('view-unfold1.html',template_env,
171                                context_instance=RequestContext(request))
172     return result