queries don't know how to expose 'sort' yet
[unfold.git] / trash / sliceview.py
1 # Create your views here.
2
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5
6 from django.contrib.auth.decorators import login_required
7
8 from unfold.page import Page
9 from manifold.manifoldquery import ManifoldQuery
10
11 from plugins.stack.stack import Stack
12 from plugins.tabs.tabs import Tabs
13 from plugins.hazelnut.hazelnut import Hazelnut 
14 from plugins.lists.slicelist import SliceList
15 from plugins.querycode.querycode import QueryCode
16 from plugins.quickfilter.quickfilter import QuickFilter
17
18 from myslice.viewutils import quickfilter_criterias
19
20 from myslice.viewutils import topmenu_items, the_user
21
22 tmp_default_slice='ple.inria.sfatest'
23
24 @login_required
25 def slice_view (request, slicename=tmp_default_slice):
26     
27     page = Page(request)
28
29     main_query = ManifoldQuery (action='get',
30                                 subject='resource',
31                                 timestamp='latest',
32                                 fields=['network','type','hrn','hostname'],
33                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
34                                 )
35     page.enqueue_query (main_query)
36
37     main_plugin = Stack (
38         page=page,
39         title="Slice view for %s"%slicename,
40         domid='thestack',
41 #        togglable=False,
42         sons=[Tabs (
43                 page=page,
44                 title="2 tabs : w/ and w/o checkboxes",
45                 domid='thetabs',
46 #                toggled=False,
47                 active_domid='checkboxes',
48                 sons=[
49                     Hazelnut ( 
50                         page=page,
51                         title='a sample and simple hazelnut',
52                         domid='simple',
53 #                        togglable=False,
54                         # this is the query at the core of the slice list
55                         query=main_query,
56                         ),
57                     Hazelnut ( 
58                         page=page,
59                         title='with checkboxes',
60                         domid='checkboxes',
61 #                        togglable=False,
62                         checkboxes=True,
63                         # this is the query at the core of the slice list
64                         query=main_query,
65                         ),
66                     ]),
67               Hazelnut ( 
68                 page=page,
69                 title='not in tabs',
70                 domid='standalone',
71 #                toggled=False,
72                 # this is the query at the core of the slice list
73                 query=main_query,
74                 ),
75               QueryCode (
76                 page=page,
77                 title='xmlrpc code',
78                 query=main_query,
79 #                toggled=False,
80                 ),
81               ])
82
83     # variables that will get passed to the view-unfold1.html template
84     template_env = {}
85     
86     # define 'unfold1_main' to the template engine - the main contents
87     template_env [ 'unfold1_main' ] = main_plugin.render(request)
88
89     # more general variables expected in the template
90     template_env [ 'title' ] = 'Test view for hazelnut'
91     # the menu items on the top
92     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
93     # so we can sho who is logged
94     template_env [ 'username' ] = the_user (request) 
95
96     # don't forget to run the requests
97     page.exec_queue_asynchroneously ()
98
99     # xxx create another plugin with the same query and a different layout (with_datatables)
100     # show that it worls as expected, one single api call to backend and 2 refreshed views
101
102     # the prelude object in page contains a summary of the requirements() for all plugins
103     # define {js,css}_{files,chunks}
104     prelude_env = page.prelude_env()
105     template_env.update(prelude_env)
106     result=render_to_response ('view-unfold1.html',template_env,
107                                context_instance=RequestContext(request))
108     print 'result=',result
109     return result