456d635dea170a3f15c51d4410dbca3275974315
[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.sfatest'
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             Messages (
48                 page=page,
49                 title="Runtime messages",
50                 domid="msgs-pre",
51                 ),
52             Tabs (
53                 page=page,
54                 title="2 tabs : w/ and w/o checkboxes",
55                 domid='thetabs',
56                 # active_domid='checkboxes',
57                 active_domid='gmap',
58                 sons=[
59                     Hazelnut ( 
60                         page=page,
61                         title='a sample and simple hazelnut',
62                         domid='simple',
63                         # tab's sons preferably turn this off
64                         togglable=False,
65                         # this is the query at the core of the slice list
66                         query=main_query,
67                         ),
68                     Hazelnut ( 
69                         page=page,
70                         title='with checkboxes',
71                         domid='checkboxes',
72                         # tab's sons preferably turn this off
73                         togglable=False,
74                         # this is the query at the core of the slice list
75                         query=main_query,
76                         checkboxes=True,
77                         datatables_options = { 
78                             # for now we turn off sorting on the checkboxes columns this way
79                             # this of course should be automatic in hazelnut
80                             'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
81                             'iDisplayLength' : 25,
82                             'bLengthChange' : True,
83                             },
84                         ),
85                     GoogleMap (
86                         page=page,
87                         title='geographic view',
88                         domid='gmap',
89                         # tab's sons preferably turn this off
90                         togglable=False,
91                         query=main_query,
92                         ),
93                     Raw (
94 #                    SensLabMap (
95                         page=page,
96                         title='3D view (disabled)',
97                         domid='smap',
98 #                        # tab's sons preferably turn this off
99                         togglable=False,
100 #                        query=main_query,
101                         html="""<p class='well'>
102 Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
103  although rudimentarily ported to the django framework, 
104 causes a weird behaviour especially wrt scrolling. 
105 On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
106 if I keep this active, so for now it's disabled
107 </p>""",
108                         ),
109                     ]),
110             Hazelnut ( 
111                 page=page,
112                 title='not in tabs',
113                 domid='standalone',
114                 # this is the query at the core of the slice list
115                 query=main_query,
116                 columns=['hrn','hostname'],
117                 ),
118               # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
119               # because domid is the key for storing toggle status in the browser
120             QueryCode (
121                 page=page,
122                 title='xmlrpc code (toggled=False)',
123                 query=main_query,
124 #                domid='xmlrpc',
125                 toggled=False,
126                 ),
127             QuickFilter (
128                 page=page,
129                 title="QuickFilter - requires metadata (toggled=False)",
130                 criterias=quickfilter_criterias,
131                 domid='filters',
132                 toggled=False,
133                 ),
134             Messages (
135                 page=page,
136                 title="Runtime messages (again)",
137                 domid="msgs-post",
138                 )
139               ])
140
141     # variables that will get passed to the view-unfold1.html template
142     template_env = {}
143     
144     # define 'unfold1_main' to the template engine - the main contents
145     template_env [ 'unfold1_main' ] = main_plugin.render(request)
146
147     # more general variables expected in the template
148     template_env [ 'title' ] = 'Test view that combines various plugins'
149     # the menu items on the top
150     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
151     # so we can sho who is logged
152     template_env [ 'username' ] = the_user (request) 
153
154     # don't forget to run the requests
155     page.expose_queries ()
156
157     # xxx create another plugin with the same query and a different layout (with_datatables)
158     # show that it worls as expected, one single api call to backend and 2 refreshed views
159
160     # the prelude object in page contains a summary of the requirements() for all plugins
161     # define {js,css}_{files,chunks}
162     prelude_env = page.prelude_env()
163     template_env.update(prelude_env)
164     result=render_to_response ('view-unfold1.html',template_env,
165                                context_instance=RequestContext(request))
166     return result