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