From 3a28f874c7a11c72f871173a1ad966d150f4412e Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Fri, 1 May 2015 15:26:19 -0400 Subject: [PATCH] use default format from language or server --- qweb_usertime/README.rst | 6 ++++++ qweb_usertime/qweb.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/qweb_usertime/README.rst b/qweb_usertime/README.rst index 2c53ea9f15e..3c766de8dc4 100644 --- a/qweb_usertime/README.rst +++ b/qweb_usertime/README.rst @@ -9,6 +9,12 @@ the current time in the timezone of the user. It can be used as:: +or, if you want to use the default date and time formats based on the users +language:: + + + + Credits ======= diff --git a/qweb_usertime/qweb.py b/qweb_usertime/qweb.py index d41cbc0c6f7..ba7d6a8dff0 100644 --- a/qweb_usertime/qweb.py +++ b/qweb_usertime/qweb.py @@ -27,6 +27,7 @@ import pytz from openerp import models +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT _logger = logging.getLogger(__name__) @@ -37,6 +38,17 @@ class QWeb(models.Model): def render_tag_usertime(self, element, template_attributes, generated_attributes, qwebcontext): tformat = template_attributes['usertime'] + if not tformat: + # No format, use default time and date formats from user lang + lang = qwebcontext['user'].lang + if lang: + lang = qwebcontext['env']['res.lang'].search( + [('code', '=', lang)] + ) + tformat = "{0.date_format} {0.time_format}".format(lang) + else: + tformat = DEFAULT_SERVER_DATETIME_FORMAT + now = datetime.now() tz_name = qwebcontext['user'].tz