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