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