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
 
from django.http import Http404
 
from django.shortcuts import render, get_object_or_404
 

	
 
from django.contrib.auth.decorators import login_required
 

	
 
from symposion.teams.models import Team
 

	
 

	
 
@login_required
 
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
 
{% extends "site_base.html" %}
 

	
 
{% load i18n %}
 
{% load proposal_tags %}
 
{% load teams_tags %}
 

	
 
{% block head_title %}Dashboard{% endblock %}
 

	
 
{% block body_class %}auth{% endblock %}
 

	
 
{% block body %}
 
    <div class="dashboard-panel">
 
        <div class="dashboard-panel-header">
 
            <i class="icon-bullhorn"></i>
 
            <h3>{% trans "Speaking" %}</h3>
 
            <div class="pull-right header-actions">
 
                {% if not user.speaker_profile %}
 
                    <a href="{% url speaker_create %}" class="btn">
 
                        <i class="icon-plus-sign"></i> Create a speaker profile
 
                    </a>
 
                {% else %}
 
                    <a href="{% url speaker_edit %}" class="btn">
 
                        <i class="icon-pencil"></i> Edit your speaker profile
 
                    </a>
 
                    <a href="{% url proposal_submit %}" class="btn">
 
                        <i class="icon-plus-sign"></i> Submit a new proposal
 
                    </a>
 
                {% endif %}
 
            </div>
...
 
@@ -123,27 +124,31 @@
 
    </div>
 

	
 
    <div class="dashboard-panel">
 
        <div class="dashboard-panel-header">
 
            <i class="icon-group"></i>
 
            <h3>{% trans "Teams" %}</h3>
 
        </div>
 
        
 
        <div class="dashboard-panel-content">
 
            {% if user.memberships.exists %}
 
                <h4>Your Teams</h4>
 
                <ul>
 
                    {% for membership in user.memberships.all %}
 
                        <li>
 
                            {% if membership.state == "manager" %}
 
                                <a href="{% url team_detail membership.team.slug %}">{{ membership.team.name }}</a>
 
                            {% else %}
 
                                {{ membership.team.name }}
 
                            {% endif %}
 
                            <span class="badge">{{ membership.get_state_display }}</span>
 
                        </li>
 
                    {% 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)