From 2ee87efb920392a07bc3511ecf503871997c0dbb Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 21 Dec 2012 14:13:42 +0100 Subject: [PATCH] add the exclude_from_json() mechanism to keep control on the amount of conext exposed to js --- engine/plugin.py | 5 +++++ plugins/simplelist.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/plugin.py b/engine/plugin.py index 4ae6fbf8..4fb42119 100644 --- a/engine/plugin.py +++ b/engine/plugin.py @@ -106,6 +106,8 @@ class Plugin: # NOTE this plugin_uuid thing might occur in js files, ** do not rename ** js_env = { 'plugin_uuid' : self.domid } js_env.update (self._settings) + for k in self.exclude_from_json(): + if k in js_env: del js_env[k] settings_json = json.dumps (js_env, separators=(',',':')) env ['settings_json' ] = settings_json # compute plugin-specific initialization @@ -211,3 +213,6 @@ class Plugin: # 'css_chunk': [], # likewise for css scripts # } + # for better performance + # you can specify a list of keys that won't be exposed as json attributes + def exclude_from_json (self): return [] diff --git a/plugins/simplelist.py b/plugins/simplelist.py index cdbe540b..5821bfbe 100644 --- a/plugins/simplelist.py +++ b/plugins/simplelist.py @@ -9,7 +9,7 @@ class SimpleList (Plugin) : Plugin.__init__ (self, **settings) self.list=list # don't expose this as it's big and -# self.add_to_settings ('list') + self.add_to_settings ('list') self.with_datatables = with_datatables self.add_to_settings ('with_datatables') @@ -27,3 +27,6 @@ class SimpleList (Plugin) : # for tests # 'js_chunks' : "/* a javascript chunk */", # 'css_chunks': "/* a css style */ ", + + def exclude_from_json (self): + return ['list'] -- 2.43.0