home · contact · privacy
Move TEMPLATES_DIR setting into run.py.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 17 Mar 2024 00:54:01 +0000 (01:54 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 17 Mar 2024 00:54:01 +0000 (01:54 +0100)
plomtask/http.py
run.py

index 4ce72ec69e823f07f4ce718cd82aea66024f9c0d..baa730ed7a77272982cb03c8ec61ea76f22d0a12 100644 (file)
@@ -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 644fc4abbf5aa7fcc1e7cd410d931e0f1af8798f..d94905dc69bc97379567fb3f79d5f7288c7bbc57 100755 (executable)
--- 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()