Skip to content

Commit

Permalink
Link to BLOB downloads, closes #1046
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Oct 25, 2020
1 parent a96ad96 commit 5db7ae3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,11 @@ def table(self, database, table):

def query(self, database, query):
return "{}/{}".format(self.database(database), urllib.parse.quote_plus(query))

def row(self, database, table, row_path):
return "{}/{}".format(self.table(database, table), row_path)

def row_blob(self, database, table, row_path, column):
return self.table(database, table) + "/-/blob/{}/{}.blob".format(
row_path, urllib.parse.quote_plus(column)
)
11 changes: 11 additions & 0 deletions datasette/static/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ svg.dropdown-menu-icon {
top: 1px;
}

.blob-download {
display: block;
white-space: nowrap;
padding-right: 20px;
position: relative;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2Ij48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03LjQ3IDEwLjc4YS43NS43NSAwIDAwMS4wNiAwbDMuNzUtMy43NWEuNzUuNzUgMCAwMC0xLjA2LTEuMDZMOC43NSA4LjQ0VjEuNzVhLjc1Ljc1IDAgMDAtMS41IDB2Ni42OUw0Ljc4IDUuOTdhLjc1Ljc1IDAgMDAtMS4wNiAxLjA2bDMuNzUgMy43NXpNMy43NSAxM2EuNzUuNzUgMCAwMDAgMS41aDguNWEuNzUuNzUgMCAwMDAtMS41aC04LjV6Ij48L3BhdGg+PC9zdmc+");
background-size: 16px 16px;
background-position: right;
background-repeat: no-repeat;
}

.anim-scale-in {
animation-name: scale-in;
animation-duration: 0.15s;
Expand Down
11 changes: 9 additions & 2 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,15 @@ async def display_columns_and_rows(
display_value = plugin_display_value
elif isinstance(value, bytes):
display_value = jinja2.Markup(
"<Binary data: {} byte{}>".format(
len(value), "" if len(value) == 1 else "s"
'<a class="blob-download" href="{}">&lt;Binary:&nbsp;{}&nbsp;byte{}&gt;</a>'.format(
self.ds.urls.row_blob(
database,
table,
path_from_row_pks(row, pks, not pks),
column,
),
len(value),
"" if len(value) == 1 else "s",
)
)
elif isinstance(value, dict):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,12 +1231,12 @@ def test_binary_data_display(app_client):
[
'<td class="col-Link type-pk"><a href="/fixtures/binary_data/1">1</a></td>',
'<td class="col-rowid type-int">1</td>',
'<td class="col-data type-bytes">&lt;Binary\xa0data:\xa07\xa0bytes&gt;</td>',
'<td class="col-data type-bytes"><a class="blob-download" href="/fixtures/binary_data/-/blob/1/data.blob">&lt;Binary:\xa07\xa0bytes&gt;</a></td>',
],
[
'<td class="col-Link type-pk"><a href="/fixtures/binary_data/2">2</a></td>',
'<td class="col-rowid type-int">2</td>',
'<td class="col-data type-bytes">&lt;Binary\xa0data:\xa07\xa0bytes&gt;</td>',
'<td class="col-data type-bytes"><a class="blob-download" href="/fixtures/binary_data/-/blob/2/data.blob">&lt;Binary:\xa07\xa0bytes&gt;</a></td>',
],
]
assert expected_tds == [
Expand Down

0 comments on commit 5db7ae3

Please sign in to comment.