Expose current SQLite row to render_cell hook, closes #1300

This commit is contained in:
Simon Willison 2022-07-07 09:30:49 -07:00
commit 6373bb3414
6 changed files with 14 additions and 7 deletions

View file

@ -98,12 +98,13 @@ def extra_body_script(
@hookimpl
def render_cell(value, column, table, database, datasette):
def render_cell(row, value, column, table, database, datasette):
async def inner():
# Render some debug output in cell with value RENDER_CELL_DEMO
if value == "RENDER_CELL_DEMO":
return json.dumps(
{
"row": dict(row),
"column": column,
"table": table,
"database": database,

View file

@ -181,12 +181,13 @@ def test_hook_render_cell_demo(app_client):
response = app_client.get("/fixtures/simple_primary_key?id=4")
soup = Soup(response.body, "html.parser")
td = soup.find("td", {"class": "col-content"})
assert {
assert json.loads(td.string) == {
"row": {"id": "4", "content": "RENDER_CELL_DEMO"},
"column": "content",
"table": "simple_primary_key",
"database": "fixtures",
"config": {"depth": "table", "special": "this-is-simple_primary_key"},
} == json.loads(td.string)
}
@pytest.mark.parametrize(