From b678d4522420fb4a477e4a39e98e86089231c7f6 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Sat, 25 Apr 2020 19:47:06 +0200 Subject: [PATCH] timeago --- oshipka/persistance/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/oshipka/persistance/__init__.py b/oshipka/persistance/__init__.py index e6e57bd..5d43145 100644 --- a/oshipka/persistance/__init__.py +++ b/oshipka/persistance/__init__.py @@ -14,7 +14,7 @@ from flask_security import RoleMixin, UserMixin from config import SQLALCHEMY_DATABASE_URI, MAKEDIRS, DATABASE_FILE from sqlalchemy.orm.collections import InstrumentedList from sqlalchemy_utils import Choice -from tww.tww import solve_query, resolve_timezone, dt_tz_translation +from tww.tww import solve_query, resolve_timezone, dt_tz_translation, time_ago db = SQLAlchemy() @@ -168,7 +168,7 @@ def register_filters(app): @app.template_filter('nl2br') def nl2br(text): text = escape(text) - result = u'
'.join(u'%s' % p.replace('\n', '
\n') for p in _paragraph_re.split(text)) + result = u'

'.join(u'%s' % p.replace('\n', '
\n') for p in _paragraph_re.split(text)) return Markup(result) @app.template_filter('format_dt') @@ -195,6 +195,14 @@ def register_filters(app): return base return "{} ({})".format(base, tz.get('tz_offset')) + @app.template_filter('timeago') + def timeago(dt): + return time_ago(dt) + + @app.template_filter('timediff') + def timediff(diff): + return time_ago(None, diff) + def init_db(app): app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI