Browse files

rewrote sponsorship template tags to follow symposion and implemented…

… sponsorship list page
  • Loading branch information...
1 parent 40dabea commit 91736931c5eb846cc58ed61c1d5f8776f0697034 @jtauber jtauber committed Jun 16, 2012
View
71 pycon/sponsorship/templatetags/sponsorship_tags.py
@@ -1,6 +1,7 @@
from django import template
-from pycon.sponsorship.models import Sponsor
+from symposion.conference.models import current_conference
+from pycon.sponsorship.models import Sponsor, SponsorLevel
register = template.Library()
@@ -11,37 +12,63 @@ class SponsorsNode(template.Node):
@classmethod
def handle_token(cls, parser, token):
bits = token.split_contents()
- section = "all"
- if len(bits) != 3 and len(bits) != 4:
- raise template.TemplateSyntaxError("%r takes two to three arguments "
- "(second to last argument must be 'as')" % bits[0])
- if bits[-2] != "as":
- raise template.TemplateSyntaxError("Second to last argument to %r must be "
- "'as'" % bits[0])
- if len(bits) == 4:
- section = bits[1]
- return cls(bits[-1], section)
+ if len(bits) == 3 and bits[1] == "as":
+ return cls(bits[2])
+ elif len(bits) == 4 and bits[2] == "as":
+ return cls(bits[3], bits[1])
+ else:
+ raise template.TemplateSyntaxError("%r takes 'as var' or 'level as var'" % bits[0])
- def __init__(self, context_var, section):
- self.section = section
+ def __init__(self, context_var, level=None):
+ if level:
+ self.level = template.Variable(level)
+ else:
+ self.level = None
self.context_var = context_var
def render(self, context):
- queryset = Sponsor.objects.active()
- queryset = queryset.select_related("level", "sponsor_logo")
- if self.section == "header":
- queryset = queryset.filter(level__in=[1])
- if self.section == "scroll":
- queryset = queryset.filter(level__in=[2, 3])
- if self.section == "footer":
- queryset = queryset.filter(level__in=[4, 10])
+ conference = current_conference()
+ if self.level:
+ level = self.level.resolve(context)
+ queryset = Sponsor.objects.filter(level__conference = conference, level__name__iexact = level, active = True).order_by("added")
+ else:
+ queryset = Sponsor.objects.filter(level__conference = conference, active = True).order_by("level__order", "added")
context[self.context_var] = queryset
return u""
+class SponsorLevelNode(template.Node):
+
+ @classmethod
+ def handle_token(cls, parser, token):
+ bits = token.split_contents()
+ if len(bits) == 3 and bits[1] == "as":
+ return cls(bits[2])
+ else:
+ raise template.TemplateSyntaxError("%r takes 'as var'" % bits[0])
+
+ def __init__(self, context_var):
+ self.context_var = context_var
+
+ def render(self, context):
+ conference = current_conference()
+ context[self.context_var] = SponsorLevel.objects.filter(conference=conference)
+ return u""
+
+
@register.tag
def sponsors(parser, token):
"""
- {% sponsors [header, scroll, footer, all] as sponsors %}
+ {% sponsors as all_sponsors %}
+ or
+ {% sponsors "gold" as gold_sponsors %}
"""
return SponsorsNode.handle_token(parser, token)
+
+
+@register.tag
+def sponsor_levels(parser, token):
+ """
+ {% sponsor_levels as levels %}
+ """
+ return SponsorLevelNode.handle_token(parser, token)
View
2 pycon/sponsorship/urls.py
@@ -3,7 +3,7 @@
urlpatterns = patterns("pycon.sponsorship.views",
- url(r"^$", direct_to_template, {"template": "sponsors/list.html"}, name="sponsor_list"),
+ url(r"^$", direct_to_template, {"template": "sponsorship/list.html"}, name="sponsor_list"),
url(r"^info/$", "sponsor_info", name="sponsor_info"),
url(r"^jobs/$", direct_to_template, {"template": "sponsors/jobs.html"}, name="sponsor_jobs"),
url(r"^apply/$", "sponsor_apply", name="sponsor_apply"),
View
3 symposion/templates/sponsorship/apply.html
@@ -5,6 +5,9 @@
{% block body_class %}sponsors{% endblock %}
{% block body %}
+
+ {# box "sponsorship-apply" #}
+
<form method="POST" action="" class="uniForm">
{% csrf_token %}
<legend>Apply to Be a Sponsor</legend>
View
55 symposion/templates/sponsorship/list.html
@@ -0,0 +1,55 @@
+{% extends "site_base.html" %}
+
+{% load sponsorship_tags %}
+{% load thumbnail %}
+
+{% block body %}
+
+ <h1>About PyCon Sponsors</h1>
+
+ {% sponsor_levels as levels %}
+
+ <div class="row">
+ <div class="span8">
+ <div class="sponsor-list">
+
+ {% for level in levels %}
+ <h3>{{ level.name }}</h3>
+
+ {% for sponsor in level.sponsors %}
+ <div class="sponsor-details row" id="sponsor-{{ sponsor.id }}">
+ <div class="span4">
+ <a href="{{ sponsor.external_url }}">
+ <img src="{% thumbnail sponsor.logo '160x80' %}" alt="{{ sponsor.name }}" />
+ </a>
+ </div>
+ <div class="span4">
+ <h2>{{ sponsor.name }}</h2>
+ <p><a href="{{ sponsor.external_url }}">{{ sponsor.external_url }}</a></p>
+ <p>{{ sponsor.listing_text|urlize|linebreaks }}</p>
+ </div>
+ </div>
+ {% endfor %}
+ {% endfor %}
+ </div>
+ </div>
+
+ <div class="span4">
+ {# include "sponsors/_subnav1.html" #}
+ <p>
+ <a href="{% url sponsor_info %}" class="btn btn-sponsor">
+ Learn how to<br />become a <b>sponsor</b>
+ </a>
+ </p>
+ <nav class="sidenav sponsor-sidenav">
+ <ul>
+ {% for level in levels %}
+ {% for sponsor in level.sponsors %}
+ <li><a href="#sponsor-{{ sponsor.id }}">{{ sponsor.name }}</a></li>
+ {% endfor %}
+ {% endfor %}
+ </ul>
+ </nav>
+ </div>
+ </div>
+{% endblock %}

0 comments on commit 9173693

Please sign in to comment.