Commit 9d51b80b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

introduce Base.getOriginalDocument() that returns :

  * the original document for an asContext() result document.
  * self for a real document.
  * None for a temporary document.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39135 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9109425c
......@@ -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.
......
......@@ -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')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment