added request for metadata calls to be able to handle errors in messages
[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 ui.topmenu                  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         auth_query  = Query().get('network').select('network_hrn','platform')
26         # DEMO GEC18 Query only PLE
27         slice_query = Query().get('user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
28         page.enqueue_query(slice_query)
29         page.enqueue_query(auth_query)
30
31         page.expose_js_metadata()
32         page.expose_queries()
33
34         slicelist = SimpleList(
35             title = None,
36             page  = page,
37             key   = 'slice.slice_hrn',
38             query = slice_query,
39         )
40         # XXX TODO: plugins/lists/static/js/simplelist.js => hardcoded keys that give links : slice_hrn & platform
41         authlist = SimpleList(
42             title = None,
43             page  = page,
44             key   = 'platform',
45             query = auth_query,
46         )
47  
48         context = super(DashboardView, self).get_context_data(**kwargs)
49         context['person']   = self.request.user
50         context['networks'] = authlist.render(self.request) 
51         context['slices']   = slicelist.render(self.request)
52
53         # XXX This is repeated in all pages
54         # more general variables expected in the template
55         context['title'] = 'Dashboard'
56         # the menu items on the top
57         context['topmenu_items'] = topmenu_items('Dashboard', self.request) 
58         # so we can sho who is logged
59         context['username'] = the_user(self.request) 
60
61         context.update(page.prelude_env())
62
63         return context
64