From 9ab593bcd52fcbe87f1be463ca5f09a757d1128f Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Thu, 8 Nov 2012 00:44:52 +0100 Subject: Add date formatting filter --- famille.py | 8 ++++++++ templates/news/list.html | 2 +- templates/news/show.html | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/famille.py b/famille.py index 87a1118..e0fc798 100644 --- a/famille.py +++ b/famille.py @@ -7,6 +7,7 @@ from functools import wraps import hashlib from docutils import core from docutils.writers.html4css1 import Writer +from datetime import datetime def rstify(string): w = Writer() @@ -17,6 +18,13 @@ def rstify(string): app = Flask(__name__) app.config.from_envvar('CONF') +@app.template_filter('format_date') +def format_date(datetime_string, format="%a %d %b %Y"): + if not datetime_string: + return "" + return datetime.strptime(datetime_string[:-1], + "%Y-%m-%dT%H:%M:%S").strftime(format) + def query_db(query, args=(), one=False): cur = g.db.execute(query, args) rv = cur.fetchone() if one else cur.fetchall() diff --git a/templates/news/list.html b/templates/news/list.html index ecb0714..ddbe1ab 100644 --- a/templates/news/list.html +++ b/templates/news/list.html @@ -7,7 +7,7 @@

{{ news.title }}

-

Posté par {{ news.name }} le {{ news.date }}

+

Posté par {{ news.name }} le {{news.date|format_date}}

diff --git a/templates/news/show.html b/templates/news/show.html index 35c510f..411cdfc 100644 --- a/templates/news/show.html +++ b/templates/news/show.html @@ -5,7 +5,7 @@

Détails

@@ -19,7 +19,9 @@

Commentaires

{% for comment in comments %} -

Posté par {{comment.name}} le {{comment.date}}

+

+ Posté par {{comment.name}} le {{comment.date|format_date}} +

{{comment.content|safe}}
-- cgit v1.2.3-70-g09d2