[CMF-checkins] SVN: CMF/trunk/CMF - fixed REQUEST handling
Yvo Schubbe
y.2007- at wcm-solutions.de
Thu Jun 21 14:42:37 EDT 2007
Log message for revision 76916:
- fixed REQUEST handling
all tests pass now without using REQUEST in the utility wrapper
Changed:
U CMF/trunk/CMFCalendar/CalendarTool.py
U CMF/trunk/CMFCore/Expression.py
U CMF/trunk/CMFCore/MemberDataTool.py
U CMF/trunk/CMFCore/URLTool.py
U CMF/trunk/CMFCore/tests/test_ActionProviderBase.py
U CMF/trunk/CMFCore/tests/test_DynamicType.py
U CMF/trunk/CMFDefault/RegistrationTool.py
U CMF/trunk/CMFDefault/skins/zpt_control/members_add_control.py
U CMF/trunk/CMFDefault/tests/RegistrationTool.txt
-=-
Modified: CMF/trunk/CMFCalendar/CalendarTool.py
===================================================================
--- CMF/trunk/CMFCalendar/CalendarTool.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCalendar/CalendarTool.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -82,7 +82,7 @@
, use_session
, show_states=None
, firstweekday=None
- ):
+ , REQUEST=None):
""" Change the configuration of the calendar tool
"""
self.calendar_types = tuple(show_types)
@@ -102,8 +102,8 @@
# Do nothing with illegal values
pass
- if hasattr(self.REQUEST, 'RESPONSE'):
- self.REQUEST.RESPONSE.redirect('manage_configure')
+ if hasattr(REQUEST, 'RESPONSE'):
+ REQUEST.RESPONSE.redirect('manage_configure')
security.declarePrivate('_getCalendar')
def _getCalendar(self):
Modified: CMF/trunk/CMFCore/Expression.py
===================================================================
--- CMF/trunk/CMFCore/Expression.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCore/Expression.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -25,7 +25,7 @@
from Products.PageTemplates.Expressions import SecureModuleImporter
from interfaces import IMembershipTool
-from interfaces import ISiteRoot
+from utils import getToolByName
class Expression(Persistent):
@@ -66,7 +66,8 @@
else:
ec = None
if ec is None:
- portal = getUtility(ISiteRoot)
+ utool = getToolByName(context, 'portal_url')
+ portal = utool.getPortalObject()
if object is None or not hasattr(object, 'aq_base'):
folder = portal
else:
Modified: CMF/trunk/CMFCore/MemberDataTool.py
===================================================================
--- CMF/trunk/CMFCore/MemberDataTool.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCore/MemberDataTool.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -51,7 +51,6 @@
id = 'portal_memberdata'
meta_type = 'CMF Member Data Tool'
- _v_temps = None
_properties = ()
security = ClassSecurityInfo()
@@ -172,7 +171,7 @@
def pruneMemberDataContents(self):
""" Delete data contents of all members not listet in acl_users.
"""
- membertool= getUtility(IMembershipTool)
+ membertool = getUtility(IMembershipTool)
members = self._members
user_list = membertool.listMemberIds()
@@ -188,27 +187,12 @@
'''
id = u.getId()
members = self._members
- if not members.has_key(id):
- # Get a temporary member that might be
- # registered later via registerMemberData().
- temps = self._v_temps
- if temps is not None and temps.has_key(id):
- m = temps[id]
- else:
- base = aq_base(self)
- m = MemberData(base, id)
- if temps is None:
- self._v_temps = {id:m}
- if hasattr(self, 'REQUEST'):
- # No REQUEST during tests.
- self.REQUEST._hold(CleanupTemp(self))
- else:
- temps[id] = m
- else:
- m = members[id]
+ if not id in members:
+ base = aq_base(self)
+ members[id] = MemberData(base, id)
# Return a wrapper with self as containment and
# the user as context.
- return m.__of__(self).__of__(u)
+ return members[id].__of__(self).__of__(u)
security.declarePrivate('registerMemberData')
def registerMemberData(self, m, id):
@@ -231,21 +215,6 @@
registerToolInterface('portal_memberdata', IMemberDataTool)
-class CleanupTemp:
-
- """Used to cleanup _v_temps at the end of the request."""
-
- def __init__(self, tool):
- self._tool = tool
-
- def __del__(self):
- try:
- del self._tool._v_temps
- except (AttributeError, KeyError):
- # The object has already been deactivated.
- pass
-
-
class MemberData(SimpleItem):
implements(IMemberData)
@@ -254,17 +223,11 @@
def __init__(self, tool, id):
self.id = id
- # Make a temporary reference to the tool.
- # The reference will be removed by notifyModified().
- self._tool = tool
security.declarePrivate('notifyModified')
def notifyModified(self):
# Links self to parent for full persistence.
- tool = getattr(self, '_tool', None)
- if tool is not None:
- del self._tool
- tool.registerMemberData(self, self.getId())
+ self.getTool().registerMemberData(self, self.getId())
security.declarePublic('getUser')
def getUser(self):
Modified: CMF/trunk/CMFCore/URLTool.py
===================================================================
--- CMF/trunk/CMFCore/URLTool.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCore/URLTool.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -75,11 +75,9 @@
def getPortalObject(self):
""" Get the portal object itself.
"""
- site = queryUtility(ISiteRoot)
- if site is None:
- # fallback
- return aq_parent(aq_inner(self))
- return site
+ # XXX: this method violates the rules for tools/utilities:
+ # queryUtility(ISiteRoot) doesn't work because we need the REQUEST
+ return aq_parent( aq_inner(self) )
security.declarePublic('getRelativeContentPath')
def getRelativeContentPath(self, content):
Modified: CMF/trunk/CMFCore/tests/test_ActionProviderBase.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_ActionProviderBase.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCore/tests/test_ActionProviderBase.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -23,7 +23,6 @@
from zope.testing.cleanup import cleanUp
from Products.CMFCore.interfaces import IMembershipTool
-from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.tests.base.dummy import DummySite
from Products.CMFCore.tests.base.dummy import DummyTool
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
@@ -69,7 +68,7 @@
SecurityRequestTest.setUp(self)
self.site = DummySite('site').__of__(self.root)
sm = getSiteManager()
- sm.registerUtility(self.site, ISiteRoot)
+ utool = self.site._setObject( 'portal_url', DummyTool() )
sm.registerUtility(DummyTool(), IMembershipTool)
def tearDown(self):
Modified: CMF/trunk/CMFCore/tests/test_DynamicType.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_DynamicType.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFCore/tests/test_DynamicType.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -155,10 +155,10 @@
SecurityRequestTest.setUp(self)
self.site = DummySite('site').__of__(self.root)
sm = getSiteManager()
- sm.registerUtility(self.site, ISiteRoot)
self.site._setObject( 'portal_membership', DummyTool() )
sm.registerUtility(self.site.portal_membership, IMembershipTool)
self.site._setObject( 'portal_types', TypesTool() )
+ self.site._setObject( 'portal_url', DummyTool() )
fti = FTIDATA_CMF15[0].copy()
self.site.portal_types._setObject( 'Dummy Content 15', FTI(**fti) )
self.site._setObject( 'foo', DummyContent() )
Modified: CMF/trunk/CMFDefault/RegistrationTool.py
===================================================================
--- CMF/trunk/CMFDefault/RegistrationTool.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFDefault/RegistrationTool.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -144,7 +144,7 @@
kw = {'member': member, 'password': member.getPassword()}
if getattr(aq_base(method), 'isDocTemp', 0):
- mail_text = method(self, self.REQUEST, **kw)
+ mail_text = method(self, REQUEST, **kw)
else:
mail_text = method(**kw)
@@ -154,7 +154,7 @@
return self.mail_password_response( self, REQUEST )
security.declarePublic( 'registeredNotify' )
- def registeredNotify( self, new_member_id, password=None ):
+ def registeredNotify(self, new_member_id, REQUEST, password=None):
""" Handle mailing the registration / welcome message.
"""
membership = getUtility(IMembershipTool)
@@ -176,7 +176,7 @@
kw = {'member': member, 'password': password, 'email': email}
if getattr(aq_base(method), 'isDocTemp', 0):
- mail_text = method(self, self.REQUEST, **kw)
+ mail_text = method(self, REQUEST, **kw)
else:
mail_text = method(**kw)
Modified: CMF/trunk/CMFDefault/skins/zpt_control/members_add_control.py
===================================================================
--- CMF/trunk/CMFDefault/skins/zpt_control/members_add_control.py 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFDefault/skins/zpt_control/members_add_control.py 2007-06-21 18:42:36 UTC (rev 76916)
@@ -17,7 +17,7 @@
return context.setStatus(False, errmsg)
else:
if ptool.getProperty('validate_email') or send_password:
- rtool.registeredNotify(member_id)
+ rtool.registeredNotify(member_id, context.REQUEST)
if mtool.checkPermission(ManageUsers, mtool):
return context.setStatus(True, _(u'Member registered.'))
else:
Modified: CMF/trunk/CMFDefault/tests/RegistrationTool.txt
===================================================================
--- CMF/trunk/CMFDefault/tests/RegistrationTool.txt 2007-06-21 18:39:19 UTC (rev 76915)
+++ CMF/trunk/CMFDefault/tests/RegistrationTool.txt 2007-06-21 18:42:36 UTC (rev 76916)
@@ -43,7 +43,7 @@
mailPassword sends a password reminder and returns a response page::
- >>> rtool.mailPassword('foo', None)
+ >>> rtool.mailPassword('foo', app.REQUEST)
'done'
>>> getUtility(IMailHost).lastMessage
@@ -51,7 +51,7 @@
registeredNotify sends a welcome message::
- >>> rtool.registeredNotify('foo')
+ >>> rtool.registeredNotify('foo', app.REQUEST)
>>> getUtility(IMailHost).lastMessage
'Welcome: foo, secret, foo at example.org'
More information about the CMF-checkins
mailing list