plomino / Plomino

Powerful and flexible web-based application builder
33 stars 37 forks source link

``plominoutils_tool`` branch #107

Open jean opened 12 years ago

jean commented 12 years ago

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:

from PlominoUtils import DateToString, htmlencode, ...

it would do:

utils_tools = getToolByName('the_tool'); DateToString = utis_tools.DateToString

Note that after this change, existing formulas would need to be recompiled (deleted from scripts). This could be done in a migration step.

ebrehault commented 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)

jean commented 12 years ago

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