Skip to content

Commit

Permalink
use default format from language or server
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Vinet committed May 1, 2015
1 parent df9e30a commit 3a28f87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qweb_usertime/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ the current time in the timezone of the user. It can be used as::

<t t-usertime="%Y-%m-%d %H:%M:%S" />

or, if you want to use the default date and time formats based on the users
language::

<t t-usertime="" />


Credits
=======

Expand Down
12 changes: 12 additions & 0 deletions qweb_usertime/qweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pytz

from openerp import models
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT

_logger = logging.getLogger(__name__)

Expand All @@ -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
Expand Down

0 comments on commit 3a28f87

Please sign in to comment.