path and full_path arguments for output renderers, closes #1179

Output renderer render() and can_render() callbacks can now accept
path and full_path arguments - the path to the HTML version of the
page without the .extension, with and without the query string.

Also fixed path_with_format() so it replaces the extension the current
request used instead of falling back to ?_format=, which Datasette no
longer reads. This broke links generated by renderers such as
datasette-export-notebook, and the URLs returned by ?_extra=renderers
on .json pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TzcVp1Cq5yCRW81GiN88JX
This commit is contained in:
Claude 2026-10-05 21:44:50 +00:00
commit cf6357cf93
No known key found for this signature in database
10 changed files with 180 additions and 7 deletions

View file

@ -5,7 +5,17 @@ from datasette.utils.asgi import Response
async def can_render(
datasette, columns, rows, sql, query_name, database, table, request, view_name
datasette,
columns,
rows,
sql,
query_name,
database,
table,
request,
path,
full_path,
view_name,
):
# We stash this on datasette so the calling unit test can see it
datasette._can_render_saw = {
@ -17,13 +27,26 @@ async def can_render(
"database": database,
"table": table,
"request": request,
"path": path,
"full_path": full_path,
"view_name": view_name,
}
return not request.args.get("_no_can_render")
async def render_test_all_parameters(
datasette, columns, rows, sql, query_name, database, table, request, view_name, data
datasette,
columns,
rows,
sql,
query_name,
database,
table,
request,
path,
full_path,
view_name,
data,
):
headers = {}
for custom_header in request.args.getlist("header"):
@ -41,6 +64,8 @@ async def render_test_all_parameters(
"database": database,
"table": table,
"request": request,
"path": path,
"full_path": full_path,
"view_name": view_name,
"1+1": result.first()[0],
},