[CMF-checkins] SVN: CMF/branches/efge-1.5-five-compatible/C Behave well with Five 1.3/1.2.

Florent Guillaume fg at nuxeo.com
Thu Nov 10 11:19:00 EST 2005


Log message for revision 40028:
  Behave well with Five 1.3/1.2.
  
  We have to use super() to call the base classes, and
  not redo recursion ourselves.
  
  One test is still failing, Products.CMFUid.tests.test_uidannotation
  .UniqueIdAnnotationTests.test_simulateNestedFolderCloneRemovingUid1
  
  Note that I consider the way that opaque subobjects have been redesigned
  to be inefficient and not well designed, to stay polite.
  
  

Changed:
  U   CMF/branches/efge-1.5-five-compatible/CHANGES.txt
  U   CMF/branches/efge-1.5-five-compatible/CMFCore/CMFCatalogAware.py
  U   CMF/branches/efge-1.5-five-compatible/CMFCore/tests/base/dummy.py
  U   CMF/branches/efge-1.5-five-compatible/CMFDefault/File.py
  U   CMF/branches/efge-1.5-five-compatible/CMFDefault/Image.py
  U   CMF/branches/efge-1.5-five-compatible/CMFDefault/tests/test_Image.py

-=-
Modified: CMF/branches/efge-1.5-five-compatible/CHANGES.txt
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CHANGES.txt	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CHANGES.txt	2005-11-10 16:18:59 UTC (rev 40028)
@@ -1,3 +1,10 @@
+Branch
+
+  Others
+
+    - Refactored the various manage_afterAdd & co to play well with Five
+      1.2.
+
 CMF 1.5.5-beta (2005/11/06)
 
   Bug Fixes

Modified: CMF/branches/efge-1.5-five-compatible/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CMFCore/CMFCatalogAware.py	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CMFCore/CMFCatalogAware.py	2005-11-10 16:18:59 UTC (rev 40028)
@@ -226,14 +226,14 @@
         """
             Recurse in both normal and opaque subobjects.
         """
-        values = self.objectValues()
-        opaque_values = self.opaqueValues()
-        for subobjects in values, opaque_values:
-            for ob in subobjects:
-                s = getattr(ob, '_p_changed', 0)
-                if hasattr(aq_base(ob), name):
-                    getattr(ob, name)(*args)
-                if s is None: ob._p_deactivate()
+        # Call the base class to recurse in normal objectValues
+        getattr(super(CMFCatalogAware, self), name)(*args)
+        # Recurse in opaqueValues
+        for ob in self.opaqueValues():
+            s = getattr(ob, '_p_changed', 0)
+            if hasattr(aq_base(ob), name):
+                getattr(ob, name)(*args)
+            if s is None: ob._p_deactivate()
 
     # ZMI
     # ---

Modified: CMF/branches/efge-1.5-five-compatible/CMFCore/tests/base/dummy.py
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CMFCore/tests/base/dummy.py	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CMFCore/tests/base/dummy.py	2005-11-10 16:18:59 UTC (rev 40028)
@@ -97,12 +97,12 @@
     def manage_afterAdd( self, item, container ):
         self.after_add_called = 1
         if self.catalog:
-            PortalContent.manage_afterAdd( self, item, container )
+            super(DummyContent, self).manage_afterAdd(item, container)
 
     def manage_beforeDelete( self, item, container ):
         self.before_delete_called = 1
         if self.catalog:
-            PortalContent.manage_beforeDelete( self, item, container )
+            super(DummyContent, self).manage_beforeDelete(item, container)
 
     def absolute_url(self):
        return self.url

Modified: CMF/branches/efge-1.5-five-compatible/CMFDefault/File.py
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CMFDefault/File.py	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CMFDefault/File.py	2005-11-10 16:18:59 UTC (rev 40028)
@@ -105,10 +105,7 @@
     self._getOb(id).manage_upload(file)
 
 
-class File( OFS.Image.File
-          , PortalContent
-          , DefaultDublinCoreImpl
-          ):
+class File(PortalContent, OFS.Image.File, DefaultDublinCoreImpl):
     """
         A Portal-managed File
     """
@@ -154,6 +151,8 @@
                 ):
         OFS.Image.File.__init__( self, id, title, file
                                , content_type, precondition )
+        self._setId(id)
+        delattr(self, '__name__')
 
         # If no file format has been passed in, rely on what OFS.Image.File
         # detected. Unlike Images, which have code to try and pick the content
@@ -166,6 +165,12 @@
                                , contributors, effective_date, expiration_date
                                , format, language, rights )
 
+    # For old instances where bases had OFS.Image.File first,
+    # the id was actually stored in __name__.
+    # getId() will do the correct thing here, as id() is callable
+    def id(self):
+        return self.__name__
+
     security.declareProtected(View, 'SearchableText')
     def SearchableText(self):
         """
@@ -174,24 +179,6 @@
         """
         return "%s %s" % (self.title, self.description)
 
-    security.declarePrivate('manage_afterAdd')
-    def manage_afterAdd(self, item, container):
-        """Both of my parents have an afterAdd method"""
-        OFS.Image.File.manage_afterAdd(self, item, container)
-        PortalContent.manage_afterAdd(self, item, container)
-
-    security.declarePrivate('manage_afterClone')
-    def manage_afterClone(self, item):
-        """Both of my parents have an afterClone method"""
-        OFS.Image.File.manage_afterClone(self, item)
-        PortalContent.manage_afterClone(self, item)
-
-    security.declarePrivate('manage_beforeDelete')
-    def manage_beforeDelete(self, item, container):
-        """Both of my parents have a beforeDelete method"""
-        PortalContent.manage_beforeDelete(self, item, container)
-        OFS.Image.File.manage_beforeDelete(self, item, container)
-
     security.declarePrivate('_isNotEmpty')
     def _isNotEmpty(self, file):
         """ Do various checks on 'file' to try to determine non emptiness. """

Modified: CMF/branches/efge-1.5-five-compatible/CMFDefault/Image.py
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CMFDefault/Image.py	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CMFDefault/Image.py	2005-11-10 16:18:59 UTC (rev 40028)
@@ -97,10 +97,7 @@
     self._getOb(id).manage_upload(file)
 
 
-class Image( OFS.Image.Image
-           , PortalContent
-           , DefaultDublinCoreImpl
-           ):
+class Image(PortalContent, OFS.Image.Image, DefaultDublinCoreImpl):
     """
         A Portal-managed Image
     """
@@ -146,6 +143,8 @@
                 ):
         OFS.Image.File.__init__( self, id, title, file
                                , content_type, precondition )
+        self._setId(id)
+        delattr(self, '__name__')
 
         # If no file format has been passed in, rely on what OFS.Image.File
         # detected.
@@ -156,6 +155,12 @@
                                , contributors, effective_date, expiration_date
                                , format, language, rights )
 
+    # For old instances where bases had OFS.Image.Image first,
+    # the id was actually stored in __name__.
+    # getId() will do the correct thing here, as id() is callable
+    def id(self):
+        return self.__name__
+
     security.declareProtected(View, 'SearchableText')
     def SearchableText(self):
         """
@@ -164,24 +169,6 @@
         """
         return "%s %s" % (self.title, self.description)
 
-    security.declarePrivate('manage_afterAdd')
-    def manage_afterAdd(self, item, container):
-        """Both of my parents have an afterAdd method"""
-        OFS.Image.Image.manage_afterAdd(self, item, container)
-        PortalContent.manage_afterAdd(self, item, container)
-
-    security.declarePrivate('manage_afterClone')
-    def manage_afterClone(self, item):
-        """Both of my parents have an afterClone method"""
-        OFS.Image.Image.manage_afterClone(self, item)
-        PortalContent.manage_afterClone(self, item)
-
-    security.declarePrivate('manage_beforeDelete')
-    def manage_beforeDelete(self, item, container):
-        """Both of my parents have a beforeDelete method"""
-        PortalContent.manage_beforeDelete(self, item, container)
-        OFS.Image.Image.manage_beforeDelete(self, item, container)
-
     security.declarePrivate('_isNotEmpty')
     def _isNotEmpty(self, file):
         """ Do various checks on 'file' to try to determine non emptiness. """

Modified: CMF/branches/efge-1.5-five-compatible/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/branches/efge-1.5-five-compatible/CMFDefault/tests/test_Image.py	2005-11-10 16:15:04 UTC (rev 40027)
+++ CMF/branches/efge-1.5-five-compatible/CMFDefault/tests/test_Image.py	2005-11-10 16:18:59 UTC (rev 40028)
@@ -53,6 +53,26 @@
         self.site = DummySite('site')
         self.site._setObject( 'portal_membership', DummyTool() )
 
+    def test_getId_on_old_Image_instance(self):
+        image = self.site._setObject( 'testimage', Image('testimage') )
+        self.assertEqual(image.getId(), 'testimage')
+        self.assertEqual(image.id, 'testimage')
+        # Mimick old instance when base classes had OFS.Image.Image first
+        image.__name__ = 'testimage'
+        delattr(image, 'id')
+        self.assertEqual(image.getId(), 'testimage')
+        self.assertEqual(image.id(), 'testimage')
+
+    def test_getId_on_old_File_instance(self):
+        file = self.site._setObject( 'testfile', File('testfile') )
+        self.assertEqual(file.getId(), 'testfile')
+        self.assertEqual(file.id, 'testfile')
+        # Mimick old instance when base classes had OFS.Image.File first
+        file.__name__ = 'testfile'
+        delattr(file, 'id')
+        self.assertEqual(file.getId(), 'testfile')
+        self.assertEqual(file.id(), 'testfile')
+
     def test_EditWithEmptyFile(self):
         # Test handling of empty file uploads
         image = self.site._setObject( 'testimage', Image('testimage') )



More information about the CMF-checkins mailing list