2 from manifold.core.query import Query
3 from manifold.manifoldapi import execute_query
5 from unfold.page import Page
7 from plugins.lists.testbedlist import TestbedList
8 from plugins.lists.slicelist import SliceList
10 from unfold.loginrequired import LoginRequiredAutoLogoutView
12 from ui.topmenu import topmenu_items_live, the_user
14 #This view requires login
15 class DashboardView (LoginRequiredAutoLogoutView):
17 template_name = "dashboard.html"
19 def get_context_data(self, **kwargs):
20 # We might have slices on different registries with different user accounts
21 # 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
22 # Different registries mean different identities, unless we identify via SFA HRN or have associated the user email to a single hrn
24 #messages.info(self.request, 'You have logged in')
25 page = Page(self.request)
27 print "Dashboard page"
29 #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn')
30 testbed_query = Query().get('network').select('network_hrn','platform')
31 # DEMO GEC18 Query only PLE
32 # user_query = Query().get('local:user').select('config','email')
33 # user_details = execute_query(self.request, user_query)
35 # not always found in user_details...
37 # for user_detail in user_details:
38 # #email = user_detail['email']
39 # if user_detail['config']:
40 # config = json.loads(user_detail['config'])
41 # user_detail['authority'] = config.get('authority',"Unknown Authority")
44 # if user_detail['authority'] is not None:
45 # sub_authority = user_detail['authority'].split('.')
46 # root_authority = sub_authority[0]
47 # slice_query = Query().get(root_authority+':user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
49 slice_query = Query().get('user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
50 page.enqueue_query(slice_query)
51 page.enqueue_query(testbed_query)
53 slicelist = SliceList(
58 testbedlist = TestbedList(
61 query = testbed_query,
64 context = super(DashboardView, self).get_context_data(**kwargs)
65 context['person'] = self.request.user
66 context['testbeds'] = testbedlist.render(self.request)
67 context['slices'] = slicelist.render(self.request)
69 # XXX This is repeated in all pages
70 # more general variables expected in the template
71 context['title'] = 'Dashboard'
72 # the menu items on the top
73 context['topmenu_items'] = topmenu_items_live('Dashboard', page)
74 # so we can sho who is logged
75 context['username'] = the_user(self.request)
77 page.expose_js_metadata()
79 # the page header and other stuff
80 context.update(page.prelude_env())