From 38941218ee93e01bc59f460b98d30ac170053480 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 29 Jan 2024 22:13:18 -0800 Subject: [PATCH] Upload a CSV database action, closes #28 --- datasette_upload_csvs/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/datasette_upload_csvs/__init__.py b/datasette_upload_csvs/__init__.py index 8c67522..4f15a75 100644 --- a/datasette_upload_csvs/__init__.py +++ b/datasette_upload_csvs/__init__.py @@ -44,6 +44,27 @@ async def inner(): return inner +@hookimpl +def database_actions(datasette, actor, database): + async def inner(): + db = datasette.get_database(database) + if ( + await datasette.permission_allowed(actor, "upload-csvs", default=False) + and db.is_mutable + and db.name not in ("_memory", "_internal") + ): + return [ + { + "href": datasette.urls.path( + "/-/upload-csvs?database={}".format(quote_plus(db.name)) + ), + "label": "Upload a CSV", + } + ] + + return inner + + async def upload_csvs(scope, receive, datasette, request): if not await datasette.permission_allowed( request.actor, "upload-csvs", default=False