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