From: Christian Heller Date: Sun, 17 Mar 2024 00:54:01 +0000 (+0100) Subject: Move TEMPLATES_DIR setting into run.py. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/condition_titles?a=commitdiff_plain;h=30bc39c0af52c9fc474d3be0c040b7effe761187;p=plomtask Move TEMPLATES_DIR setting into run.py. --- diff --git a/plomtask/http.py b/plomtask/http.py index 4ce72ec..baa730e 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -7,15 +7,13 @@ from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader from plomtask.days import Day from plomtask.misc import HandledException -TEMPLATES_DIR = 'templates' - class TaskServer(HTTPServer): """Variant of HTTPServer that knows .jinja as Jinja Environment.""" - def __init__(self, *args, **kwargs): - x = super().__init__(*args, **kwargs) - self.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR)) + def __init__(self, templates_dir, *args, **kwargs): + super().__init__(*args, **kwargs) + self.jinja = JinjaEnv(loader=JinjaFSLoader(templates_dir)) class TaskHandler(BaseHTTPRequestHandler): diff --git a/run.py b/run.py index 644fc4a..d94905d 100755 --- a/run.py +++ b/run.py @@ -5,11 +5,13 @@ from plomtask.misc import HandledException from plomtask.http import TaskHandler, TaskServer HTTP_PORT = 8082 +TEMPLATES_DIR = 'templates' if __name__ == '__main__': try: - server = TaskServer(('localhost', HTTP_PORT), TaskHandler) + server = TaskServer(TEMPLATES_DIR, + ('localhost', HTTP_PORT), TaskHandler) print(f'running at port {HTTP_PORT}') try: server.serve_forever()