Browse Source

allow getting the language format from the user + only offset datetimes, not dates

pull/42/head
Vincent Vinet 10 years ago
parent
commit
27e444b5c2
  1. 20
      email_template_dateutil/email_template.py

20
email_template_dateutil/email_template.py

@ -35,16 +35,32 @@ from openerp.addons.email_template import email_template
@contextfilter
def format_date(context, dtstr, new_format, tz=None):
def format_date(context, dtstr, new_format=None, tz=None):
if not dtstr:
return dtstr
if not new_format:
if context.get("user") and context["user"].lang:
user = context["user"]
lang_obj = user.pool["res.lang"]
cr, uid = user._cr, user._uid
lang = lang_obj.search(cr, uid, [
('code', '=', user.lang)
])
if lang:
new_format = lang_obj.browse(cr, uid, lang[0]).date_format
new_format = new_format or DFMT
try:
date = datetime.strptime(dtstr, DTFMT)
except ValueError:
# Maybe this is a date, not datetime
date = datetime.strptime(dtstr, DFMT)
else:
# If this was a date, calculating timezones will give unexpected
# results. Any timezone with a negative offset will be the day
# before, since (midnight - anything) is the previous day
if tz:
tz_name = tz
elif context.get("user") and context["user"].tz:

Loading…
Cancel
Save