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