# HG changeset patch # User Brian Neal # Date 1261341739 0 # Node ID 416353def4ca2d0030d362c28a39e339d153f708 # Parent ca7d619ee27b700b620b245e23e3029bc175663d Added a new posts template tag for the home page. diff -r ca7d619ee27b -r 416353def4ca gpp/forums/templatetags/forum_tags.py --- a/gpp/forums/templatetags/forum_tags.py Sun Dec 20 05:51:22 2009 +0000 +++ b/gpp/forums/templatetags/forum_tags.py Sun Dec 20 20:42:19 2009 +0000 @@ -7,15 +7,25 @@ from django import template from django.conf import settings +from forums.models import Topic + + register = template.Library() - TIME_FMT_24 = "%H:%M" TIME_FMT_12 = "%I:%M %p" DATE_FMT = "%b %d %Y" -DATE_FMT_24 = "%s %s" % (DATE_FMT, TIME_FMT_24) -DATE_FMT_12 = "%s %s" % (DATE_FMT, TIME_FMT_12) +SHORT_DATE_FMT = "%b %d" + +DATE_FMT_24 = ( + "%s %s" % (DATE_FMT, TIME_FMT_24), # long format + "%s %s" % (TIME_FMT_24, SHORT_DATE_FMT), # short format +) +DATE_FMT_12 = ( + "%s %s" % (DATE_FMT, TIME_FMT_12), # long format + "%s %s" % (TIME_FMT_12, SHORT_DATE_FMT), # short format +) SERVER_TZ = timezone(settings.TIME_ZONE) @@ -65,11 +75,13 @@ @register.simple_tag -def forum_date(date, user): +def forum_date(date, user, long_format=True): """ This tag displays an arbitrary datetime, adjusted by the user's time zone preferences. """ + fmt_index = 0 if long_format else 1 + date = SERVER_TZ.localize(date) if user.is_authenticated(): profile = user.get_profile() @@ -79,7 +91,7 @@ else: fmt = DATE_FMT_12 - return date.strftime(fmt) + return date.strftime(fmt[fmt_index]) @register.inclusion_tag('forums/show_form.html') @@ -94,3 +106,19 @@ 'is_ajax': is_ajax, 'MEDIA_URL': media_url, } + + +@register.inclusion_tag('forums/new_posts_tag.html', takes_context=True) +def new_posts(context): + """ + This tag displays the topics that have the newest posts. + Only the "public" forums are displayed. + """ + topics = Topic.objects.filter( + forum__category__groups__isnull=True).select_related( + 'user', 'last_post').order_by('-update_date')[:10] + + return { + 'topics': topics, + 'user': context['user'], + } diff -r ca7d619ee27b -r 416353def4ca gpp/templates/forums/new_posts_tag.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/new_posts_tag.html Sun Dec 20 20:42:19 2009 +0000 @@ -0,0 +1,14 @@ +{% load forum_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 %} +

No forum topics at this time.

+{% endif %} +
diff -r ca7d619ee27b -r 416353def4ca gpp/templates/home.html --- a/gpp/templates/home.html Sun Dec 20 05:51:22 2009 +0000 +++ b/gpp/templates/home.html Sun Dec 20 20:42:19 2009 +0000 @@ -3,6 +3,7 @@ {% load news_tags %} {% load weblinks_tags %} {% load downloads_tags %} +{% load forum_tags %} {% load cache %} {% block title %}Home{% endblock %} {% block custom_css %} @@ -39,6 +40,7 @@ {% cache 3600 home_bulletins %} {% current_bulletins %} {% endcache %} +{% new_posts %} {% cache 3600 home_news %} {% current_news %} {% endcache %}