r13672 - in archetypes.schemaextender/trunk: . archetypes/schemaextender

"Malthe Borch" <[email protected]> Wed, 08 Jun 2011 11:22:27 +0000
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: mborch
Date: Wed Jun  8 11:22:25 2011
New Revision: 13672

Modified:
   archetypes.schemaextender/trunk/CHANGES.txt
   archetypes.schemaextender/trunk/archetypes/schemaextender/extender.py
Log:
Fall back to local site hook to get (acquire) request-object for non-acquisition-wrapped objects. This fixes an issue in which DTML templates would become very inefficient due to lack of acquisition-wrapping (in scenarios seen "in the wild"). The DTML code is largely written in C, but my clue is that there's a bug in there, possibly after Acquisition-behavior was changed in Zope 2.12.

Modified: archetypes.schemaextender/trunk/CHANGES.txt
==============================================================================
--- archetypes.schemaextender/trunk/CHANGES.txt	(original)
+++ archetypes.schemaextender/trunk/CHANGES.txt	Wed Jun  8 11:22:25 2011
@@ -4,6 +4,12 @@
 2.1.1 - Unreleased
 ------------------
 
+* Acquire request object via local site hook if object is not
+  acquisition-wrapped (in ``cachingInstanceSchemaFactory``). This
+  fixes caching issues with objects rendered using DTML. Note that
+  this is likely a bug in the ``DocumentTemplate`` code. Ideally, the
+  issue should be resolved there.
+
 2.1 - 2011-01-03
 ----------------
 

Modified: archetypes.schemaextender/trunk/archetypes/schemaextender/extender.py
==============================================================================
--- archetypes.schemaextender/trunk/archetypes/schemaextender/extender.py	(original)
+++ archetypes.schemaextender/trunk/archetypes/schemaextender/extender.py	Wed Jun  8 11:22:25 2011
@@ -11,6 +11,13 @@
 from zope.component import adapter, getAdapters
 from zope.interface import implementer
 from plone.uuid.interfaces import IUUID
+
+try:
+    from zope.site.hooks import getSite
+except ImportError:
+    # BBB, for older Zope 2
+    from zope.app.component.hooks import getSite
+
 try:
     from plone.browserlayer.utils import registered_layers
     has_plone_browserlayer = True
@@ -112,8 +119,17 @@
     """ schema adapter factory using a cache on the request object """
     schema = None
     if CACHE_ENABLED:
-        request = getattr(context, 'REQUEST', None)
-        if request is not None and not isinstance(request, str):
+        try:
+            lookup = context.aq_acquire
+        except AttributeError:
+            site = getSite()
+            lookup = site.ac_acquire
+
+        try:
+            request = lookup('REQUEST')
+        except AttributeError:
+            pass
+        else:
             attr = CACHE_KEY
             cache = getattr(request, attr, _marker)
             if cache is _marker:

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev