Commit c6e376ad authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: style changes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37682 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51ba7e2a
...@@ -1174,14 +1174,17 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1174,14 +1174,17 @@ class ActivityTool (Folder, UniqueObject):
def invokeGroup(self, method_id, message_list): def invokeGroup(self, method_id, message_list):
if self.activity_tracking: if self.activity_tracking:
activity_tracking_logger.info('invoking group messages: method_id=%s, paths=%s' % (method_id, ['/'.join(m.object_path) for m in message_list])) activity_tracking_logger.info(
'invoking group messages: method_id=%s, paths=%s'
% (method_id, ['/'.join(m.object_path) for m in message_list]))
# Invoke a group method. # Invoke a group method.
object_list = [] object_list = []
expanded_object_list = [] expanded_object_list = []
new_message_list = [] new_message_list = []
path_dict = {} path_dict = {}
# Filter the list of messages. If an object is not available, mark its message as non-executable. # Filter the list of messages. If an object is not available, mark its
# In addition, expand an object if necessary, and make sure that no duplication happens. # message as non-executable. In addition, expand an object if necessary,
# and make sure that no duplication happens.
for m in message_list: for m in message_list:
# alternate method is used to segregate objects which cannot be grouped. # alternate method is used to segregate objects which cannot be grouped.
alternate_method_id = m.activity_kw.get('alternate_method_id') alternate_method_id = m.activity_kw.get('alternate_method_id')
...@@ -1195,40 +1198,27 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1195,40 +1198,27 @@ class ActivityTool (Folder, UniqueObject):
m.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=self)
continue continue
try: try:
i = len(new_message_list) # This is an index of this message in new_message_list. i = len(new_message_list) # This is an index of this message
# in new_message_list
if m.hasExpandMethod(): if m.hasExpandMethod():
for subobj in m.getObjectList(self): subobject_list = m.getObjectList(self)
else:
subobject_list = (obj,)
for subobj in subobject_list:
path = subobj.getPath() path = subobj.getPath()
if path not in path_dict: if path not in path_dict:
path_dict[path] = i path_dict[path] = i
if alternate_method_id is not None \ if alternate_method_id is not None \
and hasattr(aq_base(subobj), alternate_method_id): and hasattr(aq_base(subobj), alternate_method_id):
# if this object is alternated, generate a new single active object. # if this object is alternated,
# generate a new single active object
activity_kw = m.activity_kw.copy() activity_kw = m.activity_kw.copy()
if 'group_method_id' in activity_kw: activity_kw.pop('group_method_id', None)
del activity_kw['group_method_id'] activity_kw.pop('group_id', None)
if 'group_id' in activity_kw:
del activity_kw['group_id']
active_obj = subobj.activate(**activity_kw) active_obj = subobj.activate(**activity_kw)
getattr(active_obj, alternate_method_id)(*m.args, **m.kw) getattr(active_obj, alternate_method_id)(*m.args, **m.kw)
else: else:
expanded_object_list.append(subobj) expanded_object_list.append(subobj)
else:
path = obj.getPath()
if path not in path_dict:
path_dict[path] = i
if alternate_method_id is not None \
and hasattr(aq_base(obj), alternate_method_id):
# if this object is alternated, generate a new single active object.
activity_kw = m.activity_kw.copy()
if 'group_method_id' in activity_kw:
del activity_kw['group_method_id']
if 'group_id' in activity_kw:
del activity_kw['group_id']
active_obj = obj.activate(**activity_kw)
getattr(active_obj, alternate_method_id)(*m.args, **m.kw)
else:
expanded_object_list.append(obj)
object_list.append(obj) object_list.append(obj)
new_message_list.append(m) new_message_list.append(m)
except: except:
...@@ -1238,8 +1228,9 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1238,8 +1228,9 @@ class ActivityTool (Folder, UniqueObject):
if len(expanded_object_list) > 0: if len(expanded_object_list) > 0:
method = self.unrestrictedTraverse(method_id) method = self.unrestrictedTraverse(method_id)
# FIXME: how to apply security here? # FIXME: how to apply security here?
# NOTE: expanded_object_list must be set to failed objects by the callee. # NOTE: expanded_object_list must be set to failed objects by the
# If it fully succeeds, expanded_object_list must be empty when returning. # callee. If it fully succeeds, expanded_object_list must be
# empty when returning.
result = method(expanded_object_list, **m.kw) result = method(expanded_object_list, **m.kw)
else: else:
result = None result = None
...@@ -1247,7 +1238,7 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1247,7 +1238,7 @@ class ActivityTool (Folder, UniqueObject):
# In this case, the group method completely failed. # In this case, the group method completely failed.
exc_info = sys.exc_info() exc_info = sys.exc_info()
for m in new_message_list: for m in new_message_list:
m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info=exc_info, log=False) m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info, log=False)
LOG('WARNING ActivityTool', 0, LOG('WARNING ActivityTool', 0,
'Could not call method %s on objects %s' % 'Could not call method %s on objects %s' %
(method_id, expanded_object_list), error=exc_info) (method_id, expanded_object_list), error=exc_info)
...@@ -1255,22 +1246,17 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1255,22 +1246,17 @@ class ActivityTool (Folder, UniqueObject):
if error_log is not None: if error_log is not None:
error_log.raising(exc_info) error_log.raising(exc_info)
else: else:
# Obtain all indices of failed messages. Note that this can be a partial failure. # Obtain all indices of failed messages.
failed_message_dict = {} # Note that this can be a partial failure.
for obj in expanded_object_list: failed_message_set = set(path_dict[obj.getPath()]
path = obj.getPath() for obj in expanded_object_list)
i = path_dict[path]
failed_message_dict[i] = None
# Only for succeeded messages, an activity process is invoked (if any). # Only for succeeded messages, an activity process is invoked (if any).
for i in xrange(len(object_list)): for i, m in enumerate(new_message_list):
object = object_list[i] if i in failed_message_set:
m = new_message_list[i]
if i in failed_message_dict:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
else: else:
try: try:
m.activateResult(self, result, object) m.activateResult(self, result, object_list[i])
except: except:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
else: else:
......
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