[Checkins] SVN: Products.CMFCore/trunk/Products/CMFCore/ - MemberData tool: Make it easier to override the default

Jens Vagelpohl jens at dataflake.org
Sun May 24 04:55:50 EDT 2009


Log message for revision 100324:
  - MemberData tool: Make it easier to override the default
    MemberData implementation by trying to look up a named
    factory utility named "MemberData" before falling back on the
    default MemberData class. 
    (https://bugs.launchpad.net/zope-cmf/+bug/377208)
  

Changed:
  U   Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
  U   Products.CMFCore/trunk/Products/CMFCore/MemberDataTool.py
  U   Products.CMFCore/trunk/Products/CMFCore/tests/test_MemberDataTool.py
  U   Products.CMFCore/trunk/Products/CMFCore/tool.zcml

-=-
Modified: Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2009-05-24 08:49:42 UTC (rev 100323)
+++ Products.CMFCore/trunk/Products/CMFCore/CHANGES.txt	2009-05-24 08:55:49 UTC (rev 100324)
@@ -4,6 +4,12 @@
 2.2.0 (unreleased)
 ------------------
 
+- MemberData tool: Make it easier to override the default 
+  MemberData implementation by trying to look up a named 
+  factory utility named "MemberData" before falling back on the
+  default MemberData class.
+  (https://bugs.launchpad.net/zope-cmf/+bug/377208)
+
 - FSPageTemplate: Change the charset/encoding detection to consider 
   charset specifications in the content type, and replace the
   hardcoded Latin-15 fallback with the mechanism used by the 

Modified: Products.CMFCore/trunk/Products/CMFCore/MemberDataTool.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/MemberDataTool.py	2009-05-24 08:49:42 UTC (rev 100323)
+++ Products.CMFCore/trunk/Products/CMFCore/MemberDataTool.py	2009-05-24 08:55:49 UTC (rev 100324)
@@ -22,6 +22,9 @@
 from BTrees.OOBTree import OOBTree
 from OFS.PropertyManager import PropertyManager
 from OFS.SimpleItem import SimpleItem
+from zope.component import queryUtility
+from zope.component.factory import Factory
+from zope.component.interfaces import IFactory
 from zope.interface import implements
 from ZPublisher.Converters import type_converters
 
@@ -193,8 +196,11 @@
         id = u.getId()
         members = self._members
         if not id in members:
+            member_factory = queryUtility(IFactory, u'MemberData')
+            if member_factory is None:
+                member_factory = MemberData
             base = aq_base(self)
-            members[id] = MemberData(base, id)
+            members[id] = member_factory(base, id)
         # Return a wrapper with self as containment and
         # the user as context.
         return members[id].__of__(self).__of__(u)
@@ -405,3 +411,5 @@
     # deprecated for use with CMF applications.
 
 InitializeClass(MemberData)
+
+memberFactory = Factory(MemberData)

Modified: Products.CMFCore/trunk/Products/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/tests/test_MemberDataTool.py	2009-05-24 08:49:42 UTC (rev 100323)
+++ Products.CMFCore/trunk/Products/CMFCore/tests/test_MemberDataTool.py	2009-05-24 08:55:49 UTC (rev 100324)
@@ -19,6 +19,8 @@
 import Testing
 
 import Acquisition
+from zope.component import provideUtility
+from zope.component.interfaces import IFactory
 from zope.interface.verify import verifyClass
 from zope.testing.cleanup import cleanUp
 
@@ -51,6 +53,9 @@
         self.roles = tuple(roles)
         self.domains = tuple(domains)
 
+    def getId(self):
+        return self.name
+
     def getUserName(self):
         return self.name
 
@@ -120,7 +125,22 @@
         self.assertEqual(info_dict['member_count'], 0)
         self.assertEqual(info_dict['orphan_count'], 0)
 
+    def test_switching_memberdata_factory(self):
+        from Products.CMFCore.MemberDataTool import MemberData
+        tool = self._makeOne()
+        user = DummyUser('dummy', '', [], [])
+        member = Acquisition.aq_base(tool.wrapUser(user))
+        self.assertEquals(getattr(member, 'iamnew', None), None)
 
+        class NewMemberData(MemberData):
+            iamnew = 'yes'
+        provideUtility(NewMemberData, IFactory, 'MemberData')
+
+        user = DummyUser('dummy2', '', [], [])
+        member = Acquisition.aq_base(tool.wrapUser(user))
+        self.assertEquals(getattr(member, 'iamnew', None), 'yes')
+
+
 class MemberDataTests(unittest.TestCase):
 
     def _makeOne(self, *args, **kw):

Modified: Products.CMFCore/trunk/Products/CMFCore/tool.zcml
===================================================================
--- Products.CMFCore/trunk/Products/CMFCore/tool.zcml	2009-05-24 08:49:42 UTC (rev 100323)
+++ Products.CMFCore/trunk/Products/CMFCore/tool.zcml	2009-05-24 08:55:49 UTC (rev 100324)
@@ -34,4 +34,9 @@
       global="False"
       />
 
+  <utility
+      component=".MemberDataTool.memberFactory"
+      name="MemberData"
+      />
+
 </configure>



More information about the Checkins mailing list