-
-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Redesign register_output_renderer callback #581
Comments
The |
To solve simonw/datasette-atom#6 the name of the current canned query should be made available somehow. That way the plugin configuration could specify that the title for browse/feed should be X. |
Rather than pass a request object (hence promoting that object into part of the documented, stable API) I think I'll pass the ASGI scope - that's already a stable, documented standard. UPDATE: changed my mind since |
Here's the code that calls the renderers - this needs to be expanded to check for those extra optional arguments: datasette/datasette/views/base.py Lines 387 to 398 in 2d099ad
|
While I'm doing this, another feature I would like is the ability for renderers to opt-in / opt-out of being displayed as options on the page. https://www.niche-museums.com/browse/museums for example shows a |
Here's the code that passes a list of renderers to the template: datasette/datasette/views/base.py Lines 411 to 423 in 2d099ad
A renderer is currently defined as a two-key dictionary: @hookimpl
def register_output_renderer(datasette):
return {
'extension': 'test',
'callback': render_test
} I can add a third key, One catch: what arguments should be passed to the |
I'll use #770 for the |
The existing render callback takes the following arguments:
The I'm going to change the design of part of this ticket. I won't break the old I think the only plugins using it right now are my |
OK, the new design: your callback function can take any of the following arguments:
We will also continue to support the existing |
The |
I think I need a utility function for "call this function with this dictionary of arguments, but only pass the arguments which are inspected by the function". |
https://docs.python.org/3/library/inspect.html#introspecting-callables-with-the-signature-object
|
|
Here's the function I just wrote for this: def call_with_supported_arguments(fn, **kwargs):
parameters = inspect.signature(fn).parameters.keys()
call_with = []
for parameter in parameters:
if parameter not in kwargs:
raise TypeError("{} requires parameters {}".format(fn, tuple(parameters)))
call_with.append(kwargs[parameter])
return fn(*call_with) |
Need to figure out how best to unit test this plugin hook. |
Actually passing the |
Since I'm passing |
It bothers me that Can I come up with clearer names for these? |
I'm going to break backwards compatibility directly here, without waiting for Datasette 1.0. The reason is that https://github.com/russss/datasette-geo hasn't been updated in 13 months so is already broken against current Datasette, and the other two plugins using this hook are owned by me so I can upgrade them myself. |
(I used GitHub code search to find code using this plugin hook: https://github.com/search?q=register_output_renderer&type=Code ) |
Right now a rendering callback returns the following:
I'm going to add an optional |
(I wonder if this would be enough to allow really smart plugins to implement ETag/conditional get) |
Request object is now documented: https://datasette.readthedocs.io/en/latest/internals.html#request-object |
Updated documentation is here: https://datasette.readthedocs.io/en/latest/plugins.html#register-output-renderer-datasette |
In building https://github.com/simonw/datasette-atom it became clear that the callback function (which currently accepts just args, data and view_name) would also benefit from access to a mechanism to render templates and a
datasette
instance so it can execute SQL.To maintain backwards compatibility with existing plugins, we can introspect the callback function to see if it wants those new arguments or not.
At a minimum I want to make
datasette
and ASGIscope
available.The text was updated successfully, but these errors were encountered: