Commit ca687acf authored by Jérome Perrin's avatar Jérome Perrin

Use getattr instead of hasattr when checking ActivityBuffer.

Attach the traceback to failure notification messages.
Add some docstrings.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6958 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0ae0218b
...@@ -30,13 +30,14 @@ import ExtensionClass ...@@ -30,13 +30,14 @@ import ExtensionClass
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from Products.CMFCore.utils import getToolByName
try: try:
from Products.CMFCore import permissions from Products.CMFCore import permissions
except ImportError: except ImportError:
from Products.CMFCore import CMFCorePermissions as permissions from Products.CMFCore import CMFCorePermissions as permissions
from zLOG import LOG from zLOG import LOG, WARNING
DEFAULT_ACTIVITY = 'SQLDict' DEFAULT_ACTIVITY = 'SQLDict'
...@@ -45,16 +46,28 @@ DISTRIBUTABLE_STATE = -1 ...@@ -45,16 +46,28 @@ DISTRIBUTABLE_STATE = -1
INVOKE_ERROR_STATE = -2 INVOKE_ERROR_STATE = -2
VALIDATE_ERROR_STATE = -3 VALIDATE_ERROR_STATE = -3
STOP_STATE = -4 STOP_STATE = -4
POSITIVE_NODE_STATE = 'Positive Node State' # Special state which allows to select positive nodes # Special state which allows to select positive nodes
POSITIVE_NODE_STATE = 'Positive Node State'
class ActiveObject(ExtensionClass.Base): class ActiveObject(ExtensionClass.Base):
"""Active Object Mixin Class.
Active object are objects whose methods are lazilly evaluated in the
Activity Queue. To use an active object, you just have to call the
method on the wrapper returned by the `activate` method like this:
>>> obj.activate().aMethod()
This will defer the call to obj.aMethod()
"""
security = ClassSecurityInfo() security = ClassSecurityInfo()
def activate(self, activity=DEFAULT_ACTIVITY, active_process=None, passive_commit=0, def activate(self, activity=DEFAULT_ACTIVITY, active_process=None,
activate_kw=None,**kw): passive_commit=0, activate_kw=None, **kw):
""" """Returns an active wrapper for this object.
Reserved Optional parameters
Reserved Optional parameters:
at_date -- request execution date for this activate call at_date -- request execution date for this activate call
...@@ -68,8 +81,17 @@ class ActiveObject(ExtensionClass.Base): ...@@ -68,8 +81,17 @@ class ActiveObject(ExtensionClass.Base):
after_path -- never validate message if after_path after_path -- never validate message if after_path
is in the list of path which are is in the list of path which are
going to be executed going to be executed
after_path_and_method_id
-- never validate message if a message for
method_id on path is in the queue.
tag -- add a tag to a message
after_tag -- never validate message if there is a message
tagged with this tag.
""" """
# Get activate values from activate_kw, then _v_activate_kw # Get activate values from activate_kw, then _v_activate_kw
# only if they are not set directly as arguments to activate() # only if they are not set directly as arguments to activate()
...@@ -79,11 +101,11 @@ class ActiveObject(ExtensionClass.Base): ...@@ -79,11 +101,11 @@ class ActiveObject(ExtensionClass.Base):
kw[key] = value kw[key] = value
# This volatile variable '_v_activate_kw' can be used to pass parameters # This volatile variable '_v_activate_kw' can be used to pass parameters
# automatically to activate. # automatically to activate.
if hasattr(self, '_v_activate_kw'): if getattr(self, '_v_activate_kw', None) is not None:
for key,value in self._v_activate_kw.items(): for key,value in self._v_activate_kw.items():
if not kw.has_key(key): if not kw.has_key(key):
kw[key] = value kw[key] = value
activity_tool = getattr(self, 'portal_activities', None) activity_tool = getToolByName(self, 'portal_activities', None)
if activity_tool is None: return self # Do nothing if no portal_activities if activity_tool is None: return self # Do nothing if no portal_activities
# activate returns an ActiveWrapper # activate returns an ActiveWrapper
# a queue can be provided as well as extra parameters # a queue can be provided as well as extra parameters
...@@ -93,7 +115,8 @@ class ActiveObject(ExtensionClass.Base): ...@@ -93,7 +115,8 @@ class ActiveObject(ExtensionClass.Base):
except ConflictError: except ConflictError:
raise raise
except: except:
LOG("WARNING CMFActivity:",0, 'could not create activity for %s' % self.getRelativeUrl()) LOG("CMFActivity", WARNING,
'could not create activity for %s' % self.getRelativeUrl())
# If the portal_activities were not created # If the portal_activities were not created
# return a passive object # return a passive object
if passive_commit: get_transaction().commit() if passive_commit: get_transaction().commit()
...@@ -101,18 +124,13 @@ class ActiveObject(ExtensionClass.Base): ...@@ -101,18 +124,13 @@ class ActiveObject(ExtensionClass.Base):
security.declareProtected( permissions.ModifyPortalContent, 'flushActivity' ) security.declareProtected( permissions.ModifyPortalContent, 'flushActivity' )
def flushActivity(self, invoke=0, **kw): def flushActivity(self, invoke=0, **kw):
activity_tool = getattr(self, 'portal_activities', None) activity_tool = getToolByName(self, 'portal_activities', None)
if activity_tool is None: return # Do nothing if no portal_activities if activity_tool is None: return # Do nothing if no portal_activities
# flush all activities related to this object # flush all activities related to this object
#try: activity_tool.flush(self, invoke=invoke, **kw)
if 1:
activity_tool.flush(self, invoke=invoke, **kw) security.declareProtected( permissions.ModifyPortalContent,
#except: 'recursiveFlushActivity' )
# # If the portal_activities were not created
# # nothing to do
# pass
security.declareProtected( permissions.ModifyPortalContent, 'recursiveFlushActivity' )
def recursiveFlushActivity(self, invoke=0, **kw): def recursiveFlushActivity(self, invoke=0, **kw):
# flush all activities related to this object # flush all activities related to this object
self.flushActivity(invoke=invoke, **kw) self.flushActivity(invoke=invoke, **kw)
...@@ -123,10 +141,9 @@ class ActiveObject(ExtensionClass.Base): ...@@ -123,10 +141,9 @@ class ActiveObject(ExtensionClass.Base):
security.declareProtected( permissions.View, 'hasActivity' ) security.declareProtected( permissions.View, 'hasActivity' )
def hasActivity(self, **kw): def hasActivity(self, **kw):
"""Tells if there is pending activities for this object.
""" """
Tells if an object if active activity_tool = getToolByName(self, 'portal_activities', None)
"""
activity_tool = getattr(self, 'portal_activities', None)
if activity_tool is None: return 0 # Do nothing if no portal_activities if activity_tool is None: return 0 # Do nothing if no portal_activities
try: try:
return activity_tool.hasActivity(self, **kw) return activity_tool.hasActivity(self, **kw)
...@@ -139,20 +156,19 @@ class ActiveObject(ExtensionClass.Base): ...@@ -139,20 +156,19 @@ class ActiveObject(ExtensionClass.Base):
security.declareProtected( permissions.View, 'hasErrorActivity' ) security.declareProtected( permissions.View, 'hasErrorActivity' )
def hasErrorActivity(self, **kw): def hasErrorActivity(self, **kw):
""" """Tells if there is failed activities for this object.
Tells if an object if active
""" """
return self.hasActivity(processing_node = INVOKE_ERROR_STATE) return self.hasActivity(processing_node = INVOKE_ERROR_STATE)
security.declareProtected( permissions.View, 'hasInvalidActivity' ) security.declareProtected( permissions.View, 'hasInvalidActivity' )
def hasInvalidActivity(self, **kw): def hasInvalidActivity(self, **kw):
""" """Tells if there is invalied activities for this object.
Tells if an object if active
""" """
return self.hasActivity(processing_node = VALIDATE_ERROR_STATE) return self.hasActivity(processing_node = VALIDATE_ERROR_STATE)
security.declareProtected( permissions.View, 'getActiveProcess' ) security.declareProtected( permissions.View, 'getActiveProcess' )
def getActiveProcess(self): def getActiveProcess(self):
activity_tool = getattr(self, 'portal_activities', None) activity_tool = getToolByName(self, 'portal_activities', None)
if activity_tool is None: return None # Do nothing if no portal_activities if activity_tool is None: return None # Do nothing if no portal_activities
return self.portal_activities.getActiveProcess() return activity_tool.getActiveProcess()
This diff is collapsed.
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