Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism for register_output_renderer to suggest extension or not #645

Closed
simonw opened this issue Dec 1, 2019 · 4 comments
Closed

Mechanism for register_output_renderer to suggest extension or not #645

simonw opened this issue Dec 1, 2019 · 4 comments

Comments

@simonw
Copy link
Owner

simonw commented Dec 1, 2019

datasette-atom only works if the user constructs a SQL query with specific output columns (atom_id ,atom_updated etc).

It would be good if the .atom link wasn't shown on the query/table page unless those columns were present. Right now you get a link which results in a 400 error:

browse__museums__51_rows

See also #581.

@simonw
Copy link
Owner Author

simonw commented Dec 1, 2019

Plugins are currently expected to return this:

@hookimpl
def register_output_renderer(datasette):
    return {
        "extension": "test",
        "callback": render_test
    }

We can add an optional third argument, "should_suggest", which takes the same arguments as the callback but simply returns True or False depending on if the plugin can work for the current set of data.

If that dictionary key is omitted, Datasette will treat this test as returning True.

@simonw
Copy link
Owner Author

simonw commented Dec 1, 2019

It should be optionally awaitable - as should the existing "callback". Can use the same pattern as this one:

for extra_vars in pm.hook.extra_template_vars(
template=template.name,
database=context.get("database"),
table=context.get("table"),
view_name=self.name,
request=request,
datasette=self.ds,
):
if callable(extra_vars):
extra_vars = extra_vars()
if asyncio.iscoroutine(extra_vars):
extra_vars = await extra_vars

@simonw
Copy link
Owner Author

simonw commented Dec 2, 2019

I'm going to add unit tests for the hook, and as part of that I'll fix the weird thing at the moment where the plugins for the unit tests are defined inside a quoted string as opposed to their own separate file.

@simonw
Copy link
Owner Author

simonw commented May 28, 2020

This is a duplicate of a more recent, more developed issue: #770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant