-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
Get rid of the no-longer necessary ?_format=json hack for tables called x.json #1651
Comments
Here's the relevant code: datasette/datasette/utils/__init__.py Lines 753 to 772 in 1baa030
datasette/datasette/views/base.py Lines 451 to 479 in 1baa030
|
I found an obscure bug in #1650 which I can fix with this too. The following test should pass: @pytest.mark.parametrize(
"path,expected",
(
(
"/fivethirtyeight/twitter-ratio%2Fsenators",
"/fivethirtyeight/twitter-2Dratio-2Fsenators",
),
(
"/fixtures/table%2Fwith%2Fslashes.csv",
"/fixtures/table-2Fwith-2Fslashes-2Ecsv",
),
# query string should be preserved
("/foo/bar%2Fbaz?id=5", "/foo/bar-2Fbaz?id=5"),
),
)
def test_redirect_percent_encoding_to_dash_encoding(app_client, path, expected):
response = app_client.get(path)
assert response.status == 302
assert response.headers["location"] == expected It currently fails like this:
Because the logic in that datasette/datasette/views/base.py Lines 288 to 303 in 1baa030
|
Wow, this code is difficult to follow! Look at this bit inside the datasette/datasette/views/base.py Lines 469 to 478 in bb49994
That's modifying the arguments that were extracted from the path by the routing regular expressions to have |
My attempts to simplify
I really need to clean this up. |
I'm going to do a review of how URL routing works at the moment for the various views. I edited down the full list a bit - these are the most relevant: add_route(IndexView.as_view(self), r"/(?P<as_format>(\.jsono?)?$)")
add_route(
DatabaseView.as_view(self),
r"/(?P<db_name>[^/]+?)(?P<as_format>"
+ renderer_regex
+ r"|.jsono|\.csv)?$",
)
add_route(
TableView.as_view(self),
r"/(?P<db_name>[^/]+)/(?P<table_and_format>[^/]+?$)",
)
add_route(
RowView.as_view(self),
r"/(?P<db_name>[^/]+)/(?P<table>[^/]+?)/(?P<pk_path>[^/]+?)(?P<as_format>"
+ renderer_regex
+ r")?$",
) |
A lot of the code complexity here is caused by It would be good to get rid of that subclassed shared code, figure out how to do it via a utility function instead. |
This work is now blocked on: |
Tidy up from:
The text was updated successfully, but these errors were encountered: