1 # Create your views here.
3 from django.core.context_processors import csrf
4 from django.template import RequestContext
5 from django.template.loader import render_to_string
6 from django.shortcuts import render_to_response
8 from django.contrib.auth.decorators import login_required
10 from engine.page import Page
11 from engine.manifoldquery import ManifoldQuery
13 from plugins.slicelist import SliceList
16 from myslice.viewutils import topmenu_items, the_user
19 def dashboard_view (request):
23 slices_query = ManifoldQuery (action='get',
27 # xxx filter : should filter on the slices the logged user can see
28 # we don't have the user's hrn yet
29 # in addition this currently returns all slices anyways
32 page.enqueue_query (slices_query)
34 main_plugin = SliceList ( # setting visible attributes first
36 title='Asynchroneous SliceList',
38 with_datatables=False,
40 # this is the query at the core of the slice list
44 # variables that will get passed to the view-plugin.html template
47 # define 'content_main' to the template engine
48 template_env [ 'content_main' ] = main_plugin.render(request)
50 # ########## add another plugin with the same request, on the RHS pane
51 # # lacks a/href to /slice/%s
52 # related_plugin = SliceList (title='SliceList plugin',domid='slicelist1',
53 # with_datatables='yes',
54 # list=hard_wired_slice_names,
56 # # likewise but on the side view
57 # template_env [ 'content_related' ] = related_plugin.render (request)
59 # more general variables expected in the template
60 template_env [ 'title' ] = 'Test view for a full request cycle'
61 # the menu items on the top
62 template_env [ 'topmenu_items' ] = topmenu_items('dashboard', request)
63 # so we can sho who is logged
64 template_env [ 'username' ] = the_user (request)
67 # lacks a/href to /slice/%s
68 related_plugin = SliceList (
70 title='Same request, other layout',
73 header='paginated slices',
77 # likewise but on the side view
78 template_env [ 'content_related' ] = related_plugin.render (request)
80 # add our own css in the mix
81 page.add_css_files ( 'css/dashboard.css')
83 # don't forget to run the requests
84 page.exec_queue_asynchroneously ()
86 # xxx create another plugin with the same query and a different layout (with_datatables)
87 # show that it worls as expected, one single api call to backend and 2 refreshed views
89 # the prelude object in page contains a summary of the requirements() for all plugins
90 # define {js,css}_{files,chunks}
91 prelude_env = page.template_env()
92 template_env.update(prelude_env)
93 return render_to_response ('view-plugin.html',template_env,
94 context_instance=RequestContext(request))