# HG changeset patch # User Brian Neal # Date 1285522028 0 # Node ID 85f81377bb5bc585f058ef7e156f375dd4ab3fbd # Parent 4e307f9ddd2d98e8f7f8d083c4c6826ff13fc70a Fix #126. Incorporate the repoze timeago function as a new 'elapsed' template filter. This should save space in the shoutbox when displaying dates. Also used in the new posts forum template tag. diff -r 4e307f9ddd2d -r 85f81377bb5b gpp/core/templatetags/core_tags.py --- a/gpp/core/templatetags/core_tags.py Sun Sep 26 04:32:17 2010 +0000 +++ b/gpp/core/templatetags/core_tags.py Sun Sep 26 17:27:08 2010 +0000 @@ -7,6 +7,8 @@ from django.conf import settings from django.core.cache import cache +import repoze.timeago + from core.models import UserLastVisit, AnonLastVisit @@ -54,3 +56,21 @@ cache.set('whos_online', info, 300) return info + + +@register.filter(name='elapsed') +def elapsed(timestamp): + """ + This filter accepts a datetime and computes an elapsed time from "now". + The elapsed time is displayed as a "humanized" string. + Examples: + 1 minute ago + 5 minutes ago + 1 hour ago + 10 hours ago + 1 day ago + 7 days ago + + """ + return repoze.timeago.get_elapsed(timestamp) +elapsed.is_safe = True diff -r 4e307f9ddd2d -r 85f81377bb5b gpp/templates/forums/new_posts_tag.html --- a/gpp/templates/forums/new_posts_tag.html Sun Sep 26 04:32:17 2010 +0000 +++ b/gpp/templates/forums/new_posts_tag.html Sun Sep 26 17:27:08 2010 +0000 @@ -1,11 +1,11 @@ -{% load forum_tags %} +{% load core_tags %}

Latest Forum Posts

Join us in our forums for some lively discussions. Here are the list of forum topics with new posts.

{% if topics %} {% else %} diff -r 4e307f9ddd2d -r 85f81377bb5b gpp/templates/shoutbox/shoutbox.html --- a/gpp/templates/shoutbox/shoutbox.html Sun Sep 26 04:32:17 2010 +0000 +++ b/gpp/templates/shoutbox/shoutbox.html Sun Sep 26 17:27:08 2010 +0000 @@ -1,12 +1,13 @@ {% extends 'side_block.html' %} +{% load core_tags %} {% block block_title %}Shoutbox{% endblock %} {% block block_content %}
{% for shout in shouts %}

{{ shout.user.username }}: - {{ shout.html|safe }} - {{ shout.shout_date|date:"D M d Y H:i:s" }} + {{ shout.html|safe }}
+ {{ shout.shout_date|elapsed }}

{% endfor %}