-
-
Notifications
You must be signed in to change notification settings - Fork 772
Allow routes to have extra options #1495
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
base: main
Are you sure you want to change the base?
Conversation
datasette/app.py
Outdated
assert len(extra_options) == 1 | ||
routes.append((regex, wrapped_view, extra_options[0])) | ||
else: | ||
routes.append((regex, wrapped_view)) | ||
|
||
def add_route(view, regex): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method should gain a third optional options
parameter. The code above can then call this method.
Also, I think the internal format of the routes
property should change to a list of three-tuples, where tuples with no options have None
as their third item.
This is a great idea - I've wanted this myself before, but never spent any time thinking about how to achieve it. I think your design here is exactly right - an optional third item in the tuple consisting of a dictionary of options to pass to the view function. |
To land this change we'll need a unit test that demonstrates the new capability - I suggest putting that next to this test: datasette/tests/test_plugins.py Lines 648 to 659 in 15a9d4a
It will also need documentation, which should be added here: https://github.com/simonw/datasette/blob/15a9d4abfff0c45dee2a9f851326e1d61b1c678c/docs/plugin_hooks.rst#register-routes-datasette |
okay @simonw, made the requested changes. tests are running locally. i think this is ready for you to look at again. |
This all looks promising! I will need detailed documentation on how to upgrade datasette once it's available, and how to implement. (@fgregg example looks very straightforward on the plugin front.) |
A nudge on this. |
Right now, datasette routes can only be a 2-tuple of
(regex, view_fn)
.If it was possible for datasette to handle extra options, like standard Django does, it would add flexibility for plugin authors.
For example, if extra options were enabled, then it would be easy to make a single table the home page (#1284). This plugin would accomplish it.