comparison libervia/server/pages.py @ 1270:6dfcdbeb0d33

pages: handle themes using `theme` request argument
author Goffi <goffi@goffi.org>
date Tue, 19 May 2020 11:05:50 +0200
parents e628724530ec
children b0b9218c5982
comparison
equal deleted inserted replaced
1269:470c6cfdf4ce 1270:6dfcdbeb0d33
1343 if key not in template_data: 1343 if key not in template_data:
1344 template_data[key] = value 1344 template_data[key] = value
1345 1345
1346 return self.host.renderer.render( 1346 return self.host.renderer.render(
1347 self.template, 1347 self.template,
1348 theme=session_data.theme,
1348 site_themes=self.vhost_root.site_themes, 1349 site_themes=self.vhost_root.site_themes,
1349 page_url=self.getURL(), 1350 page_url=self.getURL(),
1350 media_path=f"/{C.MEDIA_DIR}", 1351 media_path=f"/{C.MEDIA_DIR}",
1351 cache_path=session_data.cache_dir, 1352 cache_path=session_data.cache_dir,
1352 build_path=f"/{C.BUILD_DIR}/", 1353 build_path=f"/{C.BUILD_DIR}/",
1664 1665
1665 # if locale is not specified, we try to find one requested by browser 1666 # if locale is not specified, we try to find one requested by browser
1666 if session_data.locale is None: 1667 if session_data.locale is None:
1667 self.setBestLocale(request) 1668 self.setBestLocale(request)
1668 1669
1670 # theme
1671 key_theme = C.KEY_THEME.encode()
1672 if key_theme in request.args:
1673 try:
1674 theme = request.args.pop(key_theme)[0].decode()
1675 except IndexError:
1676 theme = C.TEMPLATE_THEME_DEFAULT
1677 else:
1678 if key_theme != session_data.theme:
1679 if theme not in self.vhost_root.site_themes:
1680 log.warning(_(
1681 "Theme {theme!r} doesn't exist for {vhost}, using "
1682 "default one")
1683 .format(theme=theme, vhost=self.vhost_root))
1684 else:
1685 session_data.theme = theme
1686
1687
1669 d = defer.Deferred() 1688 d = defer.Deferred()
1670 d.addCallback(self._checkAccess, request) 1689 d.addCallback(self._checkAccess, request)
1671 1690
1672 if self.redirect is not None: 1691 if self.redirect is not None:
1673 d.addCallback( 1692 d.addCallback(