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