Mercurial > libervia-backend
changeset 2266:084a75b8aa7a
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Jun 2017 21:47:06 +0200 |
parents | 322694543225 |
children | ed28798fd76c |
files | src/tools/common/template.py |
diffstat | 1 files changed, 3 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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