mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Make request available to menu plugin hooks, closes #1371
This commit is contained in:
parent
a3faf37883
commit
d23a267138
8 changed files with 44 additions and 23 deletions
|
|
@ -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,
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue