96dfa66a42b4815b284069f0fca8bd6459b72415
[myslice.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.tabs import Tabs
10 from plugins.simplelist import SimpleList
11 from plugins.slicelist import SliceList
12 from plugins.raw import Raw
13
14 from myslice.viewutils import topmenu_items, the_user
15 from myslice.viewutils import hard_wired_slice_names, hard_wired_list, lorem_p, lorem
16
17 def test_plugin_view (request):
18     
19     # variables that will get passed to this template
20     template_env = {}
21     
22     main_plugin = \
23         VerticalLayout ( title='title for the vertical layout',name='vertical1',
24         sons = [ SimpleList (title='SimpleList and dataTables',
25                                               name='simplelist1',
26                                               list=hard_wired_list, 
27                                               header='Hard wired', 
28                                               foo='the value for foo',
29                                               with_datatables=True),
30                                   Tabs (title='Sample Tabs',name='tabs1',
31                                         active='raw1',
32                                         sons = [ Raw (title='a raw plugin',name='raw1',
33                                                       hidable=False,
34                                                       html= 3*lorem_p),
35                                                  SliceList(title='a slice list',name='slicelist-main',
36                                                            hidable=False,
37                                                            list=hard_wired_slice_names),
38                                                  Raw (title='raw title',name='raw2',
39                                                       hidable=False,html=lorem) ]),
40                                   SimpleList (title='SimpleList with slice names', 
41                                               name='simplelist2',
42                                               list=hard_wired_slice_names,
43                                               ) ] )
44     # define 'content_main' to the template engine
45     template_env [ 'content_main' ] = main_plugin.render(request)
46
47     ##########
48     # lacks a/href to /slice/%s
49     related_plugin = SliceList (title='SliceList plugin',name='slicelist1',
50                                 with_datatables='yes', 
51                                 list=hard_wired_slice_names, 
52                                 header='Slices')
53     # likewise but on the side view
54     template_env [ 'content_related' ] = related_plugin.render (request)
55
56     # more general variables expected in the template
57     template_env [ 'title' ] = 'Test Plugin View' 
58     template_env [ 'topmenu_items' ] = topmenu_items('plugin', request) 
59     template_env [ 'username' ] = the_user (request) 
60
61     # request.plugin_prelude holds a summary of the requirements() for all plugins
62     # define {js,css}_{files,chunks}
63     prelude_env = request.plugin_prelude.template_env()
64     template_env.update(prelude_env)
65
66     return render_to_response ('view-plugin.html',template_env,
67                                context_instance=RequestContext(request))
68