diff libervia/server/pages.py @ 1268:e628724530ec

pages, tasks (brython): use set for scripts + common template data: - scripts are put in a set using a namedtuple, this way duplicates can be avoided easily - if `template` is set in dyn_data_common, items there are set in template data if they don't already exist - (brython): common template data is used to set body_onload when there is a root brython script and no page script
author Goffi <goffi@goffi.org>
date Tue, 19 May 2020 11:05:40 +0200
parents b5f920845d34
children 6dfcdbeb0d33
line wrap: on
line diff
--- a/libervia/server/pages.py	Tue May 19 11:02:33 2020 +0200
+++ b/libervia/server/pages.py	Tue May 19 11:05:40 2020 +0200
@@ -1332,11 +1332,16 @@
                 except KeyError:
                     pass
                 else:
-                    template_data.setdefault('scripts', []).extend(scripts)
+                    template_data.setdefault('scripts', set()).update(scripts)
                 template_data.update(data.get('template', {}))
-        common_scripts = self.vhost_root.dyn_data_common['scripts']
+        data_common = self.vhost_root.dyn_data_common
+        common_scripts = data_common['scripts']
         if common_scripts:
-            template_data.setdefault('scripts', []).extend(common_scripts)
+            template_data.setdefault('scripts', set()).update(common_scripts)
+            if "template" in data_common:
+                for key, value in data_common["template"].items():
+                    if key not in template_data:
+                        template_data[key] = value
 
         return self.host.renderer.render(
             self.template,