mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
8a4639bc43
commit
2f7731e9e5
10 changed files with 166 additions and 14 deletions
|
|
@ -52,6 +52,7 @@ EXPECTED_PLUGINS = [
|
|||
"register_routes",
|
||||
"render_cell",
|
||||
"startup",
|
||||
"table_actions",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
@ -69,6 +70,7 @@ EXPECTED_PLUGINS = [
|
|||
"permission_allowed",
|
||||
"render_cell",
|
||||
"startup",
|
||||
"table_actions",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -296,3 +296,15 @@ def forbidden(datasette, request, message):
|
|||
def menu_links(datasette, actor):
|
||||
if actor:
|
||||
return [{"href": datasette.urls.instance(), "label": "Hello"}]
|
||||
|
||||
|
||||
@hookimpl
|
||||
def table_actions(datasette, database, table, actor):
|
||||
if actor:
|
||||
return [
|
||||
{
|
||||
"href": datasette.urls.instance(),
|
||||
"label": "Database: {}".format(database),
|
||||
},
|
||||
{"href": datasette.urls.instance(), "label": "Table: {}".format(table)},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -155,3 +155,12 @@ def menu_links(datasette, actor):
|
|||
return [{"href": datasette.urls.instance(), "label": "Hello 2"}]
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
@hookimpl
|
||||
def table_actions(datasette, database, table, actor):
|
||||
async def inner():
|
||||
if actor:
|
||||
return [{"href": datasette.urls.instance(), "label": "From async"}]
|
||||
|
||||
return inner
|
||||
|
|
|
|||
|
|
@ -782,3 +782,22 @@ def test_hook_menu_links(app_client):
|
|||
{"label": "Hello", "href": "/"},
|
||||
{"label": "Hello 2", "href": "/"},
|
||||
]
|
||||
|
||||
|
||||
def test_hook_table_actions(app_client):
|
||||
def get_table_actions_links(html):
|
||||
soup = Soup(html, "html.parser")
|
||||
details = soup.find("details", {"class": "table-menu-links"})
|
||||
if details is None:
|
||||
return []
|
||||
return [{"label": a.text, "href": a["href"]} for a in details.select("a")]
|
||||
|
||||
response = app_client.get("/fixtures/facetable")
|
||||
assert get_table_actions_links(response.text) == []
|
||||
|
||||
response_2 = app_client.get("/fixtures/facetable?_bot=1")
|
||||
assert get_table_actions_links(response_2.text) == [
|
||||
{"label": "From async", "href": "/"},
|
||||
{"label": "Database: fixtures", "href": "/"},
|
||||
{"label": "Table: facetable", "href": "/"},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue