Commit 51cdca82 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Create a temp object through type information, instead of making a hack inside...

Create a temp object through type information, instead of making a hack inside asContext. This fixes a bug that the return value of asContext is not a temp object.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38650 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d61836cf
......@@ -2792,14 +2792,17 @@ class Base( CopyContainer,
ex : joe_person = person_module.bob_person.asContext(first_name='Joe')
"""
if context is None:
# Make a copy
klass = self.__class__
try:
context = klass(self.getId())
except TypeError:
# If __init__ does not take the id argument, the class is probably
# a tool, and the id is predifined and immutable.
context = klass()
pt = self._getTypesTool()
type_info = pt.getTypeInfo(self.getPortalType())
if type_info is None:
raise ValueError('No such content type: %s' % portal_type)
context = type_info.constructInstance(
container=self.getParentValue(),
id=self.getId(),
temp_object=True,
is_indexable=False)
context.__dict__.update(self.__dict__)
# Copy REQUEST properties to self
if REQUEST is not None:
......@@ -2811,13 +2814,7 @@ class Base( CopyContainer,
setattr(context, k, REQUEST[k])
# Define local properties
context.__dict__.update(kw)
# Make it a temp content
temp_object = TempBase(self.getId())
for k in ('isIndexable', 'isTempDocument', 'reindexObject',
'recursiveReindexObject', 'activate', 'setUid'):
setattr(context, k, getattr(temp_object, k))
# Return result
return context.__of__(self.aq_parent)
return context
else:
return context.asContext(REQUEST=REQUEST, **kw)
......
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