aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2012-11-08 00:44:52 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2012-11-08 00:44:52 +0100
commit9ab593bcd52fcbe87f1be463ca5f09a757d1128f (patch)
tree6e792c98452715e5409af3afc4a23c206f362130
parent1ab9d17135c87253d9e1531cc31cf1b4ac94eceb (diff)
downloadfamille-flask-9ab593bcd52fcbe87f1be463ca5f09a757d1128f.tar.gz
Add date formatting filter
-rw-r--r--famille.py8
-rw-r--r--templates/news/list.html2
-rw-r--r--templates/news/show.html6
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 @@
<h2><a href="{{ url_for('show_news', news_id = news.id)}}">
{{ news.title }}</a>
</h2>
- <p>Posté par <a href="">{{ news.name }}</a> le {{ news.date }}</p>
+ <p>Posté par <a href="">{{ news.name }}</a> le {{news.date|format_date}}</p>
</div>
<div class="news_content">
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 @@
<h2>Détails</h2>
<ul>
<li>Auteur : <a href="">{{news.name}}</a></li>
-<li>Date : {{news.date}} </li>
+<li>Date : {{news.date|format_date}} </li>
<!--<li><a href="#comments">{{coments}}</a></li>-->
</div>
@@ -19,7 +19,9 @@
<hr/>
<h2 id="comments">Commentaires</h2>
{% for comment in comments %}
-<h3 class="comment">Posté par <a href="">{{comment.name}}</a> le {{comment.date}} </h3>
+<h3 class="comment">
+ Posté par <a href="">{{comment.name}}</a> le {{comment.date|format_date}}
+</h3>
<div class="comment_content"/>
{{comment.content|safe}}
</div>