pythonplonezopedtml

Python script in Zope can't find function name in external method


I am having a problem getting a Python script in Plone to find an External Method. Given three different objects:

  1. An external method called CloneList (Id and Function Name)
  2. A DTML Document that references it successfully using this

    <dtml-var "CloneList(PAGE,ORG,STATUS,CGAP_DATA_HOME,BASE)">
    
  3. A Python script that references the external method via this...

    return CloneList(PAGE,ORG,STATUS,CGAP_DATA_HOME,BASE)
    

The DTML document works fine but the Python script, for some reason throws:

Error Value: global name 'CloneList' is not defined

Why can the DTML template see CloneList just fine but the Python script can't?


Solution

  • The DTML namespace includes the current context, the Python Script namespace does not. The Python code has to use explicit methods to reference other objects outside of the script.

    You can use the context object to reference other objects in the ZODB, like the External Method:

    return context.CloneList(PAGE, ORG, STATUS, CGAP_DATA_HOME, BASE)
    

    You can also look up the name on container; where context uses the acquisition chain to look for names, container only looks at the folder the script lives in, plus all parent folders.