Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/libervia/server/pages.py Tue May 19 11:05:47 2020 +0200 +++ b/libervia/server/pages.py Tue May 19 11:05:50 2020 +0200 @@ -1345,6 +1345,7 @@ return self.host.renderer.render( self.template, + theme=session_data.theme, site_themes=self.vhost_root.site_themes, page_url=self.getURL(), media_path=f"/{C.MEDIA_DIR}", @@ -1666,6 +1667,24 @@ if session_data.locale is None: self.setBestLocale(request) + # theme + key_theme = C.KEY_THEME.encode() + if key_theme in request.args: + try: + theme = request.args.pop(key_theme)[0].decode() + except IndexError: + theme = C.TEMPLATE_THEME_DEFAULT + else: + if key_theme != session_data.theme: + if theme not in self.vhost_root.site_themes: + log.warning(_( + "Theme {theme!r} doesn't exist for {vhost}, using " + "default one") + .format(theme=theme, vhost=self.vhost_root)) + else: + session_data.theme = theme + + d = defer.Deferred() d.addCallback(self._checkAccess, request)