implemented promote to / demote from manager

This commit is contained in:
James Tauber 2012-08-02 13:17:16 -04:00
parent 7db401e9a2
commit 2c69596ec6
3 changed files with 44 additions and 1 deletions

View file

@ -7,4 +7,6 @@ urlpatterns = patterns("symposion.teams.views",
url(r"^(?P<slug>[\w\-]+)/leave/$", "team_leave", name="team_leave"),
url(r"^(?P<slug>[\w\-]+)/apply/$", "team_apply", name="team_apply"),
url(r"^promote/(?P<pk>\d+)/$", "team_promote", name="team_promote"),
url(r"^demote/(?P<pk>\d+)/$", "team_demote", name="team_demote"),
)

View file

@ -108,3 +108,29 @@ def team_apply(request, slug):
return redirect("team_detail", slug=slug)
else:
return redirect("team_detail", slug=slug)
@login_required
def team_promote(request, pk):
if request.method == "POST":
membership = get_object_or_404(Membership, pk=pk)
state = membership.team.get_state_for_user(request.user)
if request.user.is_staff or state == "manager":
if membership.state == "member":
membership.state = "manager"
membership.save()
# contrib.message
return redirect("team_detail", slug=membership.team.slug)
@login_required
def team_demote(request, pk):
if request.method == "POST":
membership = get_object_or_404(Membership, pk=pk)
state = membership.team.get_state_for_user(request.user)
if request.user.is_staff or state == "manager":
if membership.state == "manager":
membership.state = "member"
membership.save()
# contrib.message
return redirect("team_detail", slug=membership.team.slug)

View file

@ -29,13 +29,28 @@
{% endif %}
{% if user.is_staff or state == "manager" %}
{% if team.managers %}
<h2>Managers</h2>
<table class="table table-striped">
{% for membership in team.managers %}
<tr>
<td>{{ membership.user.email }}</td>
<td>
<form style="margin: 0;" method="post" action="{% url team_demote membership.pk %}">{% csrf_token %}<button type="submit" class="btn btn-mini">demote</button></form>
</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if team.members %}
<h2>Team Members</h2>
<table class="table table-striped">
{% for membership in team.members %}
<tr>
<td>{{ membership.user.email }}</td>
<td>{{ membership.state }}</td>
<td>
<form style="margin: 0;" method="post" action="{% url team_promote membership.pk %}">{% csrf_token %}<button type="submit" class="btn btn-mini">promote</button></form>
</td>
</tr>
{% endfor %}
</table>