toggling is broken within tabs, add a third hazenut for debugging purposes
[unfold.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.lists.slicelist import SliceList
15 from plugins.querycode.querycode import QueryCode
16 from plugins.quickfilter.quickfilter import QuickFilter
17
18 from myslice.viewutils import quickfilter_criterias
19
20 from myslice.viewutils import topmenu_items, the_user
21
22 tmp_default_slice='ple.inria.sfatest'
23
24 @login_required
25 def slice_view (request, slicename=tmp_default_slice):
26     
27     page = Page(request)
28
29     main_query = ManifoldQuery (action='get',
30                                 subject='resource',
31                                 timestamp='latest',
32                                 fields=['hrn','hostname'],
33                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
34                                 # xxx filter : should filter on the slices the logged user can see
35                                 # we don't have the user's hrn yet
36                                 # in addition this currently returns all slices anyways
37                                 # filter = ...
38                                 sort='slice_hrn',
39                                 )
40     page.enqueue_query (main_query)
41
42     main_plugin = Stack (
43         page=page,
44         title="global container",
45         domid='thestack',
46 #        togglable=False,
47         sons=[Tabs (
48                 page=page,
49                 title="2 tabs : w/ and w/o checkboxes",
50                 domid='thetabs',
51                 toggled=False,
52                 active_domid='checkboxes',
53                 sons=[
54                     Hazelnut ( 
55                         page=page,
56                         title='a sample and simple hazelnut',
57                         domid='simple',
58 #                        togglable=False,
59                         # this is the query at the core of the slice list
60                         query=main_query,
61                         ),
62                     Hazelnut ( 
63                         page=page,
64                         title='with checkboxes',
65                         domid='checkboxes',
66 #                        togglable=False,
67                         checkboxes=True,
68                         # this is the query at the core of the slice list
69                         query=main_query,
70                         ),
71                     ]),
72               Hazelnut ( 
73                 page=page,
74                 title='not in tabs',
75                 domid='standalone',
76                 toggled=False,
77                 # this is the query at the core of the slice list
78                 query=main_query,
79                 ),
80               QueryCode (
81                 page=page,
82                 title='xmlrpc code',
83                 query=main_query,
84                 toggled=False,
85                 ),
86               ])
87
88     # variables that will get passed to the view-unfold2.html template
89     template_env = {}
90     
91     # define 'unfold2_main' to the template engine
92     template_env [ 'unfold1_main' ] = main_plugin.render(request)
93
94     # more general variables expected in the template
95     template_env [ 'title' ] = 'Test view for hazelnut'
96     # the menu items on the top
97     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
98     # so we can sho who is logged
99     template_env [ 'username' ] = the_user (request) 
100
101 ### #   ########## add another plugin with the same request, on the RHS pane
102 ### #   will show up in the right-hand side area named 'related'
103 ###     related_plugin = SliceList (
104 ###         page=page,
105 ###         title='Same request, other layout',
106 ###         domid='sidelist',
107 ###         with_datatables=True, 
108 ###         header='paginated main',
109 ###         # share the query
110 ###         query=main_query,
111 ###         )
112 ###     # likewise but on the side view
113 ###     template_env [ 'unfold2_margin' ] = related_plugin.render (request)
114 ###     
115 ###     # add our own css in the mix
116 ###     page.add_css_files ( 'css/hazelnut.css')
117     
118     # don't forget to run the requests
119     page.exec_queue_asynchroneously ()
120
121     # xxx create another plugin with the same query and a different layout (with_datatables)
122     # show that it worls as expected, one single api call to backend and 2 refreshed views
123
124     # the prelude object in page contains a summary of the requirements() for all plugins
125     # define {js,css}_{files,chunks}
126     prelude_env = page.prelude_env()
127     template_env.update(prelude_env)
128     result=render_to_response ('view-unfold1.html',template_env,
129                                context_instance=RequestContext(request))
130     print 'result=',result
131     return result