render_cell() can now return an awaitable, refs

This commit is contained in:
Simon Willison 2021-08-08 16:04:42 -07:00
commit 3bb6409a6c
7 changed files with 66 additions and 21 deletions

View file

@ -370,7 +370,7 @@ Lets you customize the display of values within table cells in the HTML table vi
The name of the database
``datasette`` - :ref:`internals_datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
If your hook returns ``None``, it will be ignored. Use this to indicate that your hook is not able to custom render this particular value.
@ -378,6 +378,8 @@ If the hook returns a string, that string will be rendered in the table cell.
If you want to return HTML markup you can do so by returning a ``jinja2.Markup`` object.
You can also return an awaitable function which returns a value.
Datasette will loop through all available ``render_cell`` hooks and display the value returned by the first one that does not return ``None``.
Here is an example of a custom ``render_cell()`` plugin which looks for values that are a JSON string matching the following format::