Merge branch 'master' of ssh://git.onelab.eu/git/myslice
[myslice.git] / portal / dashboardview.py
1 from manifold.core.query         import Query
2 from unfold.page                 import Page
3
4 from plugins.lists.simplelist    import SimpleList
5
6 from unfold.loginrequired        import LoginRequiredAutoLogoutView
7
8 from myslice.viewutils           import topmenu_items, the_user
9
10 #This view requires login 
11 class DashboardView (LoginRequiredAutoLogoutView):
12
13     template_name = "dashboard.html"
14     
15     def get_context_data(self, **kwargs):
16         # We might have slices on different registries with different user accounts 
17         # We note that this portal could be specific to a given registry, to which we register users, but i'm not sure that simplifies things
18         # Different registries mean different identities, unless we identify via SFA HRN or have associated the user email to a single hrn
19
20         #messages.info(self.request, 'You have logged in')
21         page = Page(self.request)
22
23         # Slow...
24         #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn')
25         slice_query = Query().get('user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
26         auth_query  = Query().get('network').select('network_hrn')
27         print "AUTH QUERY =====================", auth_query
28         print "filter", auth_query.filters
29         page.enqueue_query(slice_query)
30         page.enqueue_query(auth_query)
31
32         page.expose_js_metadata()
33         page.expose_queries()
34
35         slicelist = SimpleList(
36             title = None,
37             page  = page,
38             key   = 'slice.slice_hrn',
39             query = slice_query,
40         )
41          
42         authlist = SimpleList(
43             title = None,
44             page  = page,
45             key   = 'network_hrn',
46             query = auth_query,
47         )
48
49         context = super(DashboardView, self).get_context_data(**kwargs)
50         context['person']   = self.request.user
51         context['networks'] = authlist.render(self.request) 
52         context['slices']   = slicelist.render(self.request)
53
54         # XXX This is repeated in all pages
55         # more general variables expected in the template
56         context['title'] = 'Test view that combines various plugins'
57         # the menu items on the top
58         context['topmenu_items'] = topmenu_items('Dashboard', self.request) 
59         # so we can sho who is logged
60         context['username'] = the_user(self.request) 
61
62         context.update(page.prelude_env())
63
64         return context
65