added available teams template tag

This commit is contained in:
James Tauber 2012-08-01 21:38:50 -04:00
parent c18fd7e378
commit 6e67b50501
5 changed files with 60 additions and 1 deletions

View file

View file

@ -0,0 +1,45 @@
from django import template
from symposion.teams.models import Team
register = template.Library()
class AvailableTeamsNode(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):
request = context["request"]
teams = []
for team in Team.objects.all():
print team
state = team.get_state_for_user(request.user)
if team.access == "open":
if state in [None, "invited"]:
teams.append(team)
elif team.access == "application":
if state in [None, "invited", "applied"]:
teams.append(team)
elif team.access == "invitation":
if state == "invited":
teams.append(team)
context[self.context_var] = teams
return u""
@register.tag
def available_teams(parser, token):
"""
{% available_teams as available_teams %}
"""
return AvailableTeamsNode.handle_token(parser, token)

View file

@ -13,4 +13,5 @@ def team_detail(request, slug):
raise Http404()
return render(request, "teams/team_detail.html", {
"team": team,
})

View file

@ -2,6 +2,7 @@
{% load i18n %}
{% load proposal_tags %}
{% load teams_tags %}
{% block head_title %}Dashboard{% endblock %}
@ -144,6 +145,10 @@
{% endfor %}
</ul>
{% endif %}
{% available_teams as available_teams %}
{% for team in available_team %}
{{ team }}
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,8 @@
{% extends "site_base.html" %}
{% block head_title %}{{ team.name }}{% endblock %}
{% block body %}
<h1>{{ team.name }}</h1>
{% endblock %}