changeset 788:84aa49497718

Added a current contests template tag & installed in sidebar.
author Brian Neal <bgneal@gmail.com>
date Sun, 18 May 2014 17:43:37 -0500
parents 7e17b9e45356
children 9e803323a0d0
files contests/models.py contests/templatetags/__init__.py contests/templatetags/contest_tags.py sg101/templates/base.html sg101/templates/contests/latest_contests_block_tag.html
diffstat 4 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contests/models.py	Sat May 17 12:17:14 2014 -0500
+++ b/contests/models.py	Sun May 18 17:43:37 2014 -0500
@@ -17,6 +17,10 @@
     def get_queryset(self):
         return super(PublicContestManager, self).get_queryset().filter(is_public=True)
 
+    def get_current_contests(self):
+        now = datetime.datetime.now()
+        return self.filter(creation_date__lte=now, win_date__isnull=True)
+
 
 class Contest(models.Model):
     """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contests/templatetags/contest_tags.py	Sun May 18 17:43:37 2014 -0500
@@ -0,0 +1,16 @@
+"""Template tags for the contests application.
+
+"""
+
+from django import template
+
+from contests.models import Contest
+
+
+register = template.Library()
+
+
+@register.inclusion_tag('contests/latest_contests_block_tag.html')
+def latest_contests_block():
+    contests = Contest.public_objects.get_current_contests()
+    return {'contests': contests}
--- a/sg101/templates/base.html	Sat May 17 12:17:14 2014 -0500
+++ b/sg101/templates/base.html	Sun May 18 17:43:37 2014 -0500
@@ -5,6 +5,7 @@
 {% load potd_tags %}
 {% load script_tags %}
 {% load poll_tags %}
+{% load contest_tags %}
 {% load donations_tags %}
 {% load core_tags %}
 {% load cache %}
@@ -73,6 +74,9 @@
    {% cache 3600 poll_block %}
       {% latest_poll_block %}
    {% endcache %}
+   {% cache 3600 contests_block %}
+      {% latest_contests_block %}
+   {% endcache %}
    {% cache 600 donations_block %}
       {% monthly_goal %}
    {% endcache %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/contests/latest_contests_block_tag.html	Sun May 18 17:43:37 2014 -0500
@@ -0,0 +1,14 @@
+{% extends 'side_block.html' %}
+{% block block_title %}Current Contests{% endblock %}
+{% block block_content %}
+{% if contests %}
+<ul>
+   {% for contest in contests %}
+   <li><a href="{{ contest.get_absolute_url }}">{{ contest.title }}</a></li>
+   {% endfor %}
+</ul>
+{% else %}
+<p class="centered">No contests at this time. Check out our
+<a href="{% url 'contests-index' %}">past contests</a>.</p>
+{% endif %}
+{% endblock %}