Author: sevein Date: Sun Oct 10 07:55:19 2010 New Revision: 29 Log: Show time difference.
Added: trunk/chk4upd/templatetags/pretty_date.py Modified: trunk/templates/report.html Added: trunk/chk4upd/templatetags/pretty_date.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/chk4upd/templatetags/pretty_date.py Sun Oct 10 07:55:19 2010 (r29) @@ -0,0 +1,38 @@ +from django import template +register = template.Library() + [email protected]('pretty_date') +def pretty_date(value): + + from datetime import datetime + + now = datetime.now() + diff = now - value + + second_diff = diff.seconds + day_diff = diff.days + + if day_diff < 0: + return '' + if day_diff == 0: + if second_diff < 10: + return "just now" + if second_diff < 60: + return str(second_diff) + " seconds ago" + if second_diff < 120: + return "a minute ago" + if second_diff < 3600: + return str( second_diff / 60 ) + " minutes ago" + if second_diff < 7200: + return "an hour ago" + if second_diff < 86400: + return str( second_diff / 3600 ) + " hours ago" + if day_diff == 1: + return "Yesterday" + if day_diff < 7: + return str(day_diff) + " days ago" + if day_diff < 31: + return str(day_diff/7) + " weeks ago" + if day_diff < 365: + return str(day_diff/30) + " months ago" + return str(day_diff/365) + " years ago" Modified: trunk/templates/report.html ============================================================================== --- trunk/templates/report.html Sun Oct 10 07:05:13 2010 (r28) +++ trunk/templates/report.html Sun Oct 10 07:55:19 2010 (r29) @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load truncate_chars %} +{% load pretty_date %} {% block title %}Report{% endblock %} {% block title_header %}Report{% endblock %} @@ -38,7 +39,7 @@ </tr> {% for item in objects.object_list %} <tr class="{% cycle 'odd' 'even' %}"> - <td class="date" title="{{ item.created_at|time:"H:i:s" }}">{{ item.created_at|date:"SHORT_DATE_FORMAT" }}</td> + <td class="date" title="{{ item.created_at|pretty_date }} ({{ item.created_at|time:"H:i:s" }})">{{ item.created_at|date:"SHORT_DATE_FORMAT" }}</td> <td><span title="{{ item.site_title }}">{{ item.site_title|truncate_chars:20 }}</span></td> <td><span title="{{ item.site_description }}">{{ item.site_description|truncate_chars:20 }}</span></td> <td>{{ item.version }} (» {{ item.version_offered }})</td> -- You received this message because you are subscribed to the Google Groups "Qubit Toolkit Commits" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/qubit-commits?hl=en.
