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