implemented team apply
This commit is contained in:
parent
a4dea58195
commit
1bfd0cc2f0
3 changed files with 34 additions and 0 deletions
|
@ -5,5 +5,6 @@ urlpatterns = patterns("symposion.teams.views",
|
|||
url(r"^(?P<slug>[\w\-]+)/$", "team_detail", name="team_detail"),
|
||||
url(r"^(?P<slug>[\w\-]+)/join/$", "team_join", name="team_join"),
|
||||
url(r"^(?P<slug>[\w\-]+)/leave/$", "team_leave", name="team_leave"),
|
||||
url(r"^(?P<slug>[\w\-]+)/apply/$", "team_apply", name="team_apply"),
|
||||
|
||||
)
|
||||
|
|
|
@ -29,6 +29,14 @@ def can_leave(team, user):
|
|||
return False
|
||||
|
||||
|
||||
def can_apply(team, user):
|
||||
state = team.get_state_for_user(user)
|
||||
if team.access == "application" and state is None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
## views
|
||||
|
||||
|
||||
|
@ -44,6 +52,7 @@ def team_detail(request, slug):
|
|||
"state": state,
|
||||
"can_join": can_join(team, request.user),
|
||||
"can_leave": can_leave(team, request.user),
|
||||
"can_apply": can_apply(team, request.user),
|
||||
})
|
||||
|
||||
|
||||
|
@ -78,3 +87,20 @@ def team_leave(request, slug):
|
|||
return redirect("dashboard")
|
||||
else:
|
||||
return redirect("team_detail", slug=slug)
|
||||
|
||||
|
||||
@login_required
|
||||
def team_apply(request, slug):
|
||||
team = get_object_or_404(Team, slug=slug)
|
||||
state = team.get_state_for_user(request.user)
|
||||
if team.access == "invitation" and state is None:
|
||||
raise Http404()
|
||||
|
||||
if can_apply(team, request.user) and request.method == "POST":
|
||||
membership, created = Membership.objects.get_or_create(team=team, user=request.user)
|
||||
membership.state = "applied"
|
||||
membership.save()
|
||||
# contrib.message
|
||||
return redirect("team_detail", slug=slug)
|
||||
else:
|
||||
return redirect("team_detail", slug=slug)
|
||||
|
|
|
@ -19,4 +19,11 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if can_apply %}
|
||||
<form method="post" action="{% url team_apply team.slug %}">
|
||||
{% csrf_token %}
|
||||
<input type="submit" class="btn btn-primary" value="apply">
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue