plugins.hazelnut: fixed to work without having a query
[myslice.git] / plugins / hazelnut / hazelnut.py
1 from unfold.plugin import Plugin
2
3 class Hazelnut (Plugin):
4
5     # set checkboxes if a final column with checkboxes is desired
6     # pass columns as the initial set of columns
7     #   if None then this is taken from the query's fields
8     def __init__ (self, query=None, query_all_uuid=None, checkboxes=False, columns=None, datatables_options={}, **settings):
9         Plugin.__init__ (self, **settings)
10         self.query          = query
11         self.query_all_uuid = query_all_uuid
12         self.checkboxes=checkboxes
13         if columns is not None:
14             self.columns=columns
15         elif self.query:
16             self.columns=self.query.fields
17         else:
18             self.columns = []
19         self.datatables_options=datatables_options
20
21     def template_file (self):
22         return "hazelnut.html"
23
24     def template_env (self, request):
25         env={}
26         env.update(self.__dict__)
27         env['columns']=self.columns
28         return env
29
30     def requirements (self):
31         reqs = {
32             'js_files' : [ "js/hazelnut.js", 
33                            "js/manifold.js", "js/manifold-query.js", 
34                            "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js",
35                            "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", 
36                            "js/unfold-helper.js",
37                            ] ,
38             'css_files': [ "css/hazelnut.css" , 
39                            "css/dataTables.bootstrap.css",
40                            ],
41             }
42         return reqs
43
44     # the list of things passed to the js plugin
45     def json_settings_list (self):
46         return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes','datatables_options']