portal: improved user and slice request/validation
[myslice.git] / trash / sampleviews.py
1 # Create your views here.
2 from django.core.context_processors import csrf
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5 from django.contrib.auth.decorators import login_required
6
7 from unfold.prelude import Prelude
8
9 from ui.topmenu import topmenu_items, the_user
10 # tmp
11 from trash.trashutils import lorem, hard_wired_slice_names
12
13 @login_required
14 def tab_view (request):
15     print "request", request.__class__
16     print request
17     prelude=Prelude( js_files='js/bootstrap.js', css_files='css/bootstrap.css')
18     prelude_env = prelude.prelude_env()
19
20     tab_env = {'title':'Page for playing with Tabs',
21                'topmenu_items': topmenu_items('tab',request),
22                'username':the_user (request),
23                'lorem': lorem,                                
24                }
25     tab_env.update (prelude_env)
26     return render_to_response ('view-tab.html', tab_env,
27                                context_instance=RequestContext(request))
28
29 def scroll_view (request):
30     return render_to_response ('view-scroll.html',
31                                {'title':'Toy page for scrolling',
32                                 'topmenu_items': topmenu_items('scroll',request),
33                                 'username':the_user (request),
34                                 'lorem':lorem,
35                                 },
36                                context_instance=RequestContext(request))
37
38 @login_required
39 def test_plugin_view (request):
40
41     page = Page(request)
42     
43     # variables that will get passed to this template
44     template_env = {}
45     
46     main_plugin = \
47         Stack ( page=page,
48                 title='title for the vertical layout',
49                 sons = [ StaticList (page=page,
50                                      title='StaticList - with datatables - starts toggled off',
51                                      list=hard_wired_list, 
52                                      header='Hard wired header', 
53                                      foo='the value for foo',
54                                      with_datatables=True,
55                                      toggled=False),
56                          Tabs (page=page,
57                                title='Sample Tabs',
58                                domid='test-tabs',
59                                # *** we select this one to be the active tab ***
60                                active_domid='son2',
61                                sons = [ Raw (page=page,
62                                              title='a raw plugin',
63                                              domid='son0',
64                                              togglable=False,
65                                              html= 3*lorem_p,
66                                              ),
67                                         StaticList(page=page,
68                                                    title='a slice list',
69                                                    domid='son1',
70                                                    togglable=False,
71                                                    header="static list but not togglable",
72                                                    list=hard_wired_slice_names,
73                                                    ),
74                                         Raw (page=page,
75                                              title='raw title',
76                                              domid='son2',
77                                              togglable=False,
78                                              html=lorem) ]),
79                          StaticList (page=page,
80                                      title='SimpleList with slice names', 
81                                      list=hard_wired_slice_names,
82                                      ),
83                          QuickFilter (page=page,
84                                       title='QuickFilter in main content',
85                                       criterias=quickfilter_criterias,
86                                       ) ] )
87     # define 'unfold2_main' to the template engine
88     template_env [ 'unfold2_main' ] = main_plugin.render(request)
89
90     ##########
91     related_plugin = StaticList (page=page,
92                                  title='SliceList plugin',domid='slicelist1',
93                                  with_datatables='yes', 
94                                  list=hard_wired_slice_names, 
95                                  header='Slices')
96     # likewise but on the side view
97     template_env [ 'unfold2_margin' ] = related_plugin.render (request)
98
99     # more general variables expected in the template
100     template_env [ 'title' ] = 'Test Plugin View' 
101     template_env [ 'topmenu_items' ] = topmenu_items('plugin', request) 
102     template_env [ 'username' ] = the_user (request) 
103
104     # we don't have anythong asynchroneous, and manifold.js is not loaded
105 #    page.expose_queries ()
106
107     # the prelude object in page contains a summary of the requirements() for all plugins
108     # define {js,css}_{files,chunks}
109     prelude_env = page.prelude_env()
110     template_env.update(prelude_env)
111     return render_to_response ('view-unfold2.html',template_env,
112                                context_instance=RequestContext(request))
113