From 530acb3df15a7e62eb00b92661059538e5c1eeae Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Mon, 16 Aug 2004 07:56:15 +0000
Subject: [PATCH] TempBase back home. context fixed

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1352 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/Base.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py
index 910b35dc5e..aefa6fec81 100755
--- a/product/ERP5Type/Base.py
+++ b/product/ERP5Type/Base.py
@@ -60,6 +60,7 @@ from string import join
 import sys
 import psyco
 import pickle
+import copy
 
 from cStringIO import StringIO
 from email.MIMEBase import MIMEBase
@@ -1260,13 +1261,23 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
   # Context related methods
   security.declarePublic('asContext')
   def asContext(self, context=None, REQUEST=None, **kw):
-    # PERFORMANCE ISSUE
-    from Products.ERP5Type.Context import newContext
     if context is None:
-      return newContext(context=self, REQUEST=REQUEST, **kw)
+      # Make a copy
+      context = self.__class__(self.getId())
+      context.__dict__.update(self.__dict__)
+      # Copy REQUEST properties to self
+      if REQUEST is not None:
+        context.__dict__.update(REQUEST)
+      # Define local properties
+      if kw is not None: context.__dict__.update(kw)
+      # Make it a temp content      
+      for k in ('isIndexable', 'reindexObject', 'recursiveReindexObject', 'activate', 'setUid', ):
+        setattr(context, k, getattr(TempBase,k))
+      # Return result              
+      return context.__of__(self)
     else:
       return context.asContext(REQUEST=REQUEST, **kw)
-
+    
   # Workflow Related Method
   security.declarePublic('getWorkflowStateItemList')
   def getWorkflowStateItemList(self):
@@ -1464,6 +1475,8 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
         local_permission_list = (local_permission_list,)
       setattr(self,permission_name,tuple(local_permission_list))
 
+InitializeClass(Base)
+
 class TempBase(Base):
   """
     If we need Base services (categories, edit, etc) in temporary objects
@@ -1474,11 +1487,11 @@ class TempBase(Base):
   def reindexObject(self, *args, **kw):
     pass
 
+  def recursiveReindexObject(self, *args, **kw):
+    pass
+
   def activate(self):
     return self
 
   def setUid(self, value):
     self.uid = value # Required for Listbox so that no casting happens when we use TempBase to create new objects
-
-InitializeClass(Base)
-
-- 
2.30.9