Async support for prepare_jinja2_environment, closes #1809

This commit is contained in:
Simon Willison 2022-09-16 20:38:15 -07:00
commit ddc999ad12
10 changed files with 76 additions and 9 deletions

View file

@ -143,8 +143,14 @@ def extra_template_vars(
@hookimpl
def prepare_jinja2_environment(env, datasette):
env.filters["format_numeric"] = lambda s: f"{float(s):,.0f}"
env.filters["to_hello"] = lambda s: datasette._HELLO
async def select_times_three(s):
db = datasette.get_database()
return (await db.execute("select 3 * ?", [int(s)])).first()[0]
async def inner():
env.filters["select_times_three"] = select_times_three
return inner
@hookimpl

View file

@ -126,6 +126,12 @@ def permission_allowed(datasette, actor, action):
return inner
@hookimpl
def prepare_jinja2_environment(env, datasette):
env.filters["format_numeric"] = lambda s: f"{float(s):,.0f}"
env.filters["to_hello"] = lambda s: datasette._HELLO
@hookimpl
def startup(datasette):
async def inner():