Mercurial > libervia-web
comparison libervia/server/server.py @ 1258:92ff09cdd6dd
server: gather themes data:
- the new LiberviaRootResource's `site_themes` attribute is a set of available themes for
a site, it is set a template variable for pages.
- if `browser_meta` are available for a theme, the metadata are merged with pages root
`_browser` data
- if python files are found in `browser_path`, they are added to be handled by brython
task.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 May 2020 19:28:14 +0200 |
parents | 1ec41ac1e7cf |
children | 6b7f9c3558cc |
comparison
equal
deleted
inserted
replaced
1257:1ec41ac1e7cf | 1258:92ff09cdd6dd |
---|---|
48 from sat.tools import utils | 48 from sat.tools import utils |
49 from sat.tools import config | 49 from sat.tools import config |
50 from sat.tools.common import regex | 50 from sat.tools.common import regex |
51 from sat.tools.common import template | 51 from sat.tools.common import template |
52 from sat.tools.common import uri as common_uri | 52 from sat.tools.common import uri as common_uri |
53 from sat.tools.common.utils import recursive_update | |
53 import libervia | 54 import libervia |
54 from libervia.server import websockets | 55 from libervia.server import websockets |
55 from libervia.server.pages import LiberviaPage | 56 from libervia.server.pages import LiberviaPage |
56 from libervia.server.utils import quote, ProgressHandler | 57 from libervia.server.utils import quote, ProgressHandler |
57 from libervia.server.tasks.manager import TasksManager | 58 from libervia.server.tasks.manager import TasksManager |
182 ProtectedFile.__init__(self, *args, **kwargs) | 183 ProtectedFile.__init__(self, *args, **kwargs) |
183 self.host = host | 184 self.host = host |
184 self.host_name = host_name | 185 self.host_name = host_name |
185 self.site_name = site_name | 186 self.site_name = site_name |
186 self.site_path = Path(site_path) | 187 self.site_path = Path(site_path) |
188 self.site_themes = set() | |
187 self.named_pages = {} | 189 self.named_pages = {} |
188 self.browser_modules = {} | 190 self.browser_modules = {} |
189 # template dynamic data used in all pages | 191 # template dynamic data used in all pages |
190 self.dyn_data_common = {"scripts": []} | 192 self.dyn_data_common = {"scripts": []} |
193 for theme, data in host.renderer.getThemesData(site_name).items(): | |
194 # we check themes for browser metadata, and merge them here if found | |
195 self.site_themes.add(theme) | |
196 browser_meta = data.get('browser_meta') | |
197 if browser_meta is not None: | |
198 log.debug(f"merging browser metadata from theme {theme}: {browser_meta}") | |
199 recursive_update(self.browser_modules, browser_meta) | |
200 browser_path = data.get('browser_path') | |
201 if browser_path is not None: | |
202 self.browser_modules.setdefault('themes_browser_paths', set()).add( | |
203 browser_path) | |
204 try: | |
205 next(browser_path.glob("*.py")) | |
206 except StopIteration: | |
207 pass | |
208 else: | |
209 log.debug(f"found brython script(s) for theme {theme}") | |
210 self.browser_modules.setdefault('brython', []).append( | |
211 { | |
212 "path": browser_path, | |
213 "url_hash": None, | |
214 "url_prefix": f"__t_{theme}" | |
215 } | |
216 ) | |
217 | |
191 self.uri_callbacks = {} | 218 self.uri_callbacks = {} |
192 self.pages_redirects = {} | 219 self.pages_redirects = {} |
193 self.cached_urls = {} | 220 self.cached_urls = {} |
194 self.main_menu = None | 221 self.main_menu = None |
195 self.build_path = host.getBuildPath(site_name) | 222 self.build_path = host.getBuildPath(site_name) |