Added plugin_config() method

This commit is contained in:
Simon Willison 2018-08-28 01:35:21 -07:00
commit 0a14a4846b
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
6 changed files with 114 additions and 6 deletions

View file

@ -170,7 +170,7 @@ class Datasette:
def metadata(self, key=None, database=None, table=None, fallback=True):
"""
Looks up metadata, cascading backwards from specified level.
Returns None if metadata value is not foundself.
Returns None if metadata value is not found.
"""
assert not (database is None and table is not None), \
"Cannot call metadata() with table= specified but not database="
@ -199,6 +199,17 @@ class Datasette:
m.update(item)
return m
def plugin_config(
self, plugin_name, database=None, table=None, fallback=True
):
"Return config for plugin, falling back from specified database/table"
plugins = self.metadata(
"plugins", database=database, table=table, fallback=fallback
)
if plugins is None:
return None
return plugins.get(plugin_name)
def app_css_hash(self):
if not hasattr(self, "_app_css_hash"):
self._app_css_hash = hashlib.sha1(

View file

@ -1,8 +1,8 @@
from pluggy import HookimplMarker
from pluggy import HookspecMarker
hookspec = HookspecMarker('datasette')
hookimpl = HookimplMarker('datasette')
hookspec = HookspecMarker("datasette")
hookimpl = HookimplMarker("datasette")
@hookspec