Mercurial > public > sg101
changeset 270:85f81377bb5b
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.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 26 Sep 2010 17:27:08 +0000 |
parents | 4e307f9ddd2d |
children | 4746df47a538 |
files | gpp/core/templatetags/core_tags.py gpp/templates/forums/new_posts_tag.html gpp/templates/shoutbox/shoutbox.html |
diffstat | 3 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 %} <div> <h2>Latest Forum Posts</h2> <p>Join us in our <a href="{% url forums-index %}">forums</a> for some lively discussions. Here are the list of forum topics with new posts.</p> {% if topics %} <ul> {% for topic in topics %} - <li><a href="{{ topic.last_post.get_absolute_url }}">{{ topic.name }}</a> by {{ topic.last_post.user.username }} on {% forum_date topic.update_date user 0 %}</li> + <li><a href="{{ topic.last_post.get_absolute_url }}">{{ topic.name }}</a> by {{ topic.last_post.user.username }} {{ topic.update_date|elapsed }}</li> {% endfor %} </ul> {% else %}
--- 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 %} <div id="shoutbox-shout-container"> {% for shout in shouts %} <p> <span class="shoutbox-user">{{ shout.user.username }}:</span> - <span class="shoutbox-shout">{{ shout.html|safe }}</span> - <span class="shoutbox-date">{{ shout.shout_date|date:"D M d Y H:i:s" }}</span> + <span class="shoutbox-shout">{{ shout.html|safe }}</span><br /> + <span class="shoutbox-date">{{ shout.shout_date|elapsed }}</span> </p> {% endfor %} </div>