in query, 'method' is now called 'subject'
[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.stack.stack import Stack
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                                   subject='slice',
30                                   timestamp='latest',
31                                   fields=['slice_hrn'],
32                                   filters=[],
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     page.enqueue_query (slices_query)
39
40     main_plugin = Stack (
41         page=page,
42         title="Putting stuff together",
43         sons=[ 
44             QueryCode (
45                 page=page,
46                 title="Vizualize your query (no syntax highlight for now)",
47                 query=slices_query,
48                 toggled=False,
49                 ),
50             QuickFilter (
51                 # we play with this one for demo purposes in dashboard.css
52                 domid='myquickfilter',
53                 page=page,
54                 title='play with filters',
55                 criterias=quickfilter_criterias,
56                 toggled=False,
57                 ),
58             SliceList ( # setting visible attributes first
59                 page=page,
60                 title='Asynchroneous SliceList',
61                 header='slices list', 
62                 with_datatables=False,
63                 # this is the query at the core of the slice list
64                 query=slices_query,
65                 ),
66             ])
67
68     # variables that will get passed to the view-plugin.html template
69     template_env = {}
70     
71     # define 'unfold1_main' to the template engine
72     template_env [ 'unfold1_main' ] = main_plugin.render(request)
73
74     # more general variables expected in the template
75     template_env [ 'title' ] = 'Test view for a full request cycle'
76     # the menu items on the top 
77     template_env [ 'topmenu_items' ] = topmenu_items('dashboard', request) 
78     # so we can sho who is logged
79     template_env [ 'username' ] = the_user (request) 
80
81 #   ########## add another plugin with the same request, on the RHS pane
82 #   will show up in the right-hand side area named 'related'
83     related_plugin = SliceList (
84         page=page,
85         title='Same request, other layout',
86         domid='sidelist',
87         with_datatables=True, 
88         header='paginated slices',
89         # share the query
90         query=slices_query,
91         )
92     # likewise but on the side view
93     template_env [ 'unfold1_margin' ] = related_plugin.render (request)
94     
95     # add our own css in the mix
96     page.add_css_files ( 'css/dashboard.css')
97     
98     # don't forget to run the requests
99     page.exec_queue_asynchroneously ()
100
101     # xxx create another plugin with the same query and a different layout (with_datatables)
102     # show that it worls as expected, one single api call to backend and 2 refreshed views
103
104     # the prelude object in page contains a summary of the requirements() for all plugins
105     # define {js,css}_{files,chunks}
106     prelude_env = page.prelude_env()
107     template_env.update(prelude_env)
108     return render_to_response ('view-plugin.html',template_env,
109                                context_instance=RequestContext(request))