[Zope] Passing of a Folder Object to a Python Script

Edward Pollard pollej@uleth.ca
Tue, 10 Sep 2002 15:46:28 -0600


Hello Folks,

A fairly straightfoward question. I'm trying to create some scripts that

allow the folder and file structure of the content to control dynamicly
the content of the menus that present said content.

In a directory are folders. These folders are the "Menu Headings" of the

content. Beneath each "Menu Heading" are some links in a "submenu"
determined by
the files within the associated folder.

If I call the submenu script explicitly in the correct context, it
generates the correct content. However the menu items should not be hard

coded so I want to pass the folder to the script which  generates the
submenu content. I have it all figured out except the parameter passing.

I have included the relevant part of the Page Template at the bottom.

The script menuWidget looks for folders in the current context. The
script subMenuWidget looks for Page Templates in the current context,
but needs to be modified to accept an ObjectManager object as a
parameter. (the "items" object from the "menu" repetition loop)

I've looked around, fidgeted, snooped, and guessed. No luck. I can't
seem to call it correctly. I believe I only need to add a parameter to
the script in the ZMI, and change these lines
    <div tal:define="submenu here/org/subMenuWidget.py" tal:omit-tag="">

    (from the template)

    submenuitems = context.objectValues('Page Template')
    (from subMenuWidget.py)

For completeness I will include the code of subMenuWidget, but I doubt
its relevant to this semantic and syntactic question.

Thanks in Advance.

Edward

PS - if anyone has any good ideas on how to sort the collection of
ObjectManager objects based on the numeric content of the isRanked
comment, advice is appreciated.

>From the Page Template:
-------------------------------------------
<div tal:define="menu here/menuWidget.py" tal:omit-tag="">
<div tal:condition="menu" tal:omit-tag="">
<div tal:repeat="items menu" tal:omit-tag="">
<P></P><b><font color="#0033CC"><span
tal:replace="items/title_or_id">folder id</span></font></b><br>
<font size="-1">
<div tal:define="submenu here/org/subMenuWidget.py" tal:omit-tag="">
 <span tal:condition="submenu" tal:omit-tag="">
 <span tal:repeat="subitems submenu" tal:omit-tag="">
  <span tal:replace="subitems/title_or_id">subfolder</span>
   </span>
    </span>
     <p tal:condition="not:submenu"><b>Submenu Here</b></p>
     </div>
     </font>
   <p></p>
    </div>
     </div>
    <p tal:condition="not:menu"><b>Main Menu Here</b></p>
   </div>
-------------------------------------------


content of subMenuWidget.py
-------------------------------------------
submenuitems = context.objectValues('Page Template')
d1 = {}
returnitems = []
for eachItem in submenuitems:
   if eachItem.getProperty('isRanked',0):
      index = eachItem.getProperty('isRanked',1000)
      while d1.has_key(index):
         index = index + 1
      d1[index] = eachItem
keys = d1.keys()
keys.sort()
for key in keys:
   dictObject = d1[key]
   returnitems.append(dictObject)
return returnitems
-------------------------------------