9b97b7a322dfc29b7258d38288d84a8e9470247c
[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                                 sort='slice_hrn',
35                                 )
36     page.enqueue_query (main_query)
37
38     main_plugin = Stack (
39         page=page,
40         title="global container",
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 #                toggled=False,
48                 active_domid='checkboxes',
49                 sons=[
50                     Hazelnut ( 
51                         page=page,
52                         title='a sample and simple hazelnut',
53                         domid='simple',
54 #                        togglable=False,
55                         # this is the query at the core of the slice list
56                         query=main_query,
57                         ),
58                     Hazelnut ( 
59                         page=page,
60                         title='with checkboxes',
61                         domid='checkboxes',
62 #                        togglable=False,
63                         checkboxes=True,
64                         # this is the query at the core of the slice list
65                         query=main_query,
66                         ),
67                     ]),
68               Hazelnut ( 
69                 page=page,
70                 title='not in tabs',
71                 domid='standalone',
72 #                toggled=False,
73                 # this is the query at the core of the slice list
74                 query=main_query,
75                 ),
76               QueryCode (
77                 page=page,
78                 title='xmlrpc code',
79                 query=main_query,
80 #                toggled=False,
81                 ),
82               ])
83
84     # variables that will get passed to the view-unfold1.html template
85     template_env = {}
86     
87     # define 'unfold1_main' to the template engine - the main contents
88     template_env [ 'unfold1_main' ] = main_plugin.render(request)
89
90     # more general variables expected in the template
91     template_env [ 'title' ] = 'Test view for hazelnut'
92     # the menu items on the top
93     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
94     # so we can sho who is logged
95     template_env [ 'username' ] = the_user (request) 
96
97     # don't forget to run the requests
98     page.exec_queue_asynchroneously ()
99
100     # xxx create another plugin with the same query and a different layout (with_datatables)
101     # show that it worls as expected, one single api call to backend and 2 refreshed views
102
103     # the prelude object in page contains a summary of the requirements() for all plugins
104     # define {js,css}_{files,chunks}
105     prelude_env = page.prelude_env()
106     template_env.update(prelude_env)
107     result=render_to_response ('view-unfold1.html',template_env,
108                                context_instance=RequestContext(request))
109     print 'result=',result
110     return result