-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
22 lines (16 loc) · 823 Bytes
/
utils.py
File metadata and controls
22 lines (16 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from datetime import datetime
import pooler
class Localizer(object):
def __init__(self, cursor, uid, lang):
pool = pooler.get_pool(cursor.dbname)
lang_o = pool.get('res.lang')
lang_id = lang_o.search(cursor, uid, [('code', '=', lang)])[0]
self.lang = lang_o.simple_browse(cursor, uid, lang_id)
def amount(self, amount, digits=2, monetary=True):
return self.lang.format('%.{}f'.format(digits), amount, monetary=monetary)
def date(self, date_str):
new_format = self.lang.date_format
return datetime.strptime(date_str, "%Y-%m-%d").strftime(new_format)
def datetime(self, datetime_str):
new_format = "{} {}".format(self.lang.date_format, self.lang.time_format)
return datetime.strptime(datetime_str, "%Y-%m-%d").strftime(new_format)