2 plugins - same query
[unfold.git] / trash / dashboard.py
1 # Create your views here.
2
3 from django.core.context_processors import csrf
4 from django.template import RequestContext
5 from django.template.loader import render_to_string
6 from django.shortcuts import render_to_response
7
8 from django.contrib.auth.decorators import login_required
9
10 from engine.pluginset import PluginSet
11 from engine.manifoldquery import ManifoldQuery
12
13 from plugins.slicelist import SliceList
14
15
16 from myslice.viewutils import topmenu_items, the_user
17
18 @login_required
19 def dashboard_view (request):
20     
21     pluginset = PluginSet(request)
22
23     slices_query = ManifoldQuery (action='get',
24                                   method='slice',
25                                   timestamp='latest',
26                                   fields=['slice_hrn'],
27                                   # xxx filter : should filter on the slices the logged user can see
28                                   # we don't have the user's hrn yet
29                                   # in addition this currently returns all slices anyways
30                                   # filter = ...
31                                   sort='slice_hrn',)
32     pluginset.enqueue_query (slices_query)
33
34     main_plugin = SliceList ( # setting visible attributes first
35         pluginset=pluginset,
36         title='Asynchroneous SliceList',
37         header='slices list', 
38         with_datatables=False,
39         toggled=True,
40         # this is the query at the core of the slice list
41         query=slices_query,
42         )
43
44     # variables that will get passed to the view-plugin.html template
45     template_env = {}
46     
47     # define 'content_main' to the template engine
48     template_env [ 'content_main' ] = main_plugin.render(request)
49
50 #    ########## add another plugin with the same request, on the RHS pane
51 #    # lacks a/href to /slice/%s
52 #    related_plugin = SliceList (title='SliceList plugin',domid='slicelist1',
53 #                                with_datatables='yes', 
54 #                                list=hard_wired_slice_names, 
55 #                                header='Slices')
56 #    # likewise but on the side view
57 #    template_env [ 'content_related' ] = related_plugin.render (request)
58
59     # more general variables expected in the template
60     template_env [ 'title' ] = 'Test view for a full request cycle'
61     # the menu items on the top 
62     template_env [ 'topmenu_items' ] = topmenu_items('dashboard', request) 
63     # so we can sho who is logged
64     template_env [ 'username' ] = the_user (request) 
65
66     ##########
67     # lacks a/href to /slice/%s
68     related_plugin = SliceList (
69         pluginset=pluginset,
70         title='Same request, other layout',
71         domid='sidelist',
72         with_datatables=True, 
73         header='paginated slices',
74         # share the query
75         query=slices_query,
76         )
77     # likewise but on the side view
78     template_env [ 'content_related' ] = related_plugin.render (request)
79     
80     # add our own css in the mix
81     pluginset.add_css_files ( 'css/dashboard.css')
82     
83     # don't forget to run the requests
84     pluginset.exec_queue_asynchroneously ()
85
86     # xxx create another plugin with the same query and a different layout (with_datatables)
87     # show that it worls as expected, one single api call to backend and 2 refreshed views
88
89     # the prelude object in pluginset contains a summary of the requirements() for all plugins
90     # define {js,css}_{files,chunks}
91     prelude_env = pluginset.template_env()
92     template_env.update(prelude_env)
93     return render_to_response ('view-plugin.html',template_env,
94                                context_instance=RequestContext(request))