Commit 3f1855f5 authored by Jean-Paul Smets's avatar Jean-Paul Smets

New error / result API


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@563 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6a8ed492
......@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
from Products.CMFCore import CMFCorePermissions
from Products.ERP5Type.Base import Base
from Products.ERP5Type import PropertySheet
from BTrees.OOBTree import OOTreeSet
from zLOG import LOG
......@@ -78,30 +79,35 @@ class ActiveProcess(Base):
constructors = (manage_addActiveProcessForm, addActiveProcess)
# Base methods
security.declareProtected(CMFCorePermissions.ManagePortal, 'postError')
def postError(self, error):
self.error_list = getattr(self, 'error_list', []) + [error]
security.declareProtected(CMFCorePermissions.ManagePortal, 'getErrorList')
def getErrorList(self):
"""
Returns the list of errors
"""
return self.error_list
security.declareProtected(CMFCorePermissions.ManagePortal, 'getErrorListText')
def getErrorListText(self):
security.declareProtected(CMFCorePermissions.ManagePortal, 'postResult')
def postResult(self, result):
if not hasattr(self, 'result_list'):
self.result_list = OOTreeSet()
self.result_list.insert(result)
security.declareProtected(CMFCorePermissions.ManagePortal, 'getResultList')
def getResultList(self):
"""
Returns the list of errors as text
Returns the list of results
"""
return '\n'.join(map(lambda x:repr(x), self.error_list))
if not hasattr(self, 'result_list'):
self.result_list = OOTreeSet()
return self.result_list
# security.declareProtected(CMFCorePermissions.ManagePortal, 'getErrorListText')
# def getResultListText(self):
# """
# Returns the list of errors as text
# """
# return '\n'.join(map(lambda x:repr(x), self.error_list))
#
security.declareProtected(CMFCorePermissions.ManagePortal, 'activateResult')
def activateResult(self, result):
if result not in (None, 0, '', (), []):
#self.activate().postError(result)
self.postError(result) # Until we get SQLQueue
self.postResult(result) # Until we get SQLQueue
# If result is a callable, then use it to propagate result (... ??? )
#if callable(result):
# return self.activateResult(Result(self, 'activateResult',result())
InitializeClass( ActiveProcess )
......@@ -58,6 +58,26 @@ def registerActivity(activity):
activity_list.append(activity_instance)
activity_dict[activity.__name__] = activity_instance
class Result:
def __init__(self, object_or_path, method_id, result, title=None, id=None, message=None):
# Some utility function to do this would be useful since we use it everywhere XXX
if type(object_or_path) in (type([]), type(())):
url = '/'.join(object_or_path)
path = object_or_path
elif type(object_or_path) is type('a'):
path = object_or_path.split('/')
url = object_or_path
else:
path = object_or_path.getPhysicalPath()
url = '/'.join(path)
self.path = path
self.url = url
self.result = result # Include arbitrary result
self.title = title # Should follow Zope convention for LOG title
self.id = id # Should follow Zope convention for LOG ids
self.message = message # Should follow Zope convention for LOG message
class Message:
def __init__(self, object, active_process, activity_kw, method_id, args, kw):
if type(object) is type('a'):
......@@ -89,7 +109,7 @@ class Message:
result = getattr(object, self.method_id)(*self.args, **self.kw)
if REQUEST.active_process is not None:
active_process = activity_tool.getActiveProcess()
active_process.activateResult(result) # XXX Allow other method_id in future
active_process.activateResult(Result(object,self.method_id,result)) # XXX Allow other method_id in future
self.is_executed = 1
except:
self.is_executed = 0
......
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