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