diff options
| -rw-r--r-- | README.md | 11 | ||||
| -rw-r--r-- | famille.py | 14 | ||||
| -rw-r--r-- | static/famille.js | 1 | ||||
| -rw-r--r-- | templates/layout.html | 5 | ||||
| -rw-r--r-- | templates/news/list.html | 4 |
5 files changed, 26 insertions, 9 deletions
@@ -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 @@ -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 %} |
