comparison src/tools/common/template.py @ 2453:84e84a46b014

template (filters): don't crash on invalid date in date_fmt
author Goffi <goffi@goffi.org>
date Thu, 30 Nov 2017 20:59:24 +0100
parents 7aa863cbc47f
children 06ff33052354
comparison
equal deleted inserted replaced
2452:7aa863cbc47f 2453:84e84a46b014
351 """Use current current global index as suffix""" 351 """Use current current global index as suffix"""
352 current = ctx['gidx'].current(value) 352 current = ctx['gidx'].current(value)
353 return value if not current else u"{}_{}".format(value, current) 353 return value if not current else u"{}_{}".format(value, current)
354 354
355 def _date_fmt(self, timestamp, fmt='short', date_only=False, auto_limit=None, auto_old_fmt=None): 355 def _date_fmt(self, timestamp, fmt='short', date_only=False, auto_limit=None, auto_old_fmt=None):
356 try:
357 return self.date_fmt(timestamp, fmt, date_only, auto_limit, auto_old_fmt)
358 except Exception as e:
359 log.warning(_(u"Can't parse date: {msg}").format(msg=e))
360 return timestamp
361
362 def date_fmt(self, timestamp, fmt='short', date_only=False, auto_limit=None, auto_old_fmt=None):
356 """format date according to locale 363 """format date according to locale
357 364
358 @param timestamp(basestring, int): unix time 365 @param timestamp(basestring, int): unix time
359 @param fmt(str): one of: 366 @param fmt(str): one of:
360 - short: e.g. u'31/12/17' 367 - short: e.g. u'31/12/17'