# HG changeset patch # User Brian Neal # Date 1400453017 18000 # Node ID 84aa494977186da79e4419c23e1304b1852745d0 # Parent 7e17b9e453566a55d91bb5bb2cbec751162e591e Added a current contests template tag & installed in sidebar. diff -r 7e17b9e45356 -r 84aa49497718 contests/models.py --- 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): """ diff -r 7e17b9e45356 -r 84aa49497718 contests/templatetags/contest_tags.py --- /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} diff -r 7e17b9e45356 -r 84aa49497718 sg101/templates/base.html --- 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 %} diff -r 7e17b9e45356 -r 84aa49497718 sg101/templates/contests/latest_contests_block_tag.html --- /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 %} + +{% else %} +

No contests at this time. Check out our +past contests.

+{% endif %} +{% endblock %}