From 7825b3c6f019fe501c1fbfd534e53e00766750d1 Mon Sep 17 00:00:00 2001 From: Dimitri Yatsenko Date: Sun, 11 Jan 2026 18:19:52 -0600 Subject: [PATCH] enhance: Show codec names in table preview instead of =BLOB= - Raw blobs (no codec) now show "bytes" - Raw json (no codec) shows "json" - Codec fields show "" (e.g., , , ) - HTML output properly escapes angle brackets for browser display - Improves clarity when viewing table contents Example output: *id raw_blob blob_data json_data 1 bytes json Co-Authored-By: Claude Opus 4.5 --- src/datajoint/preview.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/datajoint/preview.py b/src/datajoint/preview.py index 8cca46b2a..c0f103eb1 100644 --- a/src/datajoint/preview.py +++ b/src/datajoint/preview.py @@ -24,6 +24,21 @@ def _format_object_display(json_data): return "=OBJ[file]=" +def _get_blob_placeholder(heading, field_name, html_escape=False): + """Get display placeholder for a blob/json field based on its codec.""" + attr = heading.attributes.get(field_name) + if attr is None: + return "bytes" + if attr.codec is not None: + name = attr.codec.name + if html_escape: + return f"<{name}>" + return f"<{name}>" + if attr.json: + return "json" + return "bytes" + + def preview(query_expression, limit, width): heading = query_expression.heading rel = query_expression.proj(*heading.non_blobs) @@ -55,7 +70,7 @@ def preview(query_expression, limit, width): def get_placeholder(f): if f in object_fields: return "=OBJ[.xxx]=" - return "=BLOB=" + return _get_blob_placeholder(heading, f) widths = { f: min( @@ -72,7 +87,7 @@ def get_display_value(tup, f, idx): elif f in object_fields and idx < len(object_data_list): return _format_object_display(object_data_list[idx].get(f)) else: - return "=BLOB=" + return _get_blob_placeholder(heading, f) return ( " ".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): elif name in object_fields and idx < len(object_data_list): return _format_object_display(object_data_list[idx].get(name)) else: - return "=BLOB=" + return _get_blob_placeholder(heading, name, html_escape=True) css = """