From 026d72f29f3e87b3d24e6151261ef070e94893e2 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 28 Dec 2024 16:21:33 +0100 Subject: [PATCH] Added template support. --- setup.cfg | 1 + src/app/app.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/setup.cfg b/setup.cfg index 18b36bd..73749db 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,7 @@ package_dir = python_requires = >=3.7 install_requires = aiohttp + aiohttp-jinja2 dataset ipython openai diff --git a/src/app/app.py b/src/app/app.py index 09ceaa8..99a5d7c 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -4,6 +4,9 @@ import json import time import uuid +import aiohttp_jinja2 +import jinja2 + import dataset from aiohttp import web @@ -29,6 +32,7 @@ class BaseApplication(RPCApplication): basic_password=None, cookie_name=None, session=None, + template_path=None, *args, **kwargs, ): @@ -40,6 +44,7 @@ class BaseApplication(RPCApplication): middlewares.append(self.request_middleware) middlewares.append(self.base64_auth_middleware) middlewares.append(self.session_middleware) + self.template_path = template_path and template_path or pathlib.Path(__file__).parent / "templates" self.agents = {} super().__init__(middlewares=middlewares, *args, **kwargs) @@ -98,6 +103,9 @@ class BaseApplication(RPCApplication): return await handler(request) + async def render_template(self, name, request, context): + return aiohttp_jinja2.render_template(name, request=self.request, context) + @web.middleware async def request_middleware(self, request: web.Request, handler): time_start = time.time()