mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
.blob output renderer
* _blob_hash= checking plus refactored to use new BadRequest class, refs #1050 * Replace BlobView with new .blob renderer, closes #1050 * .blob downloads on arbitrary queries, closes #1051
This commit is contained in:
parent
d6f9ff7137
commit
78b3eeaad9
12 changed files with 165 additions and 121 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import hashlib
|
||||
import itertools
|
||||
import jinja2
|
||||
import json
|
||||
|
|
@ -10,6 +11,7 @@ from datasette.utils import (
|
|||
validate_sql_select,
|
||||
is_url,
|
||||
path_with_added_args,
|
||||
path_with_format,
|
||||
path_with_removed_args,
|
||||
InvalidSql,
|
||||
)
|
||||
|
|
@ -342,6 +344,24 @@ class QueryView(DataView):
|
|||
url=jinja2.escape(value.strip())
|
||||
)
|
||||
)
|
||||
elif isinstance(display_value, bytes):
|
||||
blob_url = path_with_format(
|
||||
request,
|
||||
"blob",
|
||||
extra_qs={
|
||||
"_blob_column": column,
|
||||
"_blob_hash": hashlib.sha256(
|
||||
display_value
|
||||
).hexdigest(),
|
||||
},
|
||||
)
|
||||
display_value = jinja2.Markup(
|
||||
'<a class="blob-download" href="{}"><Binary: {} byte{}></a>'.format(
|
||||
blob_url,
|
||||
len(display_value),
|
||||
"" if len(value) == 1 else "s",
|
||||
)
|
||||
)
|
||||
display_row.append(display_value)
|
||||
display_rows.append(display_row)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue