[CMF-checkins] SVN: CMF/trunk/C Merged forgotten r40207 and part of
r40401 from 1.6 branch:
Florent Guillaume
fg at nuxeo.com
Sat Jan 21 13:34:10 EST 2006
Log message for revision 41403:
Merged forgotten r40207 and part of r40401 from 1.6 branch:
(Originally from efge-1.5-five-compatible branch)
Reordered base classes of File and Image, to allow use of super().
Removed misleading comments about base class ordering in File and Image
classes.
Changed:
U CMF/trunk/CHANGES.txt
U CMF/trunk/CMFDefault/File.py
U CMF/trunk/CMFDefault/Image.py
U CMF/trunk/CMFDefault/tests/test_File.py
U CMF/trunk/CMFDefault/tests/test_Image.py
-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt 2006-01-21 15:51:20 UTC (rev 41402)
+++ CMF/trunk/CHANGES.txt 2006-01-21 18:34:10 UTC (rev 41403)
@@ -280,6 +280,8 @@
- Made unit tests close the request properly.
+ - Reordered base classes of File and Image, to allow use of super().
+
CMF 1.5.x
For a complete list see CHANGES.txt of CMF-1_5-branch.
Modified: CMF/trunk/CMFDefault/File.py
===================================================================
--- CMF/trunk/CMFDefault/File.py 2006-01-21 15:51:20 UTC (rev 41402)
+++ CMF/trunk/CMFDefault/File.py 2006-01-21 18:34:10 UTC (rev 41403)
@@ -69,24 +69,11 @@
self._getOb(id).manage_upload(file)
-class File(OFS.Image.File, PortalContent, DefaultDublinCoreImpl):
+class File(PortalContent, OFS.Image.File, DefaultDublinCoreImpl):
"""A Portal-managed File.
"""
- # The order of base classes is very significant in this case.
- # Image.File does not store it's id in it's 'id' attribute.
- # Rather, it has an 'id' method which returns the contents of the
- # instnace's __name__ attribute. Inheriting in the other order
- # obscures this method, resulting in much pulling of hair and
- # gnashing of teeth and fraying of nerves. Don't do it.
- #
- # Really.
- #
- # Note that if you use getId() to retrieve an object's ID, you will avoid
- # this problem altogether. getId is the new way, accessing .id is
- # deprecated.
-
implements(IDAVAware)
__implements__ = ( PortalContent.__implements__
, DefaultDublinCoreImpl.__implements__
@@ -116,6 +103,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
@@ -128,6 +117,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):
"""
Modified: CMF/trunk/CMFDefault/Image.py
===================================================================
--- CMF/trunk/CMFDefault/Image.py 2006-01-21 15:51:20 UTC (rev 41402)
+++ CMF/trunk/CMFDefault/Image.py 2006-01-21 18:34:10 UTC (rev 41403)
@@ -67,24 +67,11 @@
self._getOb(id).manage_upload(file)
-class Image(OFS.Image.Image, PortalContent, DefaultDublinCoreImpl):
+class Image(PortalContent, OFS.Image.Image, DefaultDublinCoreImpl):
"""A Portal-managed Image.
"""
- # The order of base classes is very significant in this case.
- # Image.Image does not store it's id in it's 'id' attribute.
- # Rather, it has an 'id' method which returns the contents of the
- # instnace's __name__ attribute. Inheriting in the other order
- # obscures this method, resulting in much pulling of hair and
- # gnashing of teeth and fraying of nerves. Don't do it.
- #
- # Really.
- #
- # Note that if you use getId() to retrieve an object's ID, you will avoid
- # this problem altogether. getId is the new way, accessing .id is
- # deprecated.
-
implements(IDAVAware)
__implements__ = ( PortalContent.__implements__
, DefaultDublinCoreImpl.__implements__
@@ -114,6 +101,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.
@@ -124,6 +113,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):
"""
Modified: CMF/trunk/CMFDefault/tests/test_File.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_File.py 2006-01-21 15:51:20 UTC (rev 41402)
+++ CMF/trunk/CMFDefault/tests/test_File.py 2006-01-21 18:34:10 UTC (rev 41403)
@@ -38,6 +38,16 @@
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
+ def test_getId_on_old_File_instance(self):
+ file = self._makeOne('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_File_setFormat(self):
# Setting the DC.format must also set the content_type property
file = self._makeOne('testfile', format='image/jpeg')
Modified: CMF/trunk/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Image.py 2006-01-21 15:51:20 UTC (rev 41402)
+++ CMF/trunk/CMFDefault/tests/test_Image.py 2006-01-21 18:34:10 UTC (rev 41403)
@@ -54,6 +54,16 @@
self.site = DummySite('site')
self.site._setObject( 'portal_membership', DummyTool() )
+ def test_getId_on_old_Image_instance(self):
+ image = self.site._setObject('testimage', self._makeOne('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_EditWithEmptyFile(self):
# Test handling of empty file uploads
image = self.site._setObject('testimage', self._makeOne('testimage'))
More information about the CMF-checkins
mailing list