Plugin now has __repr__
[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         togglable=False,
46         sons=[Tabs (
47                 page=page,
48                 title="different angles",
49                 active_domid='with-checkboxes',
50                 sons=[
51                     Hazelnut ( 
52                         page=page,
53                         title='a sample and simple hazelnut',
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='with-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               QueryCode (
69                 page=page,
70                 title='xmlrpc code',
71                 query=main_query,
72                 toggled=False,
73                 ),
74               ])
75
76     # variables that will get passed to the view-plugin.html template
77     template_env = {}
78     
79     # define 'unfold1_main' to the template engine
80     template_env [ 'unfold1_main' ] = main_plugin.render(request)
81
82     # more general variables expected in the template
83     template_env [ 'title' ] = 'Test view for hazelnut'
84     # the menu items on the top
85     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
86     # so we can sho who is logged
87     template_env [ 'username' ] = the_user (request) 
88
89 ### #   ########## add another plugin with the same request, on the RHS pane
90 ### #   will show up in the right-hand side area named 'related'
91 ###     related_plugin = SliceList (
92 ###         page=page,
93 ###         title='Same request, other layout',
94 ###         domid='sidelist',
95 ###         with_datatables=True, 
96 ###         header='paginated main',
97 ###         # share the query
98 ###         query=main_query,
99 ###         )
100 ###     # likewise but on the side view
101 ###     template_env [ 'unfold1_margin' ] = related_plugin.render (request)
102 ###     
103 ###     # add our own css in the mix
104 ###     page.add_css_files ( 'css/hazelnut.css')
105     
106     # don't forget to run the requests
107     page.exec_queue_asynchroneously ()
108
109     # xxx create another plugin with the same query and a different layout (with_datatables)
110     # show that it worls as expected, one single api call to backend and 2 refreshed views
111
112     # the prelude object in page contains a summary of the requirements() for all plugins
113     # define {js,css}_{files,chunks}
114     prelude_env = page.prelude_env()
115     template_env.update(prelude_env)
116     return render_to_response ('view-plugin.html',template_env,
117                                context_instance=RequestContext(request))