Merge lp:~openerp-dev/openobject-server/7.0-tz-order-change-csn into lp:openobject-server/7.0

Proposed by Olivier Dony (Odoo)
Status: Merged
Merged at revision: 4975
Proposed branch: lp:~openerp-dev/openobject-server/7.0-tz-order-change-csn
Merge into: lp:openobject-server/7.0
Diff against target: 12 lines (+2/-1)
1 file modified
openerp/addons/base/res/res_partner.py (+2/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-tz-order-change-csn
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Needs Fixing
Review via email: mp+163874@code.launchpad.net

Description of the change

Fix for bug 1086728: move "Etc/*" timezone entries at the end of the list to avoid confusing users. See the discussion on bug 1086728.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

@Cedric: Functionally it looks good to me, but technically I think the implementation should be shortened by using the Python API properly. Please use the functional programming aspects of Python as much as possible, it makes the code shorter, more readable, and is much less error-prone (more procedural code such as loops, assignations, etc. means more chances of introducing bugs!)

This patch could basically be a 2-liner, by using a simple sorting function that replaces "Etc/*" by "_" so it is sorted last alphabetically.

    # put POSIX 'Etc/*' entries at the end to avoid confusing users - see bug 1086728
    return [(tz,tz) for tz in sorted(pytz.all_timezones, key=lambda tz: tz if not tz.startswith('Etc/') else '_')]

For reference:
- Sorting Python lists: http://wiki.python.org/moin/HowTo/Sorting/#Key_Functions
- Python functional programming: http://docs.python.org/2/howto/functional.html

review: Needs Fixing
4974. By Cedric Snauwaert (OpenERP)

[REF]res_partner: compact code to get tz info

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/res/res_partner.py'
2--- openerp/addons/base/res/res_partner.py 2013-04-25 17:12:38 +0000
3+++ openerp/addons/base/res/res_partner.py 2013-05-15 10:12:27 +0000
4@@ -74,7 +74,8 @@
5
6
7 def _tz_get(self,cr,uid, context=None):
8- return [(x, x) for x in pytz.all_timezones]
9+ # put POSIX 'Etc/*' entries at the end to avoid confusing users - see bug 1086728
10+ return [(tz,tz) for tz in sorted(pytz.all_timezones, key=lambda tz: tz if not tz.startswith('Etc/') else '_')]
11
12 class res_partner_category(osv.osv):
13