more thoroughly disable default services; plus, various comments around
[myslice.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 #from manifold.manifoldquery import ManifoldQuery
13
14 from plugins.stack import Stack
15 from plugins.lists.slicelist import SliceList
16 from plugins.querycode import QueryCode
17 from plugins.quickfilter import QuickFilter
18
19 from trash.trashutils import quickfilter_criterias
20
21
22 from ui.topmenu import topmenu_items_live, the_user
23
24 @login_required
25 def dashboard_view (request):
26     
27     page = Page(request)
28
29     slices_query = Query.get('slice').select('slice_hrn')
30 #old#                                  # xxx filter : should filter on the slices the logged user can see
31 #old#                                  # we don't have the user's hrn yet
32 #old#                                  # in addition this currently returns all slices anyways
33 #old#                                  # filter = ...
34 #old#                                  sort='slice_hrn',)
35     page.enqueue_query (slices_query)
36
37     main_plugin = Stack (
38         page=page,
39         title="Putting stuff together",
40         sons=[ 
41             QueryCode (
42                 page=page,
43                 title="Vizualize your query",
44                 query=slices_query,
45                 toggled=False,
46                 ),
47             QuickFilter (
48                 # we play with this one for demo purposes in dashboard.css
49                 domid='myquickfilter',
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-unfold2.html template
66     template_env = {}
67     
68     # define 'unfold_main' to the template engine
69     template_env [ 'unfold_main' ] = main_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_live('dashboard', page) 
75     # so we can sho who is logged
76     template_env [ 'username' ] = the_user (request) 
77
78 #   ########## add another plugin with the same request, on the RHS pane
79 #   will show up in the right-hand side area named 'related'
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 [ 'unfold_margin' ] = related_plugin.render (request)
91     
92     # add our own css in the mix
93     #page.add_css_files ( 'css/dashboard.css')
94     
95     # the prelude object in page contains a summary of the requirements() for all plugins
96     # define {js,css}_{files,chunks}
97     prelude_env = page.prelude_env()
98     template_env.update(prelude_env)
99     return render_to_response ('view-unfold2.html',template_env,
100                                context_instance=RequestContext(request))