diff --git a/capport-example.yaml b/capport-example.yaml index 1f50aa6..6cc2c14 100644 --- a/capport-example.yaml +++ b/capport-example.yaml @@ -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 diff --git a/src/capport/api/app_cls.py b/src/capport/api/app_cls.py index 2676628..a0a05f7 100644 --- a/src/capport/api/app_cls.py +++ b/src/capport/api/app_cls.py @@ -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") + 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 diff --git a/src/capport/config.py b/src/capport/config.py index 664b0a7..0e8a9b2 100644 --- a/src/capport/config.py +++ b/src/capport/config.py @@ -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: