-
-
Notifications
You must be signed in to change notification settings - Fork 702
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
?_extra= support (draft) #1999
?_extra= support (draft) #1999
Conversation
I think I'm going to have to write a new view function from scratch which completely ignores the existing BaseView/DataView/TableView hierarchy. Here's what I get on the incoming request:
|
HTML mode needs a list of renderers so it can show links to datasette/datasette/views/base.py Lines 477 to 497 in e4ebef0
|
Next step: get Then... figure out how to render HTML and other requested formats. Then get the tests to pass! |
While working on: - simonw/datasette#1999
Breaking this down into smaller steps:
|
I'm trying to get |
I'd really like to extract this ugly logic out into a helper function: datasette/datasette/views/table.py Lines 1617 to 1684 in db1a88f
I copied it in and asked ChatGPT to "List all of the variable that are either modified or assigned to by the above code":
Then I asked which variables were used as inputs, and argued with it a bit about whether it should be counting functions. Eventually got to this:
Note that datasette/datasette/views/table.py Line 1540 in db1a88f
|
So maybe I can refactor it to look a bit more like this: datasette/datasette/views/table.py Lines 1602 to 1604 in db1a88f
One thing that's useful here is that datasette/datasette/views/table.py Lines 466 to 472 in db1a88f
So if I omit the |
I'm going to hold off on that refactor until later, when I have tests to show me if the refactor works or not. |
Just noticed that datasette/datasette/renderer.py Lines 29 to 40 in 56b0758
But that's not currently being called by my new code. |
The ease with which I added that diff --git a/datasette/views/table.py b/datasette/views/table.py
index 8d3bb2c930..3e1db9c85f 100644
--- a/datasette/views/table.py
+++ b/datasette/views/table.py
@@ -1913,6 +1913,13 @@ async def extra_request():
"args": request.args._data,
}
+ async def extra_query():
+ "Details of the underlying SQL query"
+ return {
+ "sql": sql,
+ "params": params,
+ }
+
async def extra_extras():
"Available ?_extra= blocks"
return {
@@ -1938,6 +1945,7 @@ async def extra_extras():
extra_primary_keys,
extra_debug,
extra_request,
+ extra_query,
extra_extras,
) |
For the HTML version, I need to decide where all of the stuff that happens in I think it's another one of those extra functions, triggered for datasette/datasette/views/table.py Lines 813 to 912 in 96e94f9
|
Figuring out what to do with datasette/datasette/views/table.py Lines 45 to 71 in 96e94f9
|
Aside idea: it might be interesting if there were "lazy" template variables available in the context: things that are not actually executed unless a template author requests them. Imagine if |
To replace this code: datasette/datasette/views/base.py Lines 110 to 122 in 56b0758
Maybe https://docs.datasette.io/en/stable/internals.html#await-render-template-template-context-none-request-none - turns out it does already:
It doesn't have an easy way to populate that |
Getting close now! Only 13 failures left, mostly relating to CSV.
|
Should hopefully get tests passing for #2036 too.
I rebased from
|
Oh this is a bit tricky. I have a failing test because a plugin that uses the Turns out that bit comes from here: Lines 1203 to 1217 in 56b0758
Which assumes the context has Actually I think I can cheat here, since it's still getting the HTML context in order to render the template. |
I hacked at the CSV stuff until it worked. I need to clean it up though, but I can do that in this separate task: |
This still needs documentation, but now the tests are passing I'm going to merge it into |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1999 +/- ##
==========================================
- Coverage 92.15% 87.73% -4.43%
==========================================
Files 38 38
Lines 5560 6066 +506
==========================================
+ Hits 5124 5322 +198
- Misses 436 744 +308
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Refs:
📚 Documentation preview 📚: https://datasette--1999.org.readthedocs.build/en/1999/