[Zope] context in a Product's python code (not Python Script)

John K. Hohm jhohm@acm.org
Fri, 29 Nov 2002 12:09:00 -0600


I have a Page Template and Python Script that are working fairly well together
to generate a navigational menu on my site, and now I want to make them part of
a product.  I have tried this:

class CMS(Folder):
    # ...

    # old "menu" Page Template copied to www/menu.zpt file
    security.declareProtected('View', 'menu')
    menu = PageTemplateFile('www/menu', globals())
    menu._owner = None

    security.declareProtected('View', 'menu_items')
    def menu_items(self, levels=2, REQUEST=None):
        context = self._getContext
        # body of old "menu_items" Python Script copied here

    def _getContext(self):
        while 1:
            self = self.aq_parent
            if not getattr(self, '_is_wrapperish', None):
                return self

I cannot seem to find the way to get the bindings a Python Script has,
particularly the context binding.  As you can see, I tried grabbing the
_getContext method from Script, but it gives me the root Zope object, instead of
the object that is being requested and having menu called on it from the web. 
What am I doing wrong?