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