mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Added example code to database_actions hook documentation
This commit is contained in:
parent
e4abae3fd7
commit
fbcb103c0c
1 changed files with 26 additions and 1 deletions
|
|
@ -1439,7 +1439,32 @@ database_actions(datasette, actor, database, request)
|
||||||
|
|
||||||
This hook is similar to :ref:`plugin_hook_table_actions` but populates an actions menu on the database page.
|
This hook is similar to :ref:`plugin_hook_table_actions` but populates an actions menu on the database page.
|
||||||
|
|
||||||
Example: `datasette-graphql <https://datasette.io/plugins/datasette-graphql>`_
|
This example adds a new database action for creating a table, if the user has the ``edit-schema`` permission:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from datasette import hookimpl
|
||||||
|
|
||||||
|
|
||||||
|
@hookimpl
|
||||||
|
def database_actions(datasette, actor, database):
|
||||||
|
async def inner():
|
||||||
|
if not await datasette.permission_allowed(
|
||||||
|
actor, "edit-schema", resource=database, default=False
|
||||||
|
):
|
||||||
|
return []
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"href": datasette.urls.path(
|
||||||
|
"/-/edit-schema/{}/-/create".format(database)
|
||||||
|
),
|
||||||
|
"label": "Create a table",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return inner
|
||||||
|
|
||||||
|
Example: `datasette-graphql <https://datasette.io/plugins/datasette-graphql>`_, `datasette-edit-schema <https://datasette.io/plugins/datasette-edit-schema>`_
|
||||||
|
|
||||||
.. _plugin_hook_skip_csrf:
|
.. _plugin_hook_skip_csrf:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue