Skip to content

Commit 4f6625b

Browse files
Merge pull request #1330 from datajoint/enhance/blob-preview-display
Show codec names in table preview instead of =BLOB=
2 parents 78f4d0c + 7825b3c commit 4f6625b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/datajoint/preview.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ def _format_object_display(json_data):
2424
return "=OBJ[file]="
2525

2626

27+
def _get_blob_placeholder(heading, field_name, html_escape=False):
28+
"""Get display placeholder for a blob/json field based on its codec."""
29+
attr = heading.attributes.get(field_name)
30+
if attr is None:
31+
return "bytes"
32+
if attr.codec is not None:
33+
name = attr.codec.name
34+
if html_escape:
35+
return f"<{name}>"
36+
return f"<{name}>"
37+
if attr.json:
38+
return "json"
39+
return "bytes"
40+
41+
2742
def preview(query_expression, limit, width):
2843
heading = query_expression.heading
2944
rel = query_expression.proj(*heading.non_blobs)
@@ -55,7 +70,7 @@ def preview(query_expression, limit, width):
5570
def get_placeholder(f):
5671
if f in object_fields:
5772
return "=OBJ[.xxx]="
58-
return "=BLOB="
73+
return _get_blob_placeholder(heading, f)
5974

6075
widths = {
6176
f: min(
@@ -72,7 +87,7 @@ def get_display_value(tup, f, idx):
7287
elif f in object_fields and idx < len(object_data_list):
7388
return _format_object_display(object_data_list[idx].get(f))
7489
else:
75-
return "=BLOB="
90+
return _get_blob_placeholder(heading, f)
7691

7792
return (
7893
" ".join([templates[f] % ("*" + f if f in rel.primary_key else f) for f in columns])
@@ -113,7 +128,7 @@ def get_html_display_value(tup, name, idx):
113128
elif name in object_fields and idx < len(object_data_list):
114129
return _format_object_display(object_data_list[idx].get(name))
115130
else:
116-
return "=BLOB="
131+
return _get_blob_placeholder(heading, name, html_escape=True)
117132

118133
css = """
119134
<style type="text/css">

0 commit comments

Comments
 (0)