mirror of
https://github.com/simonw/datasette.git
synced 2026-06-06 17:16:57 +02:00
Make setting(), settings_dict(), and plugin_config() async
This change makes all settings and plugin config access asynchronous in preparation for a future plugin hook that will allow fetching settings from a database or via HTTP. Changes: - Datasette.setting() is now async - Datasette.settings_dict() is now async - Datasette.plugin_config() is now async - Added _setting_sync() for contexts that cannot await (threads, sync hooks) - Added _plugin_config_sync() for contexts that cannot await - Updated all callers throughout the codebase to use await - Updated tests to work with async methods
This commit is contained in:
parent
6fede23a2e
commit
1a7b027b60
13 changed files with 90 additions and 76 deletions
|
|
@ -27,7 +27,7 @@ def prepare_connection(conn, database, datasette):
|
|||
|
||||
def prepare_connection_args():
|
||||
return 'database={}, datasette.plugin_config("name-of-plugin")={}'.format(
|
||||
database, datasette.plugin_config("name-of-plugin")
|
||||
database, datasette._plugin_config_sync("name-of-plugin")
|
||||
)
|
||||
|
||||
conn.create_function("prepare_connection_args", 0, prepare_connection_args)
|
||||
|
|
@ -84,7 +84,7 @@ def extra_body_script(
|
|||
"template": template,
|
||||
"database": database,
|
||||
"table": table,
|
||||
"config": datasette.plugin_config(
|
||||
"config": await datasette.plugin_config(
|
||||
"name-of-plugin",
|
||||
database=database,
|
||||
table=table,
|
||||
|
|
@ -113,7 +113,7 @@ def render_cell(row, value, column, table, database, datasette, request):
|
|||
"column": column,
|
||||
"table": table,
|
||||
"database": database,
|
||||
"config": datasette.plugin_config(
|
||||
"config": await datasette.plugin_config(
|
||||
"name-of-plugin",
|
||||
database=database,
|
||||
table=table,
|
||||
|
|
@ -453,8 +453,8 @@ def skip_csrf(scope):
|
|||
|
||||
@hookimpl
|
||||
def register_actions(datasette):
|
||||
extras_old = datasette.plugin_config("datasette-register-permissions") or {}
|
||||
extras_new = datasette.plugin_config("datasette-register-actions") or {}
|
||||
extras_old = datasette._plugin_config_sync("datasette-register-permissions") or {}
|
||||
extras_new = datasette._plugin_config_sync("datasette-register-actions") or {}
|
||||
|
||||
actions = [
|
||||
Action(
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ def table_actions(datasette, database, table, actor, request):
|
|||
|
||||
@hookimpl
|
||||
def register_routes(datasette):
|
||||
config = datasette.plugin_config("register-route-demo")
|
||||
config = datasette._plugin_config_sync("register-route-demo")
|
||||
if not config:
|
||||
return
|
||||
path = config["path"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue