Open jean opened 12 years ago
there is also anoher approach: we keep PlominoUtils functions, and we just add a new one like that:
from zope.globalrequest import getRequest
def findContext():
"""Find the context
"""
request = getRequest()
published = request.get('PUBLISHED', None)
context = getattr(published, '__parent__', None)
if context is None:
context = request.PARENTS[0]
return context
(I saw that as I was trying to solve a bug in plone.app.theming, I didn't knew the getRequest method, maybe it could be helpful with PlominoAgent.run_async)
This looks like a better approach for utils.
It doesn't look like it would work for async:
> .../Products/CMFPlomino/PlominoAgent.py(121)runAgent()
-> plominoContext = self
(Pdb) getattr(self, 'REQUEST', None) is None
True
(Pdb) from zope.globalrequest import getRequest
(Pdb) getRequest() is None
True
In order to allow utility methods to access
context
, they need to live on a persistent tool.The version of PlominoUtils on the https://github.com/plomino/Plomino/tree/plominoutils_tool branch requires that.
From Eric:
compileFormulaScript
would get the tool, so instead of inserting:it would do:
Note that after this change, existing formulas would need to be recompiled (deleted from
scripts
). This could be done in a migration step.