From: Christian Heller Date: Wed, 20 Mar 2024 01:22:08 +0000 (+0100) Subject: Move TEMPLATES_DIR constant into web server module. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/%7B%7Bdb.prefix%7D%7D/tasks?a=commitdiff_plain;h=c675dc8a489ef6e495a643473fab16fa5c261e27;p=plomtask Move TEMPLATES_DIR constant into web server module. --- diff --git a/plomtask/http.py b/plomtask/http.py index 8106d13..01a949e 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -8,14 +8,16 @@ from plomtask.days import Day from plomtask.misc import HandledException from plomtask.db import DatabaseConnection +TEMPLATES_DIR = 'templates' + class TaskServer(HTTPServer): """Variant of HTTPServer that knows .jinja as Jinja Environment.""" - def __init__(self, templates_dir, db_file, *args, **kwargs): + def __init__(self, db_file, *args, **kwargs): super().__init__(*args, **kwargs) self.db = db_file - self.jinja = JinjaEnv(loader=JinjaFSLoader(templates_dir)) + self.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR)) class TaskHandler(BaseHTTPRequestHandler): diff --git a/run.py b/run.py index 3334637..31d11ce 100755 --- a/run.py +++ b/run.py @@ -8,7 +8,6 @@ from plomtask.db import DatabaseFile PLOMTASK_DB_PATH = environ.get('PLOMTASK_DB_PATH') HTTP_PORT = 8082 -TEMPLATES_DIR = 'templates' DB_CREATION_ASK = 'Database file not found. Create? Y/n\n' @@ -25,8 +24,7 @@ if __name__ == '__main__': else: print('Not recognizing reply as "yes".') raise HandledException('Cannot run without database.') - server = TaskServer(TEMPLATES_DIR, db_file, - ('localhost', HTTP_PORT), TaskHandler) + server = TaskServer(db_file, ('localhost', HTTP_PORT), TaskHandler) print(f'running at port {HTTP_PORT}') try: server.serve_forever()