[MERGE] babel: use babel for locale-aware read_group date formatting.
When grouping on a date or datetime field, read_group groups by (year, month), and formats that pair to have a displayable result (as a group title). This is currently done with strftime and the pattern `%B %Y` (complete word month, long year), which is problematic as — at best — it uses the server's locale for its formatting. This means if the server works in an english locale e.g. russian users are going to see the month name in english, instead of their own language. This proposal makes use of `babel.dates.format_date`, which is locale-aware (and to which a locale can be provided directly) and the locale present in the request context to format the month, year pair according to the user's language. bzr revid: vmt@openerp.com-20121012144634-spaqze7d4jc8l00l
This commit is contained in:
commit
7878f9c7b6
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import babel.dates
|
||||||
import calendar
|
import calendar
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
|
@ -2701,7 +2702,9 @@ class BaseModel(object):
|
||||||
dt = datetime.datetime.strptime(alldata[d['id']][groupby][:7], '%Y-%m')
|
dt = datetime.datetime.strptime(alldata[d['id']][groupby][:7], '%Y-%m')
|
||||||
days = calendar.monthrange(dt.year, dt.month)[1]
|
days = calendar.monthrange(dt.year, dt.month)[1]
|
||||||
|
|
||||||
d[groupby] = datetime.datetime.strptime(d[groupby][:10], '%Y-%m-%d').strftime('%B %Y')
|
date_value = datetime.datetime.strptime(d[groupby][:10], '%Y-%m-%d')
|
||||||
|
d[groupby] = babel.dates.format_date(
|
||||||
|
date_value, format='MMMM yyyy', locale=context.get('lang', 'en_US'))
|
||||||
d['__domain'] = [(groupby, '>=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-01', '%Y-%m-%d').strftime('%Y-%m-%d') or False),\
|
d['__domain'] = [(groupby, '>=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-01', '%Y-%m-%d').strftime('%Y-%m-%d') or False),\
|
||||||
(groupby, '<=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-' + str(days), '%Y-%m-%d').strftime('%Y-%m-%d') or False)] + domain
|
(groupby, '<=', alldata[d['id']][groupby] and datetime.datetime.strptime(alldata[d['id']][groupby][:7] + '-' + str(days), '%Y-%m-%d').strftime('%Y-%m-%d') or False)] + domain
|
||||||
del alldata[d['id']][groupby]
|
del alldata[d['id']][groupby]
|
||||||
|
|
Loading…
Reference in New Issue