From f3a94527b0fb5716b2fbf4ed62a1985c05266744 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 24 Jun 2017 21:47:06 +0200 Subject: [PATCH] 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. --- src/tools/common/template.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tools/common/template.py b/src/tools/common/template.py index b3aec1e5..8d02a182 100644 --- a/src/tools/common/template.py +++ b/src/tools/common/template.py @@ -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