2 from manifold.core.query import Query
3 from manifoldapi.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 from myslice.theme import ThemeView
16 #This view requires login
17 class DashboardView (LoginRequiredAutoLogoutView, ThemeView):
19 template_name = "dashboard.html"
21 def get_context_data(self, **kwargs):
22 # We might have slices on different registries with different user accounts
23 # 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
24 # Different registries mean different identities, unless we identify via SFA HRN or have associated the user email to a single hrn
25 #messages.info(self.request, 'You have logged in')
26 page = Page(self.request)
28 print "Dashboard page"
30 #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn')
31 testbed_query = Query().get('network').select('network_hrn','platform','version')
32 # DEMO GEC18 Query only PLE
33 # user_query = Query().get('local:user').select('config','email')
34 # user_details = execute_query(self.request, user_query)
36 # not always found in user_details...
38 # for user_detail in user_details:
39 # #email = user_detail['email']
40 # if user_detail['config']:
41 # config = json.loads(user_detail['config'])
42 # user_detail['authority'] = config.get('authority',"Unknown Authority")
45 # if user_detail['authority'] is not None:
46 # sub_authority = user_detail['authority'].split('.')
47 # root_authority = sub_authority[0]
48 # slice_query = Query().get(root_authority+':user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
52 slice_query = Query().get('user').filter_by('user_hrn', '==', '$user_hrn').select('slices.slice_hrn')
53 page.enqueue_query(slice_query)
54 page.enqueue_query(testbed_query)
56 slicelist = SliceList(
59 warning_msg = "<a href='../slice_request'>Request Slice</a>",
62 testbedlist = TestbedList(
65 query = testbed_query,
68 context = super(DashboardView, self).get_context_data(**kwargs)
69 context['person'] = self.request.user
70 context['testbeds'] = testbedlist.render(self.request)
71 context['slices'] = slicelist.render(self.request)
73 # XXX This is repeated in all pages
74 # more general variables expected in the template
75 context['title'] = 'Dashboard'
76 # the menu items on the top
77 context['topmenu_items'] = topmenu_items_live('Dashboard', page)
78 # so we can sho who is logged
79 context['username'] = the_user(self.request)
81 context['theme'] = self.theme
83 page.expose_js_metadata()
85 # the page header and other stuff
86 context.update(page.prelude_env())