9509dc0a3ef2d73c07b5d100a72bd8a34a703257
[myslice.git] / plugins / hazelnut / __init__.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=None, checkboxes=False, columns=None, datatables_options={}, **settings):
9         Plugin.__init__ (self, **settings)
10         self.query          = query
11         # Until we have a proper way to access queries in Python
12         self.query_all      = query_all
13         self.query_all_uuid = query_all.query_uuid if query_all else None
14         self.checkboxes=checkboxes
15         # XXX We need to have some hidden columns until we properly handle dynamic queries
16         if columns is not None:
17             self.columns=columns
18             self.hidden_columns = []
19         elif self.query:
20             self.columns = self.query.fields
21             if query_all:
22                 # We need a list because sets are not JSON-serilizable
23                 self.hidden_columns = list(self.query_all.fields - self.query.fields)
24             else:
25                 self.hidden_columns = []
26         else:
27             self.columns = []
28             self.hidden_columns = []
29         self.datatables_options=datatables_options
30
31     def template_file (self):
32         return "hazelnut.html"
33
34     def template_env (self, request):
35         env={}
36         env.update(self.__dict__)
37         env['columns']=self.columns
38         return env
39
40     def requirements (self):
41         reqs = {
42             'js_files' : [ "js/hazelnut.js", 
43                            "js/manifold.js", "js/manifold-query.js", 
44                            "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js",
45                            "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js", 
46                            "js/unfold-helper.js",
47                            ] ,
48             'css_files': [ "css/hazelnut.css" , 
49                            "css/dataTables.bootstrap.css",
50                            ],
51             }
52         return reqs
53
54     # the list of things passed to the js plugin
55     def json_settings_list (self):
56         return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', 'hidden_columns']