mgt/slice tab: show only the first user (TO BE MODIFIED)
[myslice.git] / sample / 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.core.query                import Query
12
13 from plugins.stack                      import Stack
14 from plugins.tabs                       import Tabs
15 from plugins.lists.staticlist           import StaticList
16 from plugins.quickfilter                import QuickFilter
17 from plugins.querycode                  import QueryCode
18 from plugins.raw                        import Raw
19 from plugins.messages                   import Messages
20 from plugins.querytable                 import QueryTable
21
22 from ui.topmenu                         import topmenu_items_live, the_user
23 from trashutils                         import hard_wired_slice_names, hard_wired_list, lorem_p, lorem, quickfilter_criterias
24
25 #might be useful or not depending on the context
26 #@login_required
27 def test_plugin_view (request):
28
29     page = Page(request)
30     
31     page.expose_js_metadata()
32
33     # variables that will get passed to this template
34     template_env = {}
35     
36     slicename='ple.inria.heartbeat'
37     main_query = Query.get('resource').filter_by('slice_hrn', '=', slicename).select(['network','type','hrn','hostname','sliver'])
38     # without an querytable, this would use use : run_it=False as nothing would listen to the results
39     page.enqueue_query (main_query, # run_it=False
40                         )
41
42     main_plugin = \
43         Stack (
44         page=page,
45         title='thestack',
46         togglable=True,
47         domid='stack',
48         sons=[ \
49         # make sure the 2 things work together
50             Messages (
51                     page=page,
52                     title="Transient Runtime messages",
53                     domid="messages-transient",
54                     levels='ALL',
55                     ),
56             QueryTable (
57                     page=page,
58                     title="Slice %s - checkboxes"%slicename,
59                     query=main_query,
60                     domid="querytable",
61                     checkboxes=True,
62                     togglable=True,
63                     ),
64             Messages (
65                     page=page,
66                     title="Inline Runtime messages",
67                     domid="messages",
68                     levels='ALL',
69                     togglable=True,
70                     transient=False,
71                     ),
72             Raw (
73                     page=page,
74                     title="issue messages",
75                     togglable=True,
76                     html="""
77 <input type="button" id="bouton" value="Click me" />
78 """,
79                     ),
80             ])
81
82     page.add_js_chunks ( """
83 function issue_debug() {console.log("issue_debug");messages.debug("issue_debug");};
84 $(function(){$("#bouton").click(issue_debug);});
85 """)
86
87     # define 'unfold_main' to the template engine
88     template_env [ 'unfold_main' ] = main_plugin.render(request)
89
90     # more general variables expected in the template
91     template_env [ 'title' ] = 'Single Plugin View' 
92     template_env [ 'topmenu_items' ] = topmenu_items_live('plugin', page) 
93     template_env [ 'username' ] = the_user (request) 
94
95     # the prelude object in page contains a summary of the requirements() for all plugins
96     # define {js,css}_{files,chunks}
97     prelude_env = page.prelude_env()
98     template_env.update(prelude_env)
99     return render_to_response ('view-unfold1.html',template_env,
100                                context_instance=RequestContext(request))
101