[Zope-CMF] Re: [CMF 2.1] FSPageTemplate & Unicode

Hanno Schlichting plone at hannosch.info
Sat Jan 6 09:34:25 EST 2007


Jens Vagelpohl wrote:
> 
> On 6 Jan 2007, at 12:57, Andreas Jung wrote:
>>> On 5 Jan 2007, at 20:51, Andreas Jung wrote:
>>>> I finished my work (including some test).
>>>>
>>>> Any objections merging the changes back to the trunk?
>>>
>>> If the tests pass, no. At least from me ;)
>>>
> 
>> I merged the changes... hopefully without side-effects :-)

Well see ;) But Plone shouldn't have too many problems with it, as it
monkey-patches the hell out of the Zope3 tal and pagetemplate packages
anyways, as it produces UnicodeDecodeErrors all over the place otherwise.

> Now is the best time, I'm sure Plone 3 testing will give it the best
> workout it can get. I hope to finish my huge checkin (deprecating
> getToolByName and replacing it with utility calls) this weekend.

Regarding your greatly appreciated utilities work, I have tried it with
the current Plone 3 bundle and found various problems. After fixing
various code snippets, I have it in a state where the tests start at
least and we get about 200 errors for the CMFPlone tests.

I had to change two things in CMF so far though. Here are the patches I
came up with:

In DCWorkflow/Expression.py the workflow is not aq-wrapped anymore, so
you cannot call getPhysicalRoot on it anymore. But luckily we can use
the object instead.

The second one is even more important. The URLTool's getPortalObject
method was pretty dumb so far and returned the aq_parent of the tool. As
the tool can get pretty awkward aq_chains now, as getToolByName wraps
the tool inside the callers context, we need a better approach.

The simplest one I came up with is to do an recursive loop and check if
the parent implements ISiteRoot. This should get you the real portal
object. At least with this patch another 300 unit tests pass in CMFPlone
where about 500 failed before.

Another way would potentially be to register the portal object itself as
a utility, so you could query it directly, but that would be a bit of an
extra work...

I'll try to find out what's causing the other test failures in Plone :)

Hanno


Index: Expression.py
===================================================================
--- Expression.py       (revision 71731)
+++ Expression.py       (working copy)
@@ -122,7 +122,7 @@
         'container':    container,
         'folder':       container,
         'nothing':      None,
-        'root':         wf.getPhysicalRoot(),
+        'root':         ob.getPhysicalRoot(),
         'request':      getattr( ob, 'REQUEST', None ),
         'modules':      SecureModuleImporter,
         'user':         getSecurityManager().getUser(),


Index: URLTool.py
===================================================================
--- URLTool.py  (revision 71731)
+++ URLTool.py  (working copy)
@@ -24,6 +24,7 @@
 from zope.interface import implements

 from ActionProviderBase import ActionProviderBase
+from interfaces import ISiteRoot
 from interfaces import IURLTool
 from interfaces.portal_url import portal_url as z2IURLTool
 from permissions import ManagePortal
@@ -74,7 +75,15 @@
     def getPortalObject(self):
         """ Get the portal object itself.
         """
-        return aq_parent( aq_inner(self) )
+        portal = aq_inner(self)
+        while True:
+            portal = getattr(portal, 'aq_parent', None)
+            if portal is None:
+                break
+            if ISiteRoot.providedBy(portal):
+                return portal
+        # Portal could not be found, log an error or raise one?
+        return aq_inner(self)

     security.declarePublic('getRelativeContentPath')
     def getRelativeContentPath(self, content):



More information about the Zope-CMF mailing list