added available teams template tag
This commit is contained in:
parent
c18fd7e378
commit
6e67b50501
5 changed files with 60 additions and 1 deletions
0
symposion/teams/templatetags/__init__.py
Normal file
0
symposion/teams/templatetags/__init__.py
Normal file
45
symposion/teams/templatetags/teams_tags.py
Normal file
45
symposion/teams/templatetags/teams_tags.py
Normal 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)
|
|
@ -13,4 +13,5 @@ def team_detail(request, slug):
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
return render(request, "teams/team_detail.html", {
|
return render(request, "teams/team_detail.html", {
|
||||||
|
"team": team,
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load proposal_tags %}
|
{% load proposal_tags %}
|
||||||
|
{% load teams_tags %}
|
||||||
|
|
||||||
{% block head_title %}Dashboard{% endblock %}
|
{% block head_title %}Dashboard{% endblock %}
|
||||||
|
|
||||||
|
@ -144,6 +145,10 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% available_teams as available_teams %}
|
||||||
|
{% for team in available_team %}
|
||||||
|
{{ team }}
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
8
symposion_project/templates/teams/team_detail.html
Normal file
8
symposion_project/templates/teams/team_detail.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends "site_base.html" %}
|
||||||
|
|
||||||
|
{% block head_title %}{{ team.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h1>{{ team.name }}</h1>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue