Merge lp:~hirt/ocb-addons/6.1-sort-events-mat into lp:ocb-addons/6.1

Proposed by Etienne Hirt
Status: Merged
Merged at revision: 6828
Proposed branch: lp:~hirt/ocb-addons/6.1-sort-events-mat
Merge into: lp:ocb-addons/6.1
Diff against target: 47 lines (+23/-0)
1 file modified
base_calendar/base_calendar.py (+23/-0)
To merge this branch: bzr merge lp:~hirt/ocb-addons/6.1-sort-events-mat
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Review via email: mp+196434@code.launchpad.net

Description of the change

[FIX] correct order-by for crm_meetings with patch that is targeted for lp:openobject-addons/7.0
Consider merging also in ocb-addons

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

You might want to remove the trailing white space introduced on: l.17,26,53,54

Revision history for this message
Etienne Hirt (hirt) wrote :

> You might want to remove the trailing white space introduced on: l.17,26,53,54
Thanks for finding. Hope I removed them all. Please check again. Thanks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_calendar/base_calendar.py'
2--- base_calendar/base_calendar.py 2012-03-05 14:35:54 +0000
3+++ base_calendar/base_calendar.py 2013-12-04 22:13:31 +0000
4@@ -30,6 +30,7 @@
5 import re
6 import time
7 import tools
8+from operator import itemgetter
9
10 months = {
11 1: "January", 2: "February", 3: "March", 4: "April", \
12@@ -1303,6 +1304,18 @@
13 res.append(base_calendar_id2real_id(id))
14 return res
15
16+ def _multikeysort(self, items, columns):
17+
18+ comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
19+ def comparer(left, right):
20+ for fn, mult in comparers:
21+ result = cmp(fn(left), fn(right))
22+ if result:
23+ return mult * result
24+ else:
25+ return 0
26+ return sorted(items, cmp=comparer)
27+
28 def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
29 context = context or {}
30 args_without_date = []
31@@ -1327,6 +1340,16 @@
32 0, 0, order, context, count=False)
33 if context.get('virtual_id', True):
34 res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context)
35+ if order:
36+ order = order.split(',')
37+ sortby = {}
38+ for o in order:
39+ spl = o.split()
40+ sortby[spl[0]] = spl[1]
41+ fields = sortby.keys()
42+ ordered = self.read(cr, uid, res, fields=fields, context=context)
43+ res = self._multikeysort(ordered, [key.split()[0] if sortby[key.split()[0]] == 'ASC' else '-%s' % key.split()[0] for key in order])
44+ res = [x['id'] for x in res]
45
46 if count:
47 return len(res)

Subscribers

People subscribed via source and target branches