# HG changeset patch # User Goffi # Date 1498333626 -7200 # Node ID 084a75b8aa7a9b00ff8a00b7f897ca5cffa2113a # Parent 3226945432255d00ba170664ca0aa117d53a8423 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. diff -r 322694543225 -r 084a75b8aa7a src/tools/common/template.py --- a/src/tools/common/template.py Sat Jun 24 20:18:55 2017 +0200 +++ b/src/tools/common/template.py Sat Jun 24 21:47:06 2017 +0200 @@ -195,7 +195,7 @@ # 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 @@ """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