diff libervia/server/server.py @ 1275:334d044f2713

server: default theme can now be specified in site section of `sat.conf` with `theme` key
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:50 +0200
parents eb4f03da0d7d
children 0e4e413eb8db
line wrap: on
line diff
--- a/libervia/server/server.py	Fri May 29 21:56:42 2020 +0200
+++ b/libervia/server/server.py	Fri Jun 19 16:47:50 2020 +0200
@@ -181,6 +181,7 @@
         self.host_name = host_name
         self.site_name = site_name
         self.site_path = Path(site_path)
+        self.default_theme = self.getConfig('theme', C.TEMPLATE_THEME_DEFAULT)
         self.site_themes = set()
         self.named_pages = {}
         self.browser_modules = {}
@@ -227,10 +228,19 @@
         )
 
     def __str__(self):
-        return ("Root resource for {host_name} using {site_name} at {site_path} and "
-                "deserving files at {path}".format(
-                host_name=self.host_name, site_name=self.site_name,
-                site_path=self.site_path, path=self.path))
+        return (
+            f"Root resource for {self.host_name or 'default host'} using "
+            f"{self.site_name or 'default site'} at {self.site_path} and deserving "
+            f"files at {self.path}"
+        )
+
+    def getConfig(self, key, default=None, value_type=None):
+        """Retrieve configuration for this site
+
+        params are the same as for [Libervia.getConfig]
+        """
+        return self.host.getConfig(self, key, default, value_type)
+
 
     def _initRedirections(self, options):
         url_redirections = options["url_redirections_dict"]
@@ -740,7 +750,7 @@
                 - "path": a path is expected, will be normalized and expanded
 
         """
-        section = site_root_res.site_name.lower().strip()
+        section = site_root_res.site_name.lower().strip() or C.CONFIG_SECTION
         value = config.getConfig(self.main_conf, section, key, default=default)
         if value_type is not None:
             if value_type == 'path':