From 38676af45cdaf213cff82fc505496dfe8e104268 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Wed, 26 Sep 2007 21:06:31 +0000
Subject: [PATCH] Fixed issue related to inheritances in Form fields and ZMI.

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

diff --git a/product/ERP5Type/Interactor.py b/product/ERP5Type/Interactor.py
index d79cd06631..1582d3af89 100644
--- a/product/ERP5Type/Interactor.py
+++ b/product/ERP5Type/Interactor.py
@@ -1,16 +1,17 @@
 from Products.ERP5Type.Accessor.Accessor import Accessor as Method
 from Products.ERP5Type.Base import _aq_reset
-
+import Acquisition
+from Acquisition import aq_parent
 """
   Current implementation uses callable objects.
   Using decorator would be more modern and consistent with
   recent evolution of python. But we have 2.3 ERP5 users
   so we should, at least, provide both implementations.
-  
+
   Code structure should be changed so that Interactors
   because a new "type" of ERP5 class such Document
   with a modular plugin structure.
-  
+
   TODO: multiple instances of interactors could
   use different parameters. This way, interactions
   can be defined on "instances" or can be
@@ -19,15 +20,18 @@ from Products.ERP5Type.Base import _aq_reset
 
 
 class InteractorMethodCall:
-  
+
   def __init__(self, method, instance, *args, **kw):
     self.instance = instance
     self.args = args
     self.kw = kw
     self.method = method
-    
+
   def __call__(self):
-    return self.method(self.instance, *self.args, **self.kw)
+    # We use self.__dict__['instance'] to prevent inserting the
+    # InteractorMethodCall instance in the acquisition chain
+    # which has some side effects
+    return self.method(self.__dict__['instance'], *self.args, **self.kw)
 
 class InteractorMethod(Method):
 
@@ -174,6 +178,37 @@ class FieldValueInteractor(Interactor):
     Form.purgeFieldValueCache()
     ProxyField.purgeFieldValueCache()
 
+class TypeInteractorExample(Interactor):
+  def __init__(self, portal_type):
+    self.portal_type = portal_type
+
+  def install(self):
+    from Products.CMFCore.TypesTool import TypesTool
+    self.on(TypesTool.manage_edit).doAfter(self.doSomething)
+
+  def doSomething(self, method_call_object):
+    if self.portal_type == method_call_object.instance.portal_type:
+      pass
+      # do whatever
+
+class InteractorOfInteractor(Interactor):
+
+  def __init__(self, interactor):
+    self.interactor = interactor
+
+  def install(self):
+    self.on(interactor.doSomething).doAfter(self.doSomething)
+
+  def doSomething(self, method_call_object):
+    pass
+
+
+#test = AqDynamicInteractor()
+#test.install()
+
+
+#interactor_of_interactor = InteractorOfInteractor(test)
+#interactor_of_interactor.install()
 # This is used in ERP5Form and install method is called in ERP5Form
 fielf_value_interactor = FieldValueInteractor()
-#fielf_value_interactor.install()
+fielf_value_interactor.install()
-- 
2.30.9