tools (common/template): changed blog_date filter to date_days

Instead of returning the whole sentence, date_days only return the number of days between now and the given timestamp.
This way the template author can choose how to use it, and translation can be done template side.
This commit is contained in:
Goffi 2017-06-24 21:47:06 +02:00
commit f3a94527b0

View file

@ -195,7 +195,7 @@ class Renderer(object):
# custom filters
self.env.filters['next_gidx'] = self._next_gidx
self.env.filters['cur_gidx'] = self._cur_gidx
self.env.filters['blog_date'] = self._blog_date
self.env.filters['date_days'] = self._date_days
def installTranslations(self):
i18n_dir = os.path.join(self.base_dir, 'i18n')
@ -319,9 +319,8 @@ class Renderer(object):
"""Use current current global index as suffix"""
return u"{}_{}".format(value, ctx['gidx'].current())
def _blog_date(self, timestamp):
# FIXME: Q&D, need to be done properly
return unicode(int(time.time() - int(timestamp))/(3600*24)) + u" days ago"
def _date_days(self, timestamp):
return int(time.time() - int(timestamp))/(3600*24)
def render(self, template, theme=None, locale=DEFAULT_LOCALE, root_path=u'', css_files=None, css_inline=False, **kwargs):
"""render a template