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
=== modified file 'base_calendar/base_calendar.py'
--- base_calendar/base_calendar.py 2012-03-05 14:35:54 +0000
+++ base_calendar/base_calendar.py 2013-12-04 22:13:31 +0000
@@ -30,6 +30,7 @@
30import re30import re
31import time31import time
32import tools32import tools
33from operator import itemgetter
3334
34months = {35months = {
35 1: "January", 2: "February", 3: "March", 4: "April", \36 1: "January", 2: "February", 3: "March", 4: "April", \
@@ -1303,6 +1304,18 @@
1303 res.append(base_calendar_id2real_id(id))1304 res.append(base_calendar_id2real_id(id))
1304 return res1305 return res
13051306
1307 def _multikeysort(self, items, columns):
1308
1309 comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
1310 def comparer(left, right):
1311 for fn, mult in comparers:
1312 result = cmp(fn(left), fn(right))
1313 if result:
1314 return mult * result
1315 else:
1316 return 0
1317 return sorted(items, cmp=comparer)
1318
1306 def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):1319 def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
1307 context = context or {}1320 context = context or {}
1308 args_without_date = []1321 args_without_date = []
@@ -1327,6 +1340,16 @@
1327 0, 0, order, context, count=False)1340 0, 0, order, context, count=False)
1328 if context.get('virtual_id', True):1341 if context.get('virtual_id', True):
1329 res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context)1342 res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context)
1343 if order:
1344 order = order.split(',')
1345 sortby = {}
1346 for o in order:
1347 spl = o.split()
1348 sortby[spl[0]] = spl[1]
1349 fields = sortby.keys()
1350 ordered = self.read(cr, uid, res, fields=fields, context=context)
1351 res = self._multikeysort(ordered, [key.split()[0] if sortby[key.split()[0]] == 'ASC' else '-%s' % key.split()[0] for key in order])
1352 res = [x['id'] for x in res]
13301353
1331 if count:1354 if count:
1332 return len(res)1355 return len(res)

Subscribers

People subscribed via source and target branches