aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--famille.py14
-rw-r--r--static/famille.js1
-rw-r--r--templates/layout.html5
-rw-r--r--templates/news/list.html4
5 files changed, 26 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0ad8c57..bb4ba3a 100644
--- a/README.md
+++ b/README.md
@@ -3,11 +3,10 @@ Réécriture du site de la famille en Flask.
TODO
----
+* Gérer les fichiers pour pouvoir insérer des images
+
+Done
+----
+* display dates using timeago.js
* Email notifications
* Tirer les noms pour le Cadoscope
-* Gérer les fichiers pour pouvoir insérer des images (je ne sais pas si ca marche avec rst)
-
-Ideas
------
-
-* use timeago.js
diff --git a/famille.py b/famille.py
index 1f0cb10..c1fa510 100644
--- a/famille.py
+++ b/famille.py
@@ -38,7 +38,19 @@ def format_date(date_object, format=u"%a %d %b %Y à %Hh%M"):
if not date_object:
return ""
format = format.encode("utf8")
- return date_object.replace(tzinfo=timezone('utc')).astimezone(timezone(session['timezone'])).strftime(format).decode("utf8")
+ return date_object.replace(tzinfo=timezone('utc')). \
+ astimezone(timezone(session['timezone'])).strftime(format).decode("utf8")
+
+@app.template_filter('format_ago')
+def format_ago(date_object, format):
+ if not date_object:
+ return ""
+ format = format.encode("utf8")
+ readable = date_object.replace(tzinfo=timezone('utc')). \
+ astimezone(timezone(session['timezone'])).strftime(format)
+ iso_format = date_object.strftime('%Y-%m-%dT%H:%M:%SZ')
+ return '<span class=timeago title="{0}">{1}</span>'. \
+ format(iso_format, readable).decode("utf8")
@app.template_filter('pluralize')
def pluralize(word, count, plural=None):
diff --git a/static/famille.js b/static/famille.js
index 2739020..63fc3d5 100644
--- a/static/famille.js
+++ b/static/famille.js
@@ -21,4 +21,5 @@ $(document).ready(function(){
$("#kadobutton").click(function(){
$(".kadoscope").animate({opacity:"1"},"5000");
});
+ $('span.timeago').timeago();
}); \ No newline at end of file
diff --git a/templates/layout.html b/templates/layout.html
index 709daef..1aa6173 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -36,5 +36,10 @@
src="{{ url_for('static', filename='jquery.js')}}"></script>
<script type="text/javascript"
src="{{ url_for('static', filename='famille.js')}}"></script>
+ <script type="text/javascript"
+ src="{{ url_for('static', filename='jquery.timeago.js')}}"></script>
+ <script type="text/javascript"
+ src="{{ url_for('static', filename='jquery.timeago.fr.js')}}">
+ </script>
</body>
</html>
diff --git a/templates/news/list.html b/templates/news/list.html
index c0d7e0a..d25715b 100644
--- a/templates/news/list.html
+++ b/templates/news/list.html
@@ -11,7 +11,7 @@
{% for user in users %}
<tr>
<td><a href="{{url_for('view_user', user_id=user.id)}}">{{user.user_name}}</a></td>
- <td>{{user.last_seen|format_date('%a %d %b à %Hh%M')}}</td>
+ <td>{{user.last_seen|format_ago('%a %d %b à %Hh%M')|safe}}</td>
</tr>
{% endfor %}
</table>
@@ -20,7 +20,7 @@
<ul id="last-comments">
{% for comment in comments %}
<li><a href="{{url_for('view_user', user_id=comment.user_id)}}">{{comment.user_name}}</a>
- {{comment.date|format_date('%a %d %b à %Hh%M')}}<br/>
+ {{comment.date|format_ago('%a %d %b à %Hh%M')|safe}}<br/>
{{comment.content_cache|shortify|safe}} <a href="{{url_for('show_news', news_id=comment.news_id)}}#comments">[…]</a>
</li>
{% else %}