From 0e901f1b3ab8aef05e5203038cd7590df2cc7f61 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 19 Nov 2023 21:04:14 -0800 Subject: [PATCH] Switch to new config format Refs https://github.com/datasette/datasette-enrichments/issues/18 --- datasette_enrichments_jinja.py | 6 +++--- pyproject.toml | 2 +- tests/test_enrichments_jinja.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/datasette_enrichments_jinja.py b/datasette_enrichments_jinja.py index b13b5a7..61e7666 100644 --- a/datasette_enrichments_jinja.py +++ b/datasette_enrichments_jinja.py @@ -45,7 +45,7 @@ class ConfigForm(Form): async def initialize(self, datasette, db, table, config): # Ensure column exists - output_column = config["output_column"][0] + output_column = config["output_column"] def add_column_if_not_exists(conn): db = sqlite_utils.Database(conn) @@ -65,8 +65,8 @@ async def enrich_batch( job_id: int, ): env = SandboxedEnvironment(enable_async=True) - template = env.from_string(config["template"][0]) - output_column = config["output_column"][0] + template = env.from_string(config["template"]) + output_column = config["output_column"] for row in rows: output = await template.render_async({"row": row}) await db.execute_write( diff --git a/pyproject.toml b/pyproject.toml index 0cc8e3d..83f1fb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ classifiers=[ ] requires-python = ">=3.8" dependencies = [ - "datasette-enrichments>=0.1a3" + "datasette-enrichments>=0.1a4" ] [project.urls] diff --git a/tests/test_enrichments_jinja.py b/tests/test_enrichments_jinja.py index 7f6187f..2e0345a 100644 --- a/tests/test_enrichments_jinja.py +++ b/tests/test_enrichments_jinja.py @@ -15,8 +15,8 @@ async def test_enrichment(tmpdir): {"id": 3, "name": "Three", "description": "Third item"}, ] config = { - "output_column": ["template_output"], - "template": ["{{ row['name'] }}: {{ row['description'] }}"], + "output_column": "template_output", + "template": "{{ row['name'] }}: {{ row['description'] }}", } db["items"].insert_all(rows) ds_db = datasette.get_database("data") @@ -32,8 +32,8 @@ async def test_enrichment(tmpdir): rows=rows, pks=["id"], config={ - "output_column": ["template_output"], - "template": ["{{ row['name'] }}: {{ row['description'] }}"], + "output_column": "template_output", + "template": "{{ row['name'] }}: {{ row['description'] }}", }, job_id=1, )