comparison 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
comparison
equal deleted inserted replaced
1274:eb4f03da0d7d 1275:334d044f2713
179 ProtectedFile.__init__(self, *args, **kwargs) 179 ProtectedFile.__init__(self, *args, **kwargs)
180 self.host = host 180 self.host = host
181 self.host_name = host_name 181 self.host_name = host_name
182 self.site_name = site_name 182 self.site_name = site_name
183 self.site_path = Path(site_path) 183 self.site_path = Path(site_path)
184 self.default_theme = self.getConfig('theme', C.TEMPLATE_THEME_DEFAULT)
184 self.site_themes = set() 185 self.site_themes = set()
185 self.named_pages = {} 186 self.named_pages = {}
186 self.browser_modules = {} 187 self.browser_modules = {}
187 # template dynamic data used in all pages 188 # template dynamic data used in all pages
188 self.dyn_data_common = {"scripts": set()} 189 self.dyn_data_common = {"scripts": set()}
225 self.build_path, 226 self.build_path,
226 defaultType="application/octet-stream"), 227 defaultType="application/octet-stream"),
227 ) 228 )
228 229
229 def __str__(self): 230 def __str__(self):
230 return ("Root resource for {host_name} using {site_name} at {site_path} and " 231 return (
231 "deserving files at {path}".format( 232 f"Root resource for {self.host_name or 'default host'} using "
232 host_name=self.host_name, site_name=self.site_name, 233 f"{self.site_name or 'default site'} at {self.site_path} and deserving "
233 site_path=self.site_path, path=self.path)) 234 f"files at {self.path}"
235 )
236
237 def getConfig(self, key, default=None, value_type=None):
238 """Retrieve configuration for this site
239
240 params are the same as for [Libervia.getConfig]
241 """
242 return self.host.getConfig(self, key, default, value_type)
243
234 244
235 def _initRedirections(self, options): 245 def _initRedirections(self, options):
236 url_redirections = options["url_redirections_dict"] 246 url_redirections = options["url_redirections_dict"]
237 247
238 url_redirections = url_redirections.get(self.site_name, {}) 248 url_redirections = url_redirections.get(self.site_name, {})
738 by a well known suffix ("_path", "_list", "_dict", or "_json") 748 by a well known suffix ("_path", "_list", "_dict", or "_json")
739 None to use no filter, else can be: 749 None to use no filter, else can be:
740 - "path": a path is expected, will be normalized and expanded 750 - "path": a path is expected, will be normalized and expanded
741 751
742 """ 752 """
743 section = site_root_res.site_name.lower().strip() 753 section = site_root_res.site_name.lower().strip() or C.CONFIG_SECTION
744 value = config.getConfig(self.main_conf, section, key, default=default) 754 value = config.getConfig(self.main_conf, section, key, default=default)
745 if value_type is not None: 755 if value_type is not None:
746 if value_type == 'path': 756 if value_type == 'path':
747 v_filter = lambda v: os.path.abspath(os.path.expanduser(v)) 757 v_filter = lambda v: os.path.abspath(os.path.expanduser(v))
748 else: 758 else: