Skip to content

Commit

Permalink
Switch to new config format
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 20, 2023
1 parent 577cbd2 commit 0e901f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions datasette_enrichments_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ classifiers=[
]
requires-python = ">=3.8"
dependencies = [
"datasette-enrichments>=0.1a3"
"datasette-enrichments>=0.1a4"
]

[project.urls]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_enrichments_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
)
Expand Down

0 comments on commit 0e901f1

Please sign in to comment.