mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
row_actions() plugin hook, closes #2299
This commit is contained in:
parent
7339cc51de
commit
b8711988b9
7 changed files with 134 additions and 7 deletions
|
|
@ -53,6 +53,7 @@ EXPECTED_PLUGINS = [
|
|||
"register_permissions",
|
||||
"register_routes",
|
||||
"render_cell",
|
||||
"row_actions",
|
||||
"skip_csrf",
|
||||
"startup",
|
||||
"table_actions",
|
||||
|
|
|
|||
|
|
@ -423,6 +423,18 @@ def query_actions(datasette, database, query_name, sql):
|
|||
]
|
||||
|
||||
|
||||
@hookimpl
|
||||
def row_actions(datasette, database, table, actor, row):
|
||||
if actor:
|
||||
return [
|
||||
{
|
||||
"href": datasette.urls.instance(),
|
||||
"label": f"Row details for {actor['id']}",
|
||||
"description": json.dumps(dict(row), default=repr),
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@hookimpl
|
||||
def database_actions(datasette, database, actor, request):
|
||||
if actor:
|
||||
|
|
|
|||
|
|
@ -1000,6 +1000,24 @@ async def test_hook_query_actions(ds_client, path, expected_url):
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_row_actions(ds_client):
|
||||
response = await ds_client.get("/fixtures/facet_cities/1")
|
||||
assert get_actions_links(response.text) == []
|
||||
|
||||
response_2 = await ds_client.get(
|
||||
"/fixtures/facet_cities/1",
|
||||
cookies={"ds_actor": ds_client.actor_cookie({"id": "sam"})},
|
||||
)
|
||||
assert get_actions_links(response_2.text) == [
|
||||
{
|
||||
"label": "Row details for sam",
|
||||
"href": "/",
|
||||
"description": '{"id": 1, "name": "San Francisco"}',
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_hook_database_actions(ds_client):
|
||||
response = await ds_client.get("/fixtures")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue