Apply render_cell plugin on table views, refs #352

This commit is contained in:
Simon Willison 2018-08-04 17:04:53 -07:00
commit 61e9a4d601
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
6 changed files with 19 additions and 24 deletions

View file

@ -223,6 +223,8 @@ def extra_js_urls():
@hookimpl
def render_cell(value):
# Render {"href": "...", "label": "..."} as link
if not isinstance(value, str):
return None
stripped = value.strip()
if not stripped.startswith("{") and stripped.endswith("}"):
return None
@ -230,6 +232,8 @@ def render_cell(value):
data = json.loads(value)
except ValueError:
return None
if not isinstance(data, dict):
return None
if set(data.keys()) != {"href", "label"}:
return None
href = data["href"]
@ -389,9 +393,12 @@ INSERT INTO "searchable_fts" (rowid, text1, text2, [name with . and spaces])
CREATE TABLE [select] (
[group] text,
[having] text,
[and] text
[and] text,
[json] text
);
INSERT INTO [select] VALUES ('group', 'having', 'and',
'{"href": "http://example.com/", "label":"Example"}'
);
INSERT INTO [select] VALUES ('group', 'having', 'and');
CREATE TABLE infinity (
value REAL

View file

@ -231,7 +231,7 @@ def test_database_page(app_client):
],
},
}, {
'columns': ['group', 'having', 'and'],
'columns': ['group', 'having', 'and', 'json'],
'name': 'select',
'count': 1,
'hidden': False,
@ -599,6 +599,7 @@ def test_table_with_reserved_word_name(app_client):
'group': 'group',
'having': 'having',
'and': 'and',
'json': '{"href": "http://example.com/", "label":"Example"}'
}]