Closed cldellow closed 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.
There is an environment
param in the underlying jinja BaseLoader#get_source
... does that have something useful, or is that an internal detail?
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.
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
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.
Build out the MVP of #48:
?_dux_edit=1
query parameter present (in the future we can define via metadata){% extends "default:row.html" %}
<form>
that wraps all the controlsrender_cell
should emit an edit control if the control is editableStringControl
that is just a vanilla text input