Skip to content

Commit

Permalink
closes #116
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemaddem committed Feb 1, 2021
1 parent b090827 commit 4c3619f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion project-templates/teams/team_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ <h2>No image yet</h2>
{% if team.founder == request.user %}
<a href="{% url 'teams:remove' pk %}">Remove users</a><br>
<a href="{% url 'teams:edit' pk %}">Edit Team</a><br>
<a href="{% url 'teams:invite' %}">Invite Players</a>
<a href="{% url 'teams:invite' %}">Invite Players</a><br>
{% if team.founder not in team.captain.all %}
<a href="{% url 'teams:founder_captain' pk %}">Add Founder as Captain</a>
{% endif %}
{% endif %}


Expand Down
6 changes: 4 additions & 2 deletions teams/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.urls import path

from teams.views import MyTeamsListView, MyTeamDetailView, TeamCreateView, TeamInviteCreateView, MyInvitesListView, \
invite_view
invite_view, add_founder_as_captain
from . import views

app_name = 'teams'
Expand All @@ -17,5 +17,7 @@
path('<int:pk>/edit/', login_required(views.edit_team_view), name='edit'),
path('<int:pk>/leave/', login_required(views.LeaveTeamView.as_view()), name='leave'),
path('<int:pk>/remove/', login_required(views.RemoveUserView.as_view()), name='remove'),
path('<int:pk>/dissolve/', login_required(views.DissolveTeamView.as_view()), name='dissolve')
path('<int:pk>/dissolve/', login_required(views.DissolveTeamView.as_view()), name='dissolve'),
path('<int:pk>/founder-captain/', login_required(add_founder_as_captain), name='founder_captain')

]
22 changes: 22 additions & 0 deletions teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ def post(self, request, pk):
return redirect('teams:detail', pk)


def add_founder_as_captain(request, pk):
team = Team.objects.get(pk=pk)
if team != None:
if request.user == team.founder:
# its the right guy
if team.founder not in team.captain.all():
team.captain.add(request.user)
# mtm fields don't need to be saved :thinking:
# team.captain.save()
messages.success(request, "You were added as a captain to the team")
return redirect('teams:detail', pk=pk)
else:
messages.error(request, "You are already a captain on your team")
return redirect('teams:detail', pk=pk)
else:
messages.error(request, "Error, You are not the founder of this team")
return redirect('teams:detail', pk=pk)
else:
messages.error(request, "Error finding the correct team")
return redirect('teams:detail', pk=pk)


class DissolveTeamView(View):
template_name = 'teams/team_dissolve.html'

Expand Down

0 comments on commit 4c3619f

Please sign in to comment.