From 30bc39c0af52c9fc474d3be0c040b7effe761187 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 17 Mar 2024 01:54:01 +0100 Subject: [PATCH] Move TEMPLATES_DIR setting into run.py. --- plomtask/http.py | 8 +++----- run.py | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) 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() -- 2.30.2