Mercurial > libervia-web
diff libervia/server/pages.py @ 1256:08cd652dea14
server, pages, tasks (brython): common_scripts:
- scripts common to all pages can now be put in root `_browser` dir
- `scripts` list is not set in `dyn_data`'s `template` anymore, but directly in a root
`scripts` key (because it's not data which are sent verbatim to the template renderer)
- if an `__init__.py` script is found in root `_browser` dir, brython task will add it to
template scripts.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 May 2020 18:15:22 +0200 |
parents | b1fb57e9176d |
children | 92ff09cdd6dd |
line wrap: on
line diff
--- a/libervia/server/pages.py Sun May 03 17:06:14 2020 +0200 +++ b/libervia/server/pages.py Sun May 03 18:15:22 2020 +0200 @@ -150,7 +150,7 @@ (request.postpath) else a the request will be transmitted to a subpage @param prepare_render(callable, None): if set, will be used to prepare the rendering. That often means gathering data using the bridge - @param render(callable, None): if not template is set, this method will be + @param render(callable, None): if template is not set, this method will be called and what it returns will be rendered. This method is mutually exclusive with template and must return a unicode string. @@ -897,7 +897,7 @@ return extra def setPagination(self, request, pubsub_data): - """Add to template_data if suitable + """Add to template_data if suitable "previous_page_url" and "next_page_url" will be added using respectively "before" and "after" URL parameters @@ -1319,21 +1319,23 @@ template_data['site'] = self.vhost_root.site_name if self.dyn_data: for data in self.dyn_data.values(): - template_data_dyn = data.get('template', {}) try: - scripts = template_data_dyn['scripts'] + scripts = data['scripts'] except KeyError: pass else: template_data.setdefault('scripts', []).extend(scripts) - template_data.update(template_data_dyn) + template_data.update(data.get('template', {})) + common_scripts = self.vhost_root.dyn_data_common['scripts'] + if common_scripts: + template_data.setdefault('scripts', []).extend(common_scripts) return self.host.renderer.render( self.template, page_url=self.getURL(), - media_path="/" + C.MEDIA_DIR, + media_path=f"/{C.MEDIA_DIR}", cache_path=session_data.cache_dir, - build_path="/" + C.BUILD_DIR + "/", + build_path=f"/{C.BUILD_DIR}/", main_menu=self.main_menu, **template_data)