From a650e6f9895800fdad59beefca7f85793d0c2a4c Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 28 Sep 2017 22:28:20 -0700 Subject: [PATCH] Chapter 12: Dates and Times (v0.12) --- app/__init__.py | 2 ++ app/templates/_post.html | 2 +- app/templates/base.html | 5 +++++ app/templates/user.html | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index f814d28..3ed606d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,6 +7,7 @@ from flask_migrate import Migrate from flask_login import LoginManager from flask_mail import Mail from flask_bootstrap import Bootstrap +from flask_moment import Moment from config import Config app = Flask(__name__) @@ -17,6 +18,7 @@ login = LoginManager(app) login.login_view = 'login' mail = Mail(app) bootstrap = Bootstrap(app) +moment = Moment(app) if not app.debug: if app.config['MAIL_SERVER']: diff --git a/app/templates/_post.html b/app/templates/_post.html index 29caf6f..b5b6022 100644 --- a/app/templates/_post.html +++ b/app/templates/_post.html @@ -9,7 +9,7 @@ {{ post.author.username }} - says: + said {{ moment(post.timestamp).fromNow() }}:
{{ post.body }} diff --git a/app/templates/base.html b/app/templates/base.html index 053e93b..afb8e94 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -48,3 +48,8 @@ {% block app_content %}{% endblock %} {% endblock %} + +{% block scripts %} + {{ super() }} + {{ moment.include_moment() }} +{% endblock %} diff --git a/app/templates/user.html b/app/templates/user.html index b039db2..76dfd60 100644 --- a/app/templates/user.html +++ b/app/templates/user.html @@ -7,7 +7,9 @@

User: {{ user.username }}

{% if user.about_me %}

{{ user.about_me }}

{% endif %} - {% if user.last_seen %}

Last seen on: {{ user.last_seen }}

{% endif %} + {% if user.last_seen %} +

Last seen on: {{ moment(user.last_seen).format('LLL') }}

+ {% endif %}

{{ user.followers.count() }} followers, {{ user.followed.count() }} following.

{% if user == current_user %}

Edit your profile