1 # just one instance of QueryGrid, 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.querygrid import QueryGrid
14 class QueryGridView (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)
28 'resource.hostname', 'resource.type',
29 'resource.network_hrn',
32 #'application.measurement_point.counter'
34 # for internal use in the querygrid plugin;
35 # needs to be a unique column present for each returned record
36 main_query_init_key = 'hostname'
38 query_resource_all = Query.get('resource').select(resource_fields)
40 aq = AnalyzedQuery(main_query, metadata=metadata)
41 page.enqueue_query(main_query, analyzed_query=aq)
42 page.enqueue_query(query_resource_all)
44 sq_resource = aq.subquery('resource')
46 resources_as_list = QueryGrid(
48 domid = 'resources-list',
50 # this is the query at the core of the slice list
52 query_all = query_resource_all,
53 # safer to use 'hrn' as the internal unique key for this plugin
54 init_key = main_query_init_key,
56 datatables_options = {
58 'bLengthChange' : True,
63 # variables that will get passed to the view-unfold1.html template
66 # define 'unfold_main' to the template engine - the main contents
67 template_env [ 'unfold_main' ] = resources_as_list.render(request)
69 # more general variables expected in the template
70 template_env [ 'title' ] = 'simple %(slicename)s'%locals()
71 # the menu items on the top
72 template_env [ 'topmenu_items' ] = topmenu_items_live('Slice', page)
73 # so we can sho who is logged
74 template_env [ 'username' ] = the_user (request)
76 # the prelude object in page contains a summary of the requirements() for all plugins
77 # define {js,css}_{files,chunks}
78 prelude_env = page.prelude_env()
79 template_env.update(prelude_env)
80 result=render_to_response ('view-unfold1.html',template_env,
81 context_instance=RequestContext(request))