Commit 3d968036 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: Interactor: No more im_class attribute in Python3.

This changes the API to implement similar feature in Python3, but this should
not be an issue because Interactor are only for non-ERP5 object...
parent f60aa262
...@@ -48,8 +48,8 @@ class PortalTypeClassInteractor(Interactor): ...@@ -48,8 +48,8 @@ class PortalTypeClassInteractor(Interactor):
self.on(Variables.setStateVar).doAfter(self.resetDynamic) self.on(Variables.setStateVar).doAfter(self.resetDynamic)
from Products.Localizer.Localizer import Localizer from Products.Localizer.Localizer import Localizer
self.on(Localizer.add_language).doAfter(self.resetDynamic) self.on(Localizer, 'add_language').doAfter(self.resetDynamic)
self.on(Localizer.del_language).doAfter(self.resetDynamic) self.on(Localizer, 'del_language').doAfter(self.resetDynamic)
def resetDynamic(self, method_call_object, *args, **kw): def resetDynamic(self, method_call_object, *args, **kw):
""" """
......
...@@ -38,14 +38,14 @@ class FieldValueCacheInteractor(Interactor): ...@@ -38,14 +38,14 @@ class FieldValueCacheInteractor(Interactor):
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
from Products.ERP5Form.ProxyField import ProxyField from Products.ERP5Form.ProxyField import ProxyField
from Products.Formulator.Form import ZMIForm from Products.Formulator.Form import ZMIForm
self.on(ZMIField.manage_edit).doAfter(self.purgeFieldValueCache) self.on(ZMIField, 'manage_edit').doAfter(self.purgeFieldValueCache)
self.on(ZMIField.manage_edit_xmlrpc).doAfter(self.purgeFieldValueCache) self.on(ZMIField, 'manage_edit_xmlrpc').doAfter(self.purgeFieldValueCache)
self.on(ZMIField.manage_tales).doAfter(self.purgeFieldValueCache) self.on(ZMIField, 'manage_tales').doAfter(self.purgeFieldValueCache)
self.on(ZMIField.manage_tales_xmlrpc).doAfter(self.purgeFieldValueCache) self.on(ZMIField, 'manage_tales_xmlrpc').doAfter(self.purgeFieldValueCache)
self.on(ProxyField.manage_edit).doAfter(self.purgeFieldValueCache) self.on(ProxyField, 'manage_edit').doAfter(self.purgeFieldValueCache)
self.on(ProxyField.manage_edit_target).doAfter(self.purgeFieldValueCache) self.on(ProxyField, 'manage_edit_target').doAfter(self.purgeFieldValueCache)
self.on(ProxyField.manage_tales).doAfter(self.purgeFieldValueCache) self.on(ProxyField, 'manage_tales').doAfter(self.purgeFieldValueCache)
self.on(ZMIForm.manage_renameObject).doAfter(self.purgeFieldValueCache) self.on(ZMIForm, 'manage_renameObject').doAfter(self.purgeFieldValueCache)
def purgeFieldValueCache(self, method_call_object): def purgeFieldValueCache(self, method_call_object):
""" """
......
...@@ -94,17 +94,25 @@ class InteractorSource: ...@@ -94,17 +94,25 @@ class InteractorSource:
""" """
""" """
def __init__(self, method): def __init__(self, *args):
""" """
Register method Register method
""" """
self.method = method if len(args) == 1:
self.klass = method.im_class
self.method = method
else:
# No im_class on Python3 and Interactors only makes sense with non-ERP5
# objects anyway, so add a class argument to InteractorSource to make it
# simple
self.klass = args[0]
self.method = getattr(self.klass, args[1])
def doBefore(self, action, *args, **kw): def doBefore(self, action, *args, **kw):
""" """
""" """
if not isinstance(self.method, InteractorMethod): if not isinstance(self.method, InteractorMethod):
im_class = self.method.im_class im_class = self.klass
# Turn this into an InteractorMethod # Turn this into an InteractorMethod
interactor_method = InteractorMethod(self.method) interactor_method = InteractorMethod(self.method)
setattr(im_class, self.method.__name__, interactor_method) setattr(im_class, self.method.__name__, interactor_method)
...@@ -116,7 +124,7 @@ class InteractorSource: ...@@ -116,7 +124,7 @@ class InteractorSource:
""" """
""" """
if not isinstance(self.method, InteractorMethod): if not isinstance(self.method, InteractorMethod):
im_class = self.method.im_class im_class = self.klass
# Turn this into an InteractorMethod # Turn this into an InteractorMethod
interactor_method = InteractorMethod(self.method) interactor_method = InteractorMethod(self.method)
setattr(im_class, self.method.__name__, interactor_method) setattr(im_class, self.method.__name__, interactor_method)
...@@ -147,9 +155,9 @@ class Interactor: ...@@ -147,9 +155,9 @@ class Interactor:
raise NotImplementedError raise NotImplementedError
# Interaction implementation # Interaction implementation
def on(self, method): def on(self, *args):
""" """
Parameters may hold predicates ? Parameters may hold predicates ?
no need - use InteractorMethodCall and decide on action no need - use InteractorMethodCall and decide on action
""" """
return InteractorSource(method) return InteractorSource(*args)
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