render_cell(value, column, table, database, datasette)

The render_cell plugin hook previously was only passed value.

It is now passed (value, column, table, database, datasette).
This commit is contained in:
Simon Willison 2018-08-28 03:03:01 -07:00
commit 2e836f72d9
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
10 changed files with 127 additions and 25 deletions

View file

@ -72,7 +72,7 @@ def test_plugins_with_duplicate_js_urls(app_client):
)
def test_plugins_render_cell(app_client):
def test_plugins_render_cell_link_from_json(app_client):
sql = """
select '{"href": "http://example.com/", "label":"Example"}'
""".strip()
@ -86,9 +86,25 @@ def test_plugins_render_cell(app_client):
a = td.find("a")
assert a is not None, str(a)
assert a.attrs["href"] == "http://example.com/"
assert a.attrs["data-database"] == "fixtures"
assert a.text == "Example"
def test_plugins_render_cell_demo(app_client):
response = app_client.get("/fixtures/simple_primary_key?id=4")
soup = Soup(response.body, "html.parser")
td = soup.find("td", {"class": "col-content"})
assert {
"column": "content",
"table": "simple_primary_key",
"database": "fixtures",
"config": {
"depth": "table",
"special": "this-is-simple_primary_key"
}
} == json.loads(td.string)
def test_plugin_config(app_client):
assert {"depth": "table"} == app_client.ds.plugin_config(
"name-of-plugin", database="fixtures", table="sortable"
@ -138,7 +154,7 @@ def test_plugin_config(app_client):
),
],
)
def test_extra_body_script(app_client, path, expected_extra_body_script):
def test_plugins_extra_body_script(app_client, path, expected_extra_body_script):
r = re.compile(r"<script>var extra_body_script = (.*?);</script>")
json_data = r.search(app_client.get(path).body.decode("utf8")).group(1)
actual_data = json.loads(json_data)