fix prelude/requirements system
[unfold.git] / engine / views.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 plugins.verticallayout import VerticalLayout
9 from plugins.simplelist import SimpleList
10 from plugins.slicelist import SliceList
11
12 from myslice.viewutils import topmenu_items, the_user, hard_wired_slice_names
13
14 def test_plugin_view (request):
15     
16     # variables that will get passed to this template
17     template_env = {}
18     
19     # having html tags right here is not a real use case
20     hard_wired_list=[]
21     hard_wired_list.append("this hard-wired list")
22     hard_wired_list.append("is defined")
23     hard_wired_list.append("in plugins.simplelist.py")
24     hard_wired_list.append("which in turn relies on")
25     hard_wired_list.append("template widget-template.html")
26     hard_wired_list.append("while it should of course")
27     hard_wired_list.append("instead issue a query")
28     hard_wired_list.append("and fill the DOM in js from there")
29     hard_wired_list.append("it would however maybe make sense")
30     hard_wired_list.append("to offer the option to 'datatablify'")
31     hard_wired_list.append("the list from the python code")
32     hard_wired_list.append("just like a standard plugin can be set as visible or not")
33     hard_wired_list.append("")    
34     hard_wired_list.append("OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds")
35
36     plugin_main1 = SimpleList (list=hard_wired_list, 
37                                header='Hard wired', 
38                                foo='the value for foo',
39                                with_datatables=True)
40     plugin_main2 = SimpleList (hidable=True, 
41                                list=hard_wired_slice_names,
42                                headers='Slices in main content')
43     layout = VerticalLayout (hidable=True, visible=True,
44                              sons=[plugin_main1, plugin_main2]
45                              )
46 #    layout.inspect_request (request,"before first render")
47     content_main = layout.render (request)
48 #    layout.inspect_request (request,"after first render")
49     # this will be rendered as the main content - as per view-plugin.html and thus layout-myslice.html
50     template_env [ 'content_main' ] = content_main
51
52     ##########
53     # lacks a/href to /slice/%s
54     plugin_related = SliceList (visible=True, 
55                                 hidable=True,
56                                 with_datatables='yes', 
57                                 list=hard_wired_slice_names, 
58                                 header='Slices' )
59     content_related = plugin_related.render (request)
60     # likewise but on the side view
61     template_env [ 'content_related' ] = content_related
62
63     # more general variables expected in the template
64     template_env [ 'title' ] = 'Test Plugin View' 
65     template_env [ 'topmenu_items' ] = topmenu_items('plugin', request) 
66     template_env [ 'username' ] = the_user (request) 
67
68     # request.plugin_prelude holds a summary of the requirements() for all plugins
69     # define {js,css}_{files,chunks}
70     prelude_env = request.plugin_prelude.render_env()
71     print 'prelude_env',prelude_env
72     template_env.update(prelude_env)
73
74     return render_to_response ('view-plugin.html',template_env,
75                                context_instance=RequestContext(request))
76