Open simonw opened 8 months ago
I wrote this code earlier:
@hookimpl
def table_actions(datasette, actor, database, table):
async def inner():
if not await can_paste(datasette, actor, database, table):
return []
return [
{
"href": datasette.urls.table(database, table) + "/-/paste",
"label": "Paste data into this table",
"description": "Paste in JSON, CSV or TSV data (e.g. from Google Sheets)",
}
]
return inner
And for register_routes()
:
(r"^/(?P<database>[^/]+)/(?P<table>[^/]+)/-/paste$", paste_to_table),
There may be a bunch of extra complexity around this:
Super advanced: ability to reformat data to populate columns correctly, for example reformatting dates to match. This is likely to be a separate feature, there's a lot of depth to this one and it affects how imports work too.
Might also need a bit of persistence around this in order to remember what those conversions were for future loads into the same table.
Split from: