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