[Erp5-report] r39135 kazuhiko - in /erp5/trunk/products/ERP5Type: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Oct 14 14:29:54 CEST 2010
Author: kazuhiko
Date: Thu Oct 14 14:29:50 2010
New Revision: 39135
URL: http://svn.erp5.org?rev=39135&view=rev
Log:
introduce Base.getOriginalDocument() that returns :
* the original document for an asContext() result document.
* self for a real document.
* None for a temporary document.
Modified:
erp5/trunk/products/ERP5Type/Base.py
erp5/trunk/products/ERP5Type/tests/testERP5Type.py
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=39135&r1=39134&r2=39135&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Thu Oct 14 14:29:50 2010
@@ -2801,12 +2801,31 @@ class Base( CopyContainer,
for k in REQUEST.keys():
if k != 'SESSION':
setattr(context, k, REQUEST[k])
+ # Set the original document
+ kw['_original'] = self
# Define local properties
context.__dict__.update(kw)
return context
else:
return context.asContext(REQUEST=REQUEST, **kw)
+ security.declarePublic('getOriginalDocument')
+ def getOriginalDocument(self, context=None, REQUEST=None, **kw):
+ """
+ This method returns:
+ * the original document for an asContext() result document.
+ * self for a real document.
+ * None for a temporary document.
+ """
+ if not self.isTempObject():
+ return self
+ else:
+ original = getattr(self, '_original', None)
+ if original is not None:
+ return aq_inner(original)
+ else:
+ return None
+
security.declarePublic('isTempObject')
def isTempObject(self):
"""Return true if self is an instance of a temporary document class.
Modified: erp5/trunk/products/ERP5Type/tests/testERP5Type.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testERP5Type.py?rev=39135&r1=39134&r2=39135&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testERP5Type.py [utf8] Thu Oct 14 14:29:50 2010
@@ -1338,6 +1338,9 @@ class TestPropertySheet:
obj.setTitle('obj title')
copy = obj.asContext()
self.assertTrue(copy.isTempObject(), '%r is not a temp object' % (copy,))
+ self.assertEquals(obj, copy.getOriginalDocument())
+ self.assertEquals(obj.absolute_url(),
+ copy.getOriginalDocument().absolute_url())
copy.setTitle('copy title')
self.assertEquals('obj title', obj.getTitle())
self.assertEquals('copy title', copy.getTitle())
@@ -1671,6 +1674,7 @@ class TestPropertySheet:
from Products.ERP5Type.Document import newTempPerson
o = newTempPerson(portal, 'temp_person_1')
self.assertTrue(o.isTempObject())
+ self.assertEquals(o.getOriginalDocument(), None)
# This should generate a workflow method.
self.assertEquals(o.getValidationState(), 'draft')
More information about the Erp5-report
mailing list