Merge branch 'fibre' of ssh://git.onelab.eu/git/myslice into fibre
[unfold.git] / sample / dashboardview.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.core.query import Query
12
13 from plugins.stack import Stack
14 from plugins.lists.slicelist import SliceList
15 from plugins.querycode import QueryCode
16 from plugins.quickfilter import QuickFilter
17
18 from trashutils import quickfilter_criterias
19
20
21 from ui.topmenu import topmenu_items_live, the_user
22
23 @login_required
24 def dashboard_view (request):
25     
26     page = Page(request)
27
28     slices_query = Query.get('slice').select('slice_hrn')
29 #old#                                  # xxx filter : should filter on the slices the logged user can see
30 #old#                                  # we don't have the user's hrn yet
31 #old#                                  # in addition this currently returns all slices anyways
32 #old#                                  # filter = ...
33 #old#                                  sort='slice_hrn',)
34     page.enqueue_query (slices_query)
35
36     main_plugin = Stack (
37         page=page,
38         title="Putting stuff together",
39         sons=[ 
40             QueryCode (
41                 page=page,
42                 title="Vizualize your query",
43                 query=slices_query,
44                 toggled=False,
45                 ),
46             QuickFilter (
47                 # we play with this one for demo purposes in dashboard.css
48                 domid='myquickfilter',
49                 page=page,
50                 title='play with filters',
51                 criterias=quickfilter_criterias,
52                 toggled=False,
53                 ),
54             SliceList ( # setting visible attributes first
55                 page=page,
56                 title='Asynchroneous SliceList',
57                 header='slices list', 
58                 with_datatables=False,
59                 # this is the query at the core of the slice list
60                 query=slices_query,
61                 ),
62             ])
63
64     # variables that will get passed to the view-unfold2.html template
65     template_env = {}
66     
67     # define 'unfold_main' to the template engine
68     template_env [ 'unfold_main' ] = main_plugin.render(request)
69
70     # more general variables expected in the template
71     template_env [ 'title' ] = 'Test view for a full request cycle'
72     # the menu items on the top 
73     template_env [ 'topmenu_items' ] = topmenu_items_live('dashboard', page) 
74     # so we can sho who is logged
75     template_env [ 'username' ] = the_user (request) 
76
77 #   ########## add another plugin with the same request, on the RHS pane
78 #   will show up in the right-hand side area named 'related'
79     related_plugin = SliceList (
80         page=page,
81         title='Same request, other layout',
82         domid='sidelist',
83         with_datatables=True, 
84         header='paginated slices',
85         # share the query
86         query=slices_query,
87         )
88     # likewise but on the side view
89     template_env [ 'unfold_margin' ] = related_plugin.render (request)
90     
91     # add our own css in the mix
92     #page.add_css_files ( 'css/dashboard.css')
93     
94     # the prelude object in page contains a summary of the requirements() for all plugins
95     # define {js,css}_{files,chunks}
96     prelude_env = page.prelude_env()
97     template_env.update(prelude_env)
98     return render_to_response ('view-unfold2.html',template_env,
99                                context_instance=RequestContext(request))