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, ...@@ -2792,14 +2792,17 @@ class Base( CopyContainer,
ex : joe_person = person_module.bob_person.asContext(first_name='Joe') ex : joe_person = person_module.bob_person.asContext(first_name='Joe')
""" """
if context is None: if context is None:
# Make a copy pt = self._getTypesTool()
klass = self.__class__ type_info = pt.getTypeInfo(self.getPortalType())
try: if type_info is None:
context = klass(self.getId()) raise ValueError('No such content type: %s' % portal_type)
except TypeError:
# If __init__ does not take the id argument, the class is probably context = type_info.constructInstance(
# a tool, and the id is predifined and immutable. container=self.getParentValue(),
context = klass() id=self.getId(),
temp_object=True,
is_indexable=False)
context.__dict__.update(self.__dict__) context.__dict__.update(self.__dict__)
# Copy REQUEST properties to self # Copy REQUEST properties to self
if REQUEST is not None: if REQUEST is not None:
...@@ -2811,13 +2814,7 @@ class Base( CopyContainer, ...@@ -2811,13 +2814,7 @@ class Base( CopyContainer,
setattr(context, k, REQUEST[k]) setattr(context, k, REQUEST[k])
# Define local properties # Define local properties
context.__dict__.update(kw) context.__dict__.update(kw)
# Make it a temp content return context
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)
else: else:
return context.asContext(REQUEST=REQUEST, **kw) 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