[Zope-Checkins] SVN: Zope/branches/wichert-ofs-paste-naming/ Pass object to CopyContainer._get_id
Wichert Akkerman
cvs-admin at zope.org
Fri Jan 11 12:55:37 UTC 2013
Log message for revision 129036:
Pass object to CopyContainer._get_id
Modify OFS.CopySupport.CopyContainer to pass the object to _get_id as well,
allowing for more flexible id generation logic such as using INameChooser.
Changed:
A Zope/branches/wichert-ofs-paste-naming/
U Zope/branches/wichert-ofs-paste-naming/doc/CHANGES.rst
U Zope/branches/wichert-ofs-paste-naming/src/OFS/CopySupport.py
U Zope/branches/wichert-ofs-paste-naming/src/OFS/tests/testCopySupport.py
-=-
Modified: Zope/branches/wichert-ofs-paste-naming/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.13/doc/CHANGES.rst 2013-01-11 12:53:01 UTC (rev 129035)
+++ Zope/branches/wichert-ofs-paste-naming/doc/CHANGES.rst 2013-01-11 12:55:37 UTC (rev 129036)
@@ -8,6 +8,9 @@
2.13.20 (unreleased)
--------------------
+- OFS: Modify CopyContainer to pass the object to _get_id as well,
+ allowing for more flexible id generation logic such as using INameChooser.
+
- In PageTemplate.pt_errors accept the check_macro_expansion argument.
This is added for compatibility with zope.pagetemplate 4.0.0. The
argument is ignored. See LP #732972.
@@ -16,6 +19,7 @@
- Products.ZCTextIndex = 2.13.4
+
2.13.19 (2012-10-31)
--------------------
Modified: Zope/branches/wichert-ofs-paste-naming/src/OFS/CopySupport.py
===================================================================
--- Zope/branches/2.13/src/OFS/CopySupport.py 2013-01-11 12:53:01 UTC (rev 129035)
+++ Zope/branches/wichert-ofs-paste-naming/src/OFS/CopySupport.py 2013-01-11 12:55:37 UTC (rev 129036)
@@ -151,7 +151,7 @@
return self.manage_main(self, REQUEST)
return cp
- def _get_id(self, id):
+ def _get_id(self, id, obj=None):
# Allow containers to override the generation of
# object copy id by attempting to call its _get_id
# method, if it exists.
@@ -224,7 +224,11 @@
message=sys.exc_info()[1],
action='manage_main'))
- id = self._get_id(orig_id)
+ try:
+ id = self._get_id(orig_id, ob)
+ except TypeError:
+ # BBB for classes which do not have the second parameter.
+ id = self._get_id(orig_id)
result.append({'id': orig_id, 'new_id': id})
orig_ob = ob
@@ -271,7 +275,11 @@
if aq_base(orig_container) is aq_base(self):
id = orig_id
else:
- id = self._get_id(orig_id)
+ try:
+ id = self._get_id(orig_id, ob)
+ except TypeError:
+ # BBB for classes which do not have the second parameter.
+ id = self._get_id(orig_id)
result.append({'id': orig_id, 'new_id': id})
notify(ObjectWillBeMovedEvent(ob, orig_container, orig_id,
Modified: Zope/branches/wichert-ofs-paste-naming/src/OFS/tests/testCopySupport.py
===================================================================
--- Zope/branches/2.13/src/OFS/tests/testCopySupport.py 2013-01-11 12:53:01 UTC (rev 129035)
+++ Zope/branches/wichert-ofs-paste-naming/src/OFS/tests/testCopySupport.py 2013-01-11 12:55:37 UTC (rev 129036)
@@ -170,6 +170,22 @@
self.assertTrue('newfile' in self.folder1.objectIds())
self.assertTrue('newfile' in self.folder2.objectIds())
+ def testPasteOld_get_idWithoutObjParameter( self ):
+ from OFS.CopySupport import CopyContainer
+ self.assertTrue( 'file' in self.folder1.objectIds() )
+ self.assertFalse( 'file' in self.folder2.objectIds() )
+
+ old_get_id = CopyContainer._get_id
+ try:
+ CopyContainer._get_id = lambda self, id: 'copy'
+ cookie = self.folder1.manage_copyObjects( ids=('file',) )
+ result = self.folder2.manage_pasteObjects( cookie )
+ self.assertTrue( 'file' in self.folder1.objectIds() )
+ self.assertTrue( 'copy' in self.folder2.objectIds() )
+ self.assertTrue( result == [{'id':'file', 'new_id':'copy'}])
+ finally:
+ CopyContainer._get_id = old_get_id
+
def testPasteSingleNotSameID( self ):
self.assertTrue( 'file' in self.folder1.objectIds() )
self.assertFalse( 'file' in self.folder2.objectIds() )
More information about the Zope-Checkins
mailing list