# HG changeset patch # User Brian Neal # Date 1263759841 0 # Node ID 8acf5be27f18083f339ceec057188dfa19f7937f # Parent 952e05cb3d8004e9e347956ca6df28bf1a14dff2 Implement #50, add a template tag to display the latest poll and add to the home page. diff -r 952e05cb3d80 -r 8acf5be27f18 gpp/polls/templatetags/poll_tags.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/polls/templatetags/poll_tags.py Sun Jan 17 20:24:01 2010 +0000 @@ -0,0 +1,18 @@ +""" +Template tags for the Polls application. +""" +from django import template + +from polls.models import Poll + +register = template.Library() + + +@register.inclusion_tag("polls/latest_poll_tag.html") +def latest_poll(): + try: + poll = Poll.objects.get_current_polls()[0] + except IndexError: + poll = None + + return {'poll': poll } diff -r 952e05cb3d80 -r 8acf5be27f18 gpp/polls/urls.py --- a/gpp/polls/urls.py Sun Jan 03 04:15:14 2010 +0000 +++ b/gpp/polls/urls.py Sun Jan 17 20:24:01 2010 +0000 @@ -2,8 +2,8 @@ from django.conf.urls.defaults import * urlpatterns = patterns('polls.views', - url(r'^$', 'poll_index', name='polls-main'), - (r'^(?P\d+)/$', 'poll_detail'), - (r'^(?P\d+)/results/$', 'poll_results'), - (r'^(?P\d+)/vote/$', 'poll_vote'), + url(r'^$', 'poll_index', name='polls-main'), + url(r'^(?P\d+)/$', 'poll_detail', name='polls-detail'), + url(r'^(?P\d+)/results/$', 'poll_results', name='polls-results'), + url(r'^(?P\d+)/vote/$', 'poll_vote', name='polls-vote'), ) diff -r 952e05cb3d80 -r 8acf5be27f18 gpp/templates/home.html --- a/gpp/templates/home.html Sun Jan 03 04:15:14 2010 +0000 +++ b/gpp/templates/home.html Sun Jan 17 20:24:01 2010 +0000 @@ -3,6 +3,7 @@ {% load news_tags %} {% load weblinks_tags %} {% load downloads_tags %} +{% load poll_tags %} {% load forum_tags %} {% load cache %} {% block title %}Home{% endblock %} @@ -45,6 +46,7 @@ {% current_news %} {% endcache %} {% cache 3600 home_new_stuff %} +{% latest_poll %}
{% latest_weblinks %}
diff -r 952e05cb3d80 -r 8acf5be27f18 gpp/templates/polls/latest_poll_tag.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/polls/latest_poll_tag.html Sun Jan 17 20:24:01 2010 +0000 @@ -0,0 +1,13 @@ +{% if poll %} +
+

Latest Poll

+

{{ poll.question }}

+
    + {% for choice in poll.choice_set.all %} +
  • {{ choice.choice }}
  • + {% endfor %} +
+

Go see the results and vote + or check out more polls.

+
+{% endif %}