efc353b9ebbb5081df4b225762582e9f57c7f18a
[myslice.git] / trash / pluginview.py
1 # Create your views here.
2
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
7
8 from django.contrib.auth.decorators import login_required
9
10 from unfold.page import Page
11 from manifold.manifoldquery import ManifoldQuery
12
13 from plugins.stack.stack import Stack
14 from plugins.tabs.tabs import Tabs
15 from plugins.lists.staticlist import StaticList
16 from plugins.quickfilter.quickfilter import QuickFilter
17 from plugins.querycode.querycode import QueryCode
18 from plugins.raw.raw import Raw
19 from plugins.messages.messages import Messages
20 from plugins.hazelnut.hazelnut import Hazelnut
21 from plugins.updater.updater import Updater
22
23 from myslice.viewutils import topmenu_items, the_user
24 from myslice.viewutils import hard_wired_slice_names, hard_wired_list, lorem_p, lorem, quickfilter_criterias
25
26 @login_required
27 def test_plugin_view (request):
28
29     page = Page(request)
30     
31     # variables that will get passed to this template
32     template_env = {}
33     
34     slicename='ple.inria.heartbeat'
35     main_query = ManifoldQuery (action='get',
36                                 subject='resource',
37                                 timestamp='latest',
38                                 fields=['network','type','hrn','hostname','sliver'],
39                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
40                                 )
41     # without an hazelnut, this would use use : run_it=False as nothing would listen to the results
42     page.enqueue_query (main_query, # run_it=False
43                         )
44
45     main_plugin = \
46         Stack (
47         page=page,
48         title='thestack',
49         togglable=False,
50         domid='stack',
51         sons=[ \
52             Updater (
53                     page=page,
54                     title="wont show up as non togglable by default",
55                     query=main_query,
56                     label="Update me",
57                     domid="the-updater",
58                     ),
59             # make sure the 2 things work together
60             Hazelnut (
61                     page=page,
62                     title="Slice %s - checkboxes interacting w/ updater"%slicename,
63                     query=main_query,
64                     domid="hazelnut",
65                     checkboxes=True,
66                     ),
67             Messages (
68                     page=page,
69                     title="Runtime messages",
70                     domid="msgs-pre",
71                     levels='ALL',
72                     ),
73             ])
74
75     # define 'unfold1_main' to the template engine
76     template_env [ 'unfold1_main' ] = main_plugin.render(request)
77
78     # more general variables expected in the template
79     template_env [ 'title' ] = 'Single Plugin View' 
80     template_env [ 'topmenu_items' ] = topmenu_items('plugin', request) 
81     template_env [ 'username' ] = the_user (request) 
82
83     # run queries when we have any
84     page.expose_queries ()
85
86     # the prelude object in page contains a summary of the requirements() for all plugins
87     # define {js,css}_{files,chunks}
88     prelude_env = page.prelude_env()
89     template_env.update(prelude_env)
90     return render_to_response ('view-unfold1.html',template_env,
91                                context_instance=RequestContext(request))
92