cldellow / datasette-ui-extras

Add editing UI and other power-user features to Datasette.
Apache License 2.0
12 stars 1 forks source link

mvp of Edit UI: update existing rows #37

Closed cldellow closed 1 year ago

cldellow commented 1 year ago

Build out the MVP of #48:

cldellow commented 1 year ago

How can we conditionally render an edit page? Ideally, we'd do this at the top level by serving a different jinja template altogether, and only when we detect _dux_edit=1.

I hoped prepare_jinja2_environment would work. But I think it doesn't have the context of the request.

cldellow commented 1 year ago

There is an environment param in the underlying jinja BaseLoader#get_source... does that have something useful, or is that an internal detail?

cldellow commented 1 year ago

It's a global thing, not specific to a given request: https://jinja.palletsprojects.com/en/3.0.x/api/

So, hm. Kinda sucks, maybe we have to hijack the whole row view, which will break customizability.

cldellow commented 1 year ago

We can do something disgusting with a monkey patch on https://github.com/simonw/datasette/blob/1.0a2/datasette/views/row.py#L19 to change the templates it returns to be edit-focused based on the request

cldellow commented 1 year ago

We might want some way to map from a request to a list of editable columns? This would be used when determining if we should show the edit page, when render_cell determines if it should show an edit control, etc.

D'oh, this also reminds me that the version of render_cell that takes a request isn't publicly available yet. Hm.