Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
1255:b1fb57e9176d | 1256:08cd652dea14 |
---|---|
148 @param parse_url(callable, None): if set it will be called to handle the URL path | 148 @param parse_url(callable, None): if set it will be called to handle the URL path |
149 after this method, the page will be rendered if noting is left in path | 149 after this method, the page will be rendered if noting is left in path |
150 (request.postpath) else a the request will be transmitted to a subpage | 150 (request.postpath) else a the request will be transmitted to a subpage |
151 @param prepare_render(callable, None): if set, will be used to prepare the | 151 @param prepare_render(callable, None): if set, will be used to prepare the |
152 rendering. That often means gathering data using the bridge | 152 rendering. That often means gathering data using the bridge |
153 @param render(callable, None): if not template is set, this method will be | 153 @param render(callable, None): if template is not set, this method will be |
154 called and what it returns will be rendered. | 154 called and what it returns will be rendered. |
155 This method is mutually exclusive with template and must return a unicode | 155 This method is mutually exclusive with template and must return a unicode |
156 string. | 156 string. |
157 @param template(unicode, None): path to the template to render. | 157 @param template(unicode, None): path to the template to render. |
158 This method is mutually exclusive with render | 158 This method is mutually exclusive with render |
895 elif 'before' in params: | 895 elif 'before' in params: |
896 extra['rsm_before'] = params['before'] | 896 extra['rsm_before'] = params['before'] |
897 return extra | 897 return extra |
898 | 898 |
899 def setPagination(self, request, pubsub_data): | 899 def setPagination(self, request, pubsub_data): |
900 """Add to template_data if suitable | 900 """Add to template_data if suitable |
901 | 901 |
902 "previous_page_url" and "next_page_url" will be added using respectively | 902 "previous_page_url" and "next_page_url" will be added using respectively |
903 "before" and "after" URL parameters | 903 "before" and "after" URL parameters |
904 @param request(server.Request): current HTTP request | 904 @param request(server.Request): current HTTP request |
905 @param pubsub_data(dict): pubsub metadata parsed with | 905 @param pubsub_data(dict): pubsub metadata parsed with |
1317 template_data['locale'] = session_data.locale | 1317 template_data['locale'] = session_data.locale |
1318 if self.vhost_root.site_name: | 1318 if self.vhost_root.site_name: |
1319 template_data['site'] = self.vhost_root.site_name | 1319 template_data['site'] = self.vhost_root.site_name |
1320 if self.dyn_data: | 1320 if self.dyn_data: |
1321 for data in self.dyn_data.values(): | 1321 for data in self.dyn_data.values(): |
1322 template_data_dyn = data.get('template', {}) | |
1323 try: | 1322 try: |
1324 scripts = template_data_dyn['scripts'] | 1323 scripts = data['scripts'] |
1325 except KeyError: | 1324 except KeyError: |
1326 pass | 1325 pass |
1327 else: | 1326 else: |
1328 template_data.setdefault('scripts', []).extend(scripts) | 1327 template_data.setdefault('scripts', []).extend(scripts) |
1329 template_data.update(template_data_dyn) | 1328 template_data.update(data.get('template', {})) |
1329 common_scripts = self.vhost_root.dyn_data_common['scripts'] | |
1330 if common_scripts: | |
1331 template_data.setdefault('scripts', []).extend(common_scripts) | |
1330 | 1332 |
1331 return self.host.renderer.render( | 1333 return self.host.renderer.render( |
1332 self.template, | 1334 self.template, |
1333 page_url=self.getURL(), | 1335 page_url=self.getURL(), |
1334 media_path="/" + C.MEDIA_DIR, | 1336 media_path=f"/{C.MEDIA_DIR}", |
1335 cache_path=session_data.cache_dir, | 1337 cache_path=session_data.cache_dir, |
1336 build_path="/" + C.BUILD_DIR + "/", | 1338 build_path=f"/{C.BUILD_DIR}/", |
1337 main_menu=self.main_menu, | 1339 main_menu=self.main_menu, |
1338 **template_data) | 1340 **template_data) |
1339 | 1341 |
1340 def _renderEb(self, failure_, request): | 1342 def _renderEb(self, failure_, request): |
1341 """don't raise error on CancelError""" | 1343 """don't raise error on CancelError""" |