[z3-five] Re: another newbie cmf/plone integration question...

Lennart Regebro regebro at gmail.com
Mon Jun 13 14:06:15 CEST 2005


The template variables, like context, container and those, is defined
in pt_getContext(), like nyah:

        c = {'template': self,
             'here': here,
             'context': here,
             'container': self._getContainer(),
             'nothing': None,
             'options': {},
             'root': root,
             'request': request,
             'modules': ModuleImporter,
             }

_getContainer() is defined in Shared/DC/Scripts/Bindings.py for some
weird reason:

    def _getContainer(self):
        # Utility for bindcode.
        while 1:
            self = self.aq_inner.aq_parent
            if not getattr(self, '_is_wrapperish', None):
                parent = getattr(self, 'aq_parent', None)
                inner = getattr(self, 'aq_inner', None)
                container = getattr(inner, 'aq_parent', None)
                try: getSecurityManager().validate(parent, container, '', self)
                except Unauthorized:
                    return UnauthorizedBinding('container', self)
                return self

This will indeed, when the template calls it in Five, return the view.
Which isn't what I expect, I  I tried replacing "self._getContainer()"
with "here._getContainer()" which seems to make more sense to me, but
of course, since here doesn't inherit from Bindings, that fails. So, I
made a new variation of _getContainer that takes a parameter, and I
use self._getContainer(here) to get the container of "here" instead of
"self". This passes the unit tests. I have made no real actual testing
of this patch, but I attach it so that people who have the problem can
test it.

If it works, I'll check it in.
-------------- next part --------------
Index: pagetemplatefile.py
===================================================================
--- pagetemplatefile.py	(revision 12943)
+++ pagetemplatefile.py	(working copy)
@@ -19,6 +19,8 @@
 
 # Zope 2
 from Globals import package_home
+from AccessControl import getSecurityManager
+from Shared.DC.Scripts.Bindings import Unauthorized, UnauthorizedBinding
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
 # Zope 3
@@ -82,7 +84,7 @@
         c = {'template': self,
              'here': here,
              'context': here,
-             'container': self._getContainer(),
+             'container': self._getContainer(here),
              'nothing': None,
              'options': {},
              'root': root,
@@ -98,6 +100,22 @@
     pt_getContext = rebindFunction(_pt_getContext,
                                    SecureModuleImporter=ModuleImporter)
 
+    def _getContainer(self, here=None):
+        # Utility for bindcode.
+        if here is None:
+            here = self
+        while 1:
+            here = here.aq_inner.aq_parent
+            if not getattr(here, '_is_wrapperish', None):
+                parent = getattr(here, 'aq_parent', None)
+                inner = getattr(here, 'aq_inner', None)
+                container = getattr(inner, 'aq_parent', None)
+                try: getSecurityManager().validate(parent, container, '', here)
+                except Unauthorized:
+                    return UnauthorizedBinding('container', here)
+                return here
+
+
 # this is not in use right now, but would be how to integrate Zope 3 page
 # templates instead of Zope 2 page templates
 class FivePageTemplateFile(ViewPageTemplateFile):


More information about the z3-five mailing list