[Erp5-report] r38613 nicolas.dumazet - in /erp5/trunk/products: ERP5/ ERP5Type/patches/ ERP...
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Sep 24 11:46:10 CEST 2010
Author: nicolas.dumazet
Date: Fri Sep 24 11:46:09 2010
New Revision: 38613
URL: http://svn.erp5.org?rev=38613&view=rev
Log:
backport some equivalence of Zope2.12 getSite to be able to retrieve
the site from anywhere.
Also setSite() in places where the published object is not in the site
or before an ERP5 site installation: this is required for portal types
as classes in 2.12 as PARENTS is not anymore there in the request.
If some traces appear in the logs for 2.12 instances, the proper fix
is to add a setSite() in the codepath leading to the point using getSite()
Added:
erp5/trunk/products/ERP5Type/patches/getSite.py
Modified:
erp5/trunk/products/ERP5/ERP5Site.py
erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
Modified: erp5/trunk/products/ERP5/ERP5Site.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/ERP5Site.py?rev=38613&r1=38612&r2=38613&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/ERP5Site.py [utf8] (original)
+++ erp5/trunk/products/ERP5/ERP5Site.py [utf8] Fri Sep 24 11:46:09 2010
@@ -36,6 +36,7 @@ from Products.ERP5Type.Log import log as
from Products.CMFActivity.Errors import ActivityPendingError
import ERP5Defaults
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
+from zope.site.hooks import setSite
from zLOG import LOG, INFO
from string import join
@@ -351,6 +352,14 @@ class ERP5Site(FolderMixIn, CMFSite):
security.declareProtected(Permissions.AccessContentsInformation, 'getPath')
getPath = getUrl
+ security.declareProtected(Permissions.AccessContentsInformation, 'objectValues')
+ def objectValues(self, *args, **kw):
+ # When stepping in an ERP5Site from outside,
+ # (e.g. left hand tree frame in {zope root}/manage )
+ # we need to set up the site to load portal types inside each site
+ setSite(self)
+ return super(FolderMixIn, self).objectValues(*args, **kw)
+
security.declareProtected(Permissions.AccessContentsInformation, 'searchFolder')
def searchFolder(self, **kw):
"""
@@ -359,6 +368,7 @@ class ERP5Site(FolderMixIn, CMFSite):
"""
if not kw.has_key('parent_uid'):
kw['parent_uid'] = self.uid
+ setSite(self)
return self.portal_catalog.searchResults(**kw)
security.declareProtected(Permissions.AccessContentsInformation, 'countFolder')
@@ -369,6 +379,7 @@ class ERP5Site(FolderMixIn, CMFSite):
"""
if not kw.has_key('parent_uid'):
kw['parent_uid'] = self.uid
+ setSite(self)
return self.portal_catalog.countResults(**kw)
# Proxy methods for security reasons
@@ -1466,6 +1477,23 @@ class ERP5Generator(PortalGenerator):
# Return the fully wrapped object.
p = parent.this()._getOb(id)
+ setSite(p)
+
+ try:
+ sm = p.getSiteManager()
+ except:
+ # Zope 2.8, ot site manager, no DefaultTraversable, dont care
+ pass
+ else:
+ import zope
+ # XXX hackish, required to setUpERP5Core while in tests,
+ # could probably be better
+ # (for some reason calling setSite here does not allow
+ # the newly created site to find the global DefaultTraversable
+ # object)
+ sm.registerAdapter(zope.traversing.adapters.DefaultTraversable,
+ required=(zope.interface.Interface,))
+
erp5_sql_deferred_connection_string = erp5_sql_connection_string
p._setProperty('erp5_catalog_storage',
erp5_catalog_storage, 'string')
Added: erp5/trunk/products/ERP5Type/patches/getSite.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/getSite.py?rev=38613&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/getSite.py (added)
+++ erp5/trunk/products/ERP5Type/patches/getSite.py [utf8] Fri Sep 24 11:46:09 2010
@@ -0,0 +1,62 @@
+from zLOG import LOG
+module_name = 'zope.site.hooks'
+native_setsite = False
+try:
+ hooks = __import__(module_name, {}, {}, module_name)
+ native = True
+except ImportError:
+ # backwards compatibility for Zope < 2.12
+ import imp, sys
+ sys.modules[module_name] = hooks = imp.new_module(module_name)
+ def setSite(foo=None):
+ pass
+ hooks.setSite = setSite
+ def getSite(foo=None):
+ return None
+ hooks.getSite = getSite
+
+# patch getSite so that it works everywhere
+from Products.ERP5Type.Globals import get_request
+
+oldgetsite = hooks.getSite
+def getSite():
+ try:
+ x = oldgetsite()
+ # this should be enough for Zope 2.12
+ if x is not None:
+ return x
+ except:
+ if native_setsite:
+ # this should not happen on 2.12, log it
+ import traceback; traceback.print_stack()
+ LOG('getSite() cant retrieve the site', 100,
+ 'setSite() should have been called earlier on')
+ pass
+ # and Zope 2.8 needs to use the request
+ parents = get_request()['PARENTS']
+
+ portal = None
+ for item in parents:
+ if item.meta_type == 'ERP5 Site':
+ portal = item
+ break
+
+ if portal is None:
+ # not perfect?
+ try:
+ portal = parents[-1].getPortalObject()
+ except:
+ import traceback; traceback.print_stack()
+ raise AttributeError("getSite() cant retrieve the site.")
+
+ return portal
+hooks.getSite = getSite
+
+from Products.CMFActivity.ActivityTool import ActivityTool
+ActivityTool_process_timer = ActivityTool.process_timer
+def process_timer(self, *args, **kw):
+ portal = self.getPortalObject()
+ hooks.setSite(portal)
+ return ActivityTool_process_timer(self, *args, **kw)
+ActivityTool.process_timer = process_timer
+
Modified: erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py?rev=38613&r1=38612&r2=38613&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/ERP5TypeTestCase.py [utf8] Fri Sep 24 11:46:09 2010
@@ -46,13 +46,6 @@ def get_request():
Products.ERP5Type.Utils.get_request = get_request
Globals.get_request = get_request
-try:
- from zope.site.hooks import setSite
-except ImportError:
- # BACK: Zope 2.8. setSite is somewhere else, and we can't use it anyway
- # since ERP5Site is not yet an ISite. Remove once we drop support for 2.8
- def setSite(site=None):
- pass
try:
import itools.zope
@@ -917,6 +910,8 @@ class ERP5TypeTestCase(ProcessingNodeTes
transaction.commit()
self.portal = portal
+ setSite(portal)
+
# Make sure skins are correctly set-up (it's not implicitly set up
# by Acquisition on Zope 2.12 as it is on 2.8)
portal.setupCurrentSkin(portal.REQUEST)
More information about the Erp5-report
mailing list