1 # just one instance of QueryTable, nothing more, nothing less
2 from django.views.generic.base import TemplateView
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
6 from manifold.core.query import Query, AnalyzedQuery
8 from unfold.page import Page
10 from ui.topmenu import topmenu_items_live, the_user
12 from plugins.querytable import QueryTable
14 class QueryTableView (TemplateView):
16 def get (self, request, slicename='ple.inria.f14'):
19 page.expose_js_metadata()
20 metadata = page.get_metadata()
21 resource_md = metadata.details_by_object('resource')
22 resource_fields = [column['name'] for column in resource_md['column']]
24 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
27 'resource.hostname', 'resource.type',
28 'resource.network_hrn',
31 #'application.measurement_point.counter'
33 # for internal use in the querytable plugin;
34 # needs to be a unique column present for each returned record
35 main_query_init_key = 'hostname'
37 query_resource_all = Query.get('resource').select(resource_fields)
39 aq = AnalyzedQuery(main_query, metadata=metadata)
40 page.enqueue_query(main_query, analyzed_query=aq)
41 page.enqueue_query(query_resource_all)
43 sq_resource = aq.subquery('resource')
45 resources_as_list = QueryTable(
47 domid = 'resources-list',
49 # this is the query at the core of the slice list
51 query_all = query_resource_all,
52 # safer to use 'hrn' as the internal unique key for this plugin
53 init_key = main_query_init_key,
55 datatables_options = {
57 'bLengthChange' : True,
62 # variables that will get passed to the view-unfold1.html template
65 # define 'unfold_main' to the template engine - the main contents
66 template_env [ 'unfold_main' ] = resources_as_list.render(request)
68 # more general variables expected in the template
69 template_env [ 'title' ] = 'simple %(slicename)s'%locals()
70 # the menu items on the top
71 template_env [ 'topmenu_items' ] = topmenu_items_live('Slice', page)
72 # so we can sho who is logged
73 template_env [ 'username' ] = the_user (request)
75 # the prelude object in page contains a summary of the requirements() for all plugins
76 # define {js,css}_{files,chunks}
77 prelude_env = page.prelude_env()
78 template_env.update(prelude_env)
79 result=render_to_response ('view-unfold1.html',template_env,
80 context_instance=RequestContext(request))