diff --git a/app/__init__.py b/app/__init__.py index 217210a..57bb3d2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -5,6 +5,7 @@ from flask.ext.login import LoginManager from flask.ext.openid import OpenID from flask.ext.mail import Mail from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD +from momentjs import momentjs app = Flask(__name__) app.config.from_object('config') @@ -35,5 +36,7 @@ if not app.debug: app.logger.setLevel(logging.INFO) app.logger.info('microblog startup') +app.jinja_env.globals['momentjs'] = momentjs + from app import views, models diff --git a/app/momentjs.py b/app/momentjs.py new file mode 100644 index 0000000..5d2db81 --- /dev/null +++ b/app/momentjs.py @@ -0,0 +1,18 @@ +from jinja2 import Markup + +class momentjs: + def __init__(self, timestamp): + self.timestamp = timestamp + + def render(self, format): + return Markup("" % (self.timestamp.strftime("%Y-%m-%dT%H:%M:%S Z"), format)) + + def format(self, fmt): + return self.render("format(\"%s\")" % fmt) + + def calendar(self): + return self.render("calendar()") + + def fromNow(self): + return self.render("fromNow()") + diff --git a/app/templates/post.html b/app/templates/post.html index 9543fda..0207904 100644 --- a/app/templates/post.html +++ b/app/templates/post.html @@ -2,10 +2,7 @@
{{post.author.nickname}} said - :
+{{post.author.nickname}} said {{momentjs(post.timestamp).fromNow()}}:
{{post.body}}
{{user.about_me}}
{% endif %} {% if user.last_seen %} -Last seen: - -
+Last seen: {{momentjs(user.last_seen).calendar()}}
{% endif %}Followers: {{user.followers.count() - 1}} | Following: {{user.followed.count() - 1}} | {% if user.id == g.user.id %}