This commit is contained in:
Daniel Tsvetkov 2020-04-25 19:47:06 +02:00
parent b7623e46dd
commit b678d45224

View File

@ -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'<br>'.join(u'%s' % p.replace('\n', '<br>\n') for p in _paragraph_re.split(text))
result = u'<p>'.join(u'%s' % p.replace('\n', '<br>\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