make path of custom templates and static files configurable
This commit is contained in:
parent
a7dc356dd9
commit
5c5a309934
@ -11,4 +11,5 @@ server-names:
|
||||
- ...
|
||||
api-port: 8000
|
||||
controller-port: 5000
|
||||
custom: custom # path of custom templates and static files
|
||||
database-file: capport.state
|
||||
|
@ -48,14 +48,16 @@ class MyQuartApp(quart_trio.QuartTrio):
|
||||
def __init__(self, import_name: str, **kwargs) -> None:
|
||||
self.my_config = capport.config.Config.load_default_once()
|
||||
kwargs.setdefault("template_folder", os.path.join(os.path.dirname(__file__), "templates"))
|
||||
cust_templ = os.path.join("custom", "templates")
|
||||
if os.path.exists(cust_templ):
|
||||
self.custom_loader = jinja2.FileSystemLoader(os.fspath(cust_templ))
|
||||
cust_static = os.path.abspath(os.path.join("custom", "static"))
|
||||
if os.path.exists(cust_static):
|
||||
static_folder = cust_static
|
||||
else:
|
||||
static_folder = os.path.join(os.path.dirname(__file__), "static")
|
||||
if self.my_config.custom:
|
||||
cust_templ = os.path.join(self.my_config.custom, "templates")
|
||||
if os.path.exists(cust_templ):
|
||||
# prepend custom templates to search path
|
||||
self.custom_loader = jinja2.FileSystemLoader(os.fspath(cust_templ))
|
||||
cust_static = os.path.abspath(os.path.join(self.my_config.custom, "static"))
|
||||
if os.path.exists(cust_static):
|
||||
# overwrite static folder
|
||||
static_folder = cust_static
|
||||
kwargs.setdefault("static_folder", static_folder)
|
||||
super().__init__(import_name, **kwargs)
|
||||
self.debug = self.my_config.debug
|
||||
|
@ -22,6 +22,7 @@ class Config:
|
||||
api_port: int
|
||||
controller_port: int
|
||||
database_file: str # empty str: disable database
|
||||
custom: str
|
||||
debug: bool
|
||||
|
||||
@staticmethod
|
||||
@ -58,6 +59,7 @@ class Config:
|
||||
api_port=data.pop("api-port", 8000),
|
||||
controller_port=data.pop("controller-port", 5000),
|
||||
database_file=str(data.pop("database-file", "capport.state")),
|
||||
custom=str(data.pop("custom", "custom")),
|
||||
debug=data.pop("debug", False),
|
||||
)
|
||||
if data:
|
||||
|
Loading…
Reference in New Issue
Block a user