Mercurial > libervia-web
diff libervia/server/server.py @ 1132:0cafb79ced6d
server: use site names in _moveFirstLevelToDict to better distinguish values for default site at first level + better handling of default menu
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Sep 2018 21:16:53 +0200 |
parents | 9cf592d1e6aa |
children | ef565839dada |
line wrap: on
line diff
--- a/libervia/server/server.py Tue Sep 18 21:16:51 2018 +0200 +++ b/libervia/server/server.py Tue Sep 18 21:16:53 2018 +0200 @@ -1753,12 +1753,15 @@ return os.path.join(u'/', C.TPL_RESOURCE, template_data.site or u'sat', C.TEMPLATE_TPL_DIR, template_data.theme, relative_url) - def _moveFirstLevelToDict(self, options, key): + def _moveFirstLevelToDict(self, options, key, keys_to_keep): """Read a config option and put value at first level into u'' dict This is useful to put values for Libervia official site directly in dictionary, and to use site_name as keys when external sites are used. options will be modified in place + @param options(dict): options to modify + @param key(unicode): setting key to modify + @param keys_to_keep(list(unicode)): keys allowed in first level """ try: conf = options[key] @@ -1767,27 +1770,30 @@ if not isinstance(conf, dict): options[key] = {u'': conf} return - default_dict = conf.setdefault(u'', {}) + default_dict = conf.get(u'', {}) to_delete = [] for key, value in conf.iteritems(): - # "/" can't be present in host name, and help to differenciate from - # non vhost dict (which may be used in redirections) - if not isinstance(value, dict) or u'/' in key: + if key not in keys_to_keep: default_dict[key] = value to_delete.append(key) for key in to_delete: del conf[key] + if default_dict: + conf[u''] = default_dict def backendReady(self, __): self.media_dir = self.bridge.getConfig("", "media_dir") self.local_dir = self.bridge.getConfig("", "local_dir") self.cache_root_dir = os.path.join(self.local_dir, C.CACHE_DIR) + self.renderer = template.Renderer(self, self._front_url_filter) + sites_names = self.renderer.sites_paths.keys() - self._moveFirstLevelToDict(self.options, "url_redirections_dict") - self._moveFirstLevelToDict(self.options, "menu_json") + self._moveFirstLevelToDict(self.options, "url_redirections_dict", sites_names) + self._moveFirstLevelToDict(self.options, "menu_json", sites_names) + if not u'' in self.options["menu_json"]: + self.options["menu_json"][u''] = C.DEFAULT_MENU # we create virtual hosts and import Libervia pages into them - self.renderer = template.Renderer(self, self._front_url_filter) self.vhost_root = vhost.NameVirtualHost() default_site_path = os.path.dirname(libervia.__file__) # self.sat_root is official Libervia site