Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / portal / platformsview.py
1 from manifold.core.query         import Query
2 from unfold.page                 import Page
3
4 from unfold.loginrequired       import FreeAccessView
5 from ui.topmenu                  import topmenu_items_live, the_user
6
7 from plugins.querytable          import QueryTable
8 from myslice.theme import ThemeView
9
10 # View for platforms
11 class PlatformsView(FreeAccessView, ThemeView):
12     template_name = "platforms.html"
13
14     def get_context_data(self, **kwargs):
15         page = Page(self.request)
16         page.add_js_files  ( [ "js/common.functions.js" ] )
17         platform_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform','platform_longname','gateway_type')
18         #platform_query  = Query().get('local:platform').select('platform','platform_longname','gateway_type')
19         page.enqueue_query(platform_query)
20
21         page.expose_js_metadata()
22         platformlist = QueryTable(
23             page  = page,
24             title = 'List',
25             domid = 'checkboxes',
26             # this is the query at the core of the slice list
27             query = platform_query,
28             query_all = platform_query,
29             checkboxes = False,
30             init_key   = 'platform',
31             datatables_options = { 
32                 'iDisplayLength': 10,
33                 'bLengthChange' : True,
34                 'bAutoWidth'    : True,
35                 },
36         )
37
38         context = super(PlatformsView, self).get_context_data(**kwargs)
39         context['person']   = self.request.user
40         context['platforms'] = platformlist.render(self.request)
41
42         # XXX This is repeated in all pages
43         # more general variables expected in the template
44         context['title'] = 'Platforms connected to MySlice'
45         # the menu items on the top
46         context['topmenu_items'] = topmenu_items_live('Platforms', page)
47         # so we can sho who is logged
48         context['username'] = the_user(self.request)
49         context['theme'] = self.theme
50         context.update(page.prelude_env())
51
52         context['layout_1_or_2']="layout-unfold2.html" if not context['username'] else "layout-unfold1.html"
53
54         return context