Commit 000dba76 authored by Julien Muchembled's avatar Julien Muchembled

Clean up some code using ActiveProcess.getResultList

parent e26beb3a
...@@ -8,14 +8,11 @@ if active_process is None: ...@@ -8,14 +8,11 @@ if active_process is None:
else: else:
active_process = context.getPortalObject().restrictedTraverse(active_process) active_process = context.getPortalObject().restrictedTraverse(active_process)
result_list = [] if active_process is None:
constraint_message_list = [] return []
if active_process is not None:
result_list = [x for x in active_process.getResultList()]
# High severity will be displayed first
result_list.sort(key=lambda x: -x.severity)
for result in result_list: constraint_message_list = []
for result in active_process.ActiveProcess_getResultList():
constraint_message_list.extend(result.getProperty('constraint_message_list') or []) constraint_message_list.extend(result.getProperty('constraint_message_list') or [])
return constraint_message_list return constraint_message_list
if process is None: if process is None:
return False return False
result_list = process.getResultList() result_list = process.getResultList()
return result_list and bool(result_list[0].getProperty('severity')) or False return bool(result_list and result_list[0].getProperty('severity'))
...@@ -3,35 +3,19 @@ ...@@ -3,35 +3,19 @@
or of the last process if nothing specified. or of the last process if nothing specified.
""" """
def getLastActiveProcess(sub): if active_process is None:
""" # Get the last active process finished, not the current one.
This returns the last active process finished. So it will active_process = context.getPortalObject().portal_catalog.getResultValue(
not returns the current one portal_type='Active Process',
"""
limit = 1
active_process_list = context.getPortalObject().portal_catalog(
portal_type='Active Process', limit=limit,
sort_on=(('creation_date', 'DESC'), sort_on=(('creation_date', 'DESC'),
# XXX Work around poor resolution of MySQL dates. # XXX Work around poor resolution of MySQL dates.
('CONVERT(`catalog`.`id`, UNSIGNED)', 'DESC')), ('CONVERT(`catalog`.`id`, UNSIGNED)', 'DESC')),
causality_uid=sub.getUid()) causality_uid=sub.getUid())
if len(active_process_list) < limit:
process = None
else:
process = active_process_list[-1].getObject()
return process
if active_process is None:
active_process = getLastActiveProcess(context)
else: else:
active_process = context.getPortalObject().restrictedTraverse(active_process) active_process = context.getPortalObject().restrictedTraverse(active_process)
result_list = [] if active_process is None:
return []
if active_process is not None:
result_list = [x for x in active_process.getResultList()]
# High severity will be displayed first
result_list.sort(key=lambda x: -x.severity)
return result_list return active_process.ActiveProcess_getResultList()
...@@ -202,7 +202,6 @@ class TestUpgrader(ERP5TypeTestCase): ...@@ -202,7 +202,6 @@ class TestUpgrader(ERP5TypeTestCase):
group_dict = DETAIL_PATTERN.match(detail).groupdict() group_dict = DETAIL_PATTERN.match(detail).groupdict()
person = self.portal.restrictedTraverse(group_dict['relative_url']) person = self.portal.restrictedTraverse(group_dict['relative_url'])
message_list = [m.message for m in person.checkConsistency()] message_list = [m.message for m in person.checkConsistency()]
self.assertNotEqual(result_list, [])
self.assertEqual(len(result_list), 1) self.assertEqual(len(result_list), 1)
return person, group_dict, detail, message_list return person, group_dict, detail, message_list
......
...@@ -8,11 +8,7 @@ if active_process is None: ...@@ -8,11 +8,7 @@ if active_process is None:
else: else:
active_process = context.getPortalObject().restrictedTraverse(active_process) active_process = context.getPortalObject().restrictedTraverse(active_process)
result_list = [] if active_process is None:
return []
if active_process is not None:
result_list = [x for x in active_process.getResultList()]
# High severity will be displayed first
result_list.sort(key=lambda x: -x.severity)
return result_list return active_process.ActiveProcess_getResultList()
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