Make request available to menu plugin hooks, closes #1371

This commit is contained in:
Simon Willison 2021-06-09 21:45:24 -07:00
commit d23a267138
8 changed files with 44 additions and 23 deletions

View file

@ -316,9 +316,12 @@ def forbidden(datasette, request, message):
@hookimpl
def menu_links(datasette, actor):
def menu_links(datasette, actor, request):
if actor:
return [{"href": datasette.urls.instance(), "label": "Hello"}]
label = "Hello"
if request.args.get("_hello"):
label += ", " + request.args["_hello"]
return [{"href": datasette.urls.instance(), "label": label}]
@hookimpl
@ -334,11 +337,14 @@ def table_actions(datasette, database, table, actor):
@hookimpl
def database_actions(datasette, database, actor):
def database_actions(datasette, database, actor, request):
if actor:
label = f"Database: {database}"
if request.args.get("_hello"):
label += " - " + request.args["_hello"]
return [
{
"href": datasette.urls.instance(),
"label": f"Database: {database}",
"label": label,
}
]

View file

@ -158,9 +158,12 @@ def menu_links(datasette, actor):
@hookimpl
def table_actions(datasette, database, table, actor):
def table_actions(datasette, database, table, actor, request):
async def inner():
if actor:
return [{"href": datasette.urls.instance(), "label": "From async"}]
label = "From async"
if request.args.get("_hello"):
label += " " + request.args["_hello"]
return [{"href": datasette.urls.instance(), "label": label}]
return inner