From a871e7b5ddb4a9f812d4ea82af996310efdbc3b7 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg <miguel.grinberg@gmail.com> 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 | 1 + app/templates/user.html | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 95f8c6c..c52bcaa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,6 +6,7 @@ from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager from flask_mail import Mail +from flask_moment import Moment from config import Config app = Flask(__name__) @@ -15,6 +16,7 @@ migrate = Migrate(app, db) login = LoginManager(app) login.login_view = 'login' mail = Mail(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 @@ <a href="{{ url_for('user', username=post.author.username) }}"> {{ post.author.username }} </a> - says: + said {{ moment(post.timestamp).fromNow() }}: <br> {{ post.body }} </td> diff --git a/app/templates/base.html b/app/templates/base.html index 303ae76..ea22642 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -54,5 +54,6 @@ {% block content %}{% endblock %} </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script> + {{ moment.include_moment() }} </body> </html> diff --git a/app/templates/user.html b/app/templates/user.html index a48e7c3..c28617e 100644 --- a/app/templates/user.html +++ b/app/templates/user.html @@ -7,7 +7,9 @@ <td> <h1>User: {{ user.username }}</h1> {% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %} - {% if user.last_seen %}<p>Last seen on: {{ user.last_seen }}</p>{% endif %} + {% if user.last_seen %} + <p>Last seen on: {{ moment(user.last_seen).format('LLL') }}</p> + {% endif %} <p>{{ user.followers.count() }} followers, {{ user.following.count() }} following.</p> {% if user == current_user %} <p><a href="{{ url_for('edit_profile') }}">Edit your profile</a></p>