Lets say you want a form with a button "download as XML" which takes the input and downloads as XML.
There isn't a good way to do this
Actions formulas aren't executed on submission
Page forms only have beforeCreate as an event which can be used. But beforeCreate doesn't have access to the temporary document which makes it hard to use the data.
if you want to use a calculatedField to create the XML, you can't give it a temporary document
when you try to set the mimetype and body on the zope response in beforeCreate, beforeCreate is still getting called inside a template so the body will get replaced with the template contents.
Options downloads
Submission action
Actions are the most intuitive place to put code to handle submissions. We could have "submission action" with a formula that takes a temporarydocument as the context and gives full control over the the response.
A user can then add a action with a download macro to perform downloads.
Currently however Action formulas are never called on submission. They are called at render to give a link to redirect to. So it would change what they do (although conceptionally if they can't be made to act on submission they should be called links not actions IMO).
change beforeCreate
move beforeCreate outside of the template. but how to signal that you don't want to render the template? at the moment any string is interpreted as an error.
[x] New event
onDisplay or onRender or beforeFormDisplay or beforeLoad?
Something that gets called before the template is rendered and has the ability to determine if what will happen next i.e. redirect or stream or render as normal.
How should a formula indicate what should happen next?
[x] return value? ZopeReponse means use that. None means render normally. String means direct
dict means?
boolean. True means render. False means don't
Flag in request.
Inspect Response and see if a redirect header or body has been set. if so, don't render the template
if your have a formula you have to call render yourself.
Options for temp docs
form.getTemporaryDocument
ie an api that any formula can turn the request into a validated temporary document.
tempdoc in every formula.
Like plominoContext, there is plominoRequestDocument in every formula which provides an consistent way to access the data thats been submitted
User problem
Lets say you want a form with a button "download as XML" which takes the input and downloads as XML.
There isn't a good way to do this
Options downloads
Submission action
Actions are the most intuitive place to put code to handle submissions. We could have "submission action" with a formula that takes a temporarydocument as the context and gives full control over the the response.
A user can then add a action with a download macro to perform downloads.
Currently however Action formulas are never called on submission. They are called at render to give a link to redirect to. So it would change what they do (although conceptionally if they can't be made to act on submission they should be called links not actions IMO).
change beforeCreate
move beforeCreate outside of the template. but how to signal that you don't want to render the template? at the moment any string is interpreted as an error.
[x] New event
onDisplay or onRender or beforeFormDisplay or beforeLoad?
Something that gets called before the template is rendered and has the ability to determine if what will happen next i.e. redirect or stream or render as normal.
How should a formula indicate what should happen next?
Options for temp docs
form.getTemporaryDocument
ie an api that any formula can turn the request into a validated temporary document.
tempdoc in every formula.
Like plominoContext, there is plominoRequestDocument in every formula which provides an consistent way to access the data thats been submitted