[Checkins] SVN: Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/ - work on replaceable MemberData implementation

Jens Vagelpohl jens at dataflake.org
Sat May 16 04:46:04 EDT 2009


Log message for revision 100009:
  - work on replaceable MemberData implementation

Changed:
  U   Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/MemberDataTool.py
  U   Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tests/test_MemberDataTool.py
  U   Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tool.zcml

-=-
Modified: Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/MemberDataTool.py
===================================================================
--- Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/MemberDataTool.py	2009-05-16 08:37:08 UTC (rev 100008)
+++ Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/MemberDataTool.py	2009-05-16 08:46:03 UTC (rev 100009)
@@ -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/branches/jens_replaceable_memberdata/Products/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tests/test_MemberDataTool.py	2009-05-16 08:37:08 UTC (rev 100008)
+++ Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tests/test_MemberDataTool.py	2009-05-16 08:46:03 UTC (rev 100009)
@@ -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/branches/jens_replaceable_memberdata/Products/CMFCore/tool.zcml
===================================================================
--- Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tool.zcml	2009-05-16 08:37:08 UTC (rev 100008)
+++ Products.CMFCore/branches/jens_replaceable_memberdata/Products/CMFCore/tool.zcml	2009-05-16 08:46:03 UTC (rev 100009)
@@ -34,4 +34,9 @@
       global="False"
       />
 
+  <utility
+      component=".MemberDataTool.memberFactory"
+      name="MemberData"
+      />
+
 </configure>



More information about the Checkins mailing list