Changeset - 6e67b505013b
[Not reviewed]
0 2 3
James Tauber - 12 years ago 2012-08-02 01:39:00
jtauber@jtauber.com
added available teams template tag
5 files changed with 60 insertions and 1 deletions:
0 comments (0 inline, 0 general)
symposion/teams/templatetags/__init__.py
Show inline comments
 
new file 100644
symposion/teams/templatetags/teams_tags.py
Show inline comments
 
new file 100644
 
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)
symposion/teams/views.py
Show inline comments
...
 
@@ -11,6 +11,7 @@ def team_detail(request, slug):
 
    team = get_object_or_404(Team, slug=slug)
 
    if team.get_state_for_user(request.user) != "manager":
 
        raise Http404()
 

 
    
 
    return render(request, "teams/team_detail.html", {
 
        "team": team,
 
    })
symposion_project/templates/dashboard.html
Show inline comments
...
 
@@ -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 %}
symposion_project/templates/teams/team_detail.html
Show inline comments
 
new file 100644
 
{% extends "site_base.html" %}
 

	
 
{% block head_title %}{{ team.name }}{% endblock %}
 

	
 
{% block body %}
 
    <h1>{{ team.name }}</h1>
 
    
 
{% endblock %}
0 comments (0 inline, 0 general)