Commit 4e179f7a authored by Jérome Perrin's avatar Jérome Perrin

*: use key instead of cmp to sort

parent 562249eb
...@@ -68,10 +68,7 @@ for person in person_value_list: ...@@ -68,10 +68,7 @@ for person in person_value_list:
total=person_total, total=person_total,
**result_dict)) **result_dict))
result_list.sort(lambda a,b: cmp( result_list.sort(key=lambda r: (r.person_career_reference or '', r.person_title or ''))
a.person_career_reference or a.person_title,
b.person_career_reference or b.person_title))
request.set('total_time', total_time) request.set('total_time', total_time)
request.set('total_time_per_resource', total_time_per_resource) request.set('total_time_per_resource', total_time_per_resource)
......
...@@ -553,12 +553,12 @@ class BusinessConfiguration(Item): ...@@ -553,12 +553,12 @@ class BusinessConfiguration(Item):
"immediateReindexObject"]) "immediateReindexObject"])
# build # build
configuration_save_list = self.contentValues(portal_type='Configuration Save') configuration_save_list = self.contentValues(portal_type='Configuration Save')
configuration_save_list.sort(lambda x, y: cmp(x.getIntIndex(x.getIntId()), configuration_save_list.sort(key=lambda x: (x.getIntIndex(x.getIntId()) or 0))
y.getIntIndex(y.getIntId())))
for configuration_save in configuration_save_list: for configuration_save in configuration_save_list:
# XXX: check which items are configure-able # XXX: check which items are configure-able
configuration_item_list = configuration_save.contentValues() configuration_item_list = configuration_save.contentValues()
configuration_item_list.sort(lambda x, y: cmp(x.getIntId(), y.getIntId())) configuration_item_list.sort(key=lambda x: (x.getIntId() or 0))
for configurator_item in configuration_item_list: for configurator_item in configuration_item_list:
configurator_item.activate(**kw).fixConsistency( configurator_item.activate(**kw).fixConsistency(
filter={"constraint_type":"configuration"}) filter={"constraint_type":"configuration"})
......
...@@ -58,13 +58,7 @@ for inventory in portal.portal_simulation.getInventoryList( ...@@ -58,13 +58,7 @@ for inventory in portal.portal_simulation.getInventoryList(
request.set('total_price', total_price) request.set('total_price', total_price)
def sort_method(a, b): return sorted(
employee_career_reference_diff = cmp(a.employee_career_reference, object_list,
b.employee_career_reference) key=lambda o: (o.employee_career_reference or '', o.employee_title)
if employee_career_reference_diff: )
return employee_career_reference_diff
return cmp(a.employee_title, b.employee_title)
object_list.sort(sort_method)
return object_list
...@@ -38,10 +38,10 @@ inventory_param_dict = { ...@@ -38,10 +38,10 @@ inventory_param_dict = {
} }
employee_param_dict = inventory_param_dict.copy() employee_param_dict = inventory_param_dict.copy()
employee_param_dict['contribution_share_uid'] = context.portal_categories.contribution_share.employee.getUid() employee_param_dict['contribution_share_uid'] = portal.portal_categories.contribution_share.employee.getUid()
employer_param_dict = inventory_param_dict.copy() employer_param_dict = inventory_param_dict.copy()
employer_param_dict['contribution_share_uid'] = context.portal_categories.contribution_share.employer.getUid() employer_param_dict['contribution_share_uid'] = portal.portal_categories.contribution_share.employer.getUid()
if request.get('mirror_section'): if request.get('mirror_section'):
mirror_section = request['mirror_section'] mirror_section = request['mirror_section']
...@@ -116,17 +116,12 @@ sorted_inventory_list = [] ...@@ -116,17 +116,12 @@ sorted_inventory_list = []
sorted_inventory_list = inventory_list.values() sorted_inventory_list = inventory_list.values()
# sort by salary range, and add intermediate sums if needed # sort by salary range, and add intermediate sums if needed
def sort_method(a, b): sorted_inventory_list.sort(
salary_range_diff = cmp(a.salary_range, b.salary_range) key=lambda i: (
if salary_range_diff: i.salary_range or '',
return salary_range_diff i.employee_career_reference or '',
employee_career_reference_diff = cmp(a.employee_career_reference, i.employee_title or '',
b.employee_career_reference) ))
if employee_career_reference_diff:
return employee_career_reference_diff
return cmp(a.employee_title, b.employee_title)
sorted_inventory_list.sort(sort_method)
i = 0 i = 0
intermediate_base_total = 0 intermediate_base_total = 0
......
...@@ -120,38 +120,12 @@ for paysheet_line in paysheet_line_list: ...@@ -120,38 +120,12 @@ for paysheet_line in paysheet_line_list:
if 'no_slice' in object_dict: if 'no_slice' in object_dict:
line_list.append(paysheet_line.asContext(**object_dict['no_slice'])) line_list.append(paysheet_line.asContext(**object_dict['no_slice']))
reverse = False
sort_key = lambda l: (l.getIntIndex() or 0)
# sort results
def sortByTitleAscending(x, y):
return cmp(x.getTitle(), y.getTitle())
def sortByTitleDescending(x, y):
return cmp(y.getTitle(), x.getTitle())
def sortByIntIndexAscending(x, y):
return cmp(x.getIntIndex(), y.getIntIndex())
def sortByIntIndexDescending(x, y):
return cmp(y.getIntIndex(), x.getIntIndex())
sortByDefaultSortMethod = sortByIntIndexAscending
if 'sort_on' in kw: if 'sort_on' in kw:
sort_on = kw['sort_on'] sort_on = kw['sort_on']
if sort_on[0][0] == 'title' and sort_on[0][1]=='ascending': reverse = sort_on[0][1]=='descending'
line_list.sort(sortByTitleAscending) if sort_on[0][0] == 'title':
elif sort_on[0][0] == 'title' and sort_on[0][1]=='descending': sort_key = lambda l: (l.getTitle() or '')
line_list.sort(sortByTitleDescending)
elif sort_on[0][0] == 'int_index' and sort_on[0][1]=='ascending':
line_list.sort(sortByIntIndexAscending)
elif sort_on[0][0] == 'int_index' and sort_on[0][1]=='descending':
line_list.sort(sortByIntIndexDescending)
else:
line_list.sort(sortByDefaultSortMethod)
else:
line_list.sort(sortByDefaultSortMethod)
return line_list return sorted(line_list, key=sort_key, reverse=reverse)
...@@ -57,8 +57,6 @@ if active_process_path: ...@@ -57,8 +57,6 @@ if active_process_path:
else: else:
raise ValueError("No active process found to process report") raise ValueError("No active process found to process report")
def sortProduct(a, b):
return cmp(a['product'], b['product'])
period_counter_dict = {} period_counter_dict = {}
line_list = [] line_list = []
...@@ -132,7 +130,7 @@ if len(client_dict): ...@@ -132,7 +130,7 @@ if len(client_dict):
product_lines_list.append(obj) product_lines_list.append(obj)
# sort product list # sort product list
product_lines_list.sort(sortProduct) product_lines_list.sort(key=lambda p: p['product'])
extend(product_lines_list) extend(product_lines_list)
else: else:
# products # products
...@@ -169,7 +167,8 @@ else: ...@@ -169,7 +167,8 @@ else:
period_counter_dict['total amount'] = line_total_amount period_counter_dict['total amount'] = line_total_amount
append(obj) append(obj)
line_list.sort(sortProduct) line_list.sort(key=lambda p: p['product'])
obj = Object(uid="new_") obj = Object(uid="new_")
obj["client"] = 'Total' obj["client"] = 'Total'
......
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