Skip to content

Commit

Permalink
feat(app/views): Human readible date on entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jakuboskera committed Oct 14, 2021
1 parent 9504e30 commit 618e654
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,3 @@ $ make skaffold-dev
```console
$ make skaffold-cleanup
```

2 changes: 1 addition & 1 deletion app/templates/pages/entries/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if entries | length > 0 %}
{% for entry in entries %}
<div class="card shadow-sm rounded mb-4" tabindex="0">
<div class="card-header">{{ entry.created }} </div>
<div class="card-header">{{ entry.created | strftime }} </div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>{{ entry.comment }}</p>
Expand Down
9 changes: 9 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import health
from api import EntryList
from dateutil import parser
from flask import jsonify
from flask import redirect
from flask import render_template
Expand Down Expand Up @@ -70,3 +71,11 @@ def page_not_found(e):
Requested non-existing page.
"""
return render_template("pages/404.html"), 404


@app.template_filter("strftime")
def _jinja2_filter_datetime(date, fmt=None):
date = parser.parse(date)
native = date.replace(tzinfo=None)
format = "%b %d, %Y"
return native.strftime(format)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Flask_Migrate==2.6.0
psycopg2_binary==2.8.6
py-healthcheck==1.10.1
gunicorn==20.1.0
python-dateutil==2.8.1

0 comments on commit 618e654

Please sign in to comment.