diff --git a/src/teams/models.py b/src/teams/models.py
index f376fc85..f78aba71 100644
--- a/src/teams/models.py
+++ b/src/teams/models.py
@@ -356,3 +356,7 @@ class TeamShift(CampRelatedModel):
self.shift_range.lower,
self.shift_range.upper
)
+
+ @property
+ def users(self):
+ return [member.user for member in self.team_members.all()]
diff --git a/src/teams/templates/team_shift_list.html b/src/teams/templates/team_shift_list.html
index 42f2ddb3..063cc077 100644
--- a/src/teams/templates/team_shift_list.html
+++ b/src/teams/templates/team_shift_list.html
@@ -63,7 +63,12 @@
Delete
{% endif %}
- {% if shift.people_required > shift.team_members.count %}
+ {% if user in shift.users %}
+
+ Drop it!
+
+ {% elif shift.people_required > shift.team_members.count %}
Take it!
diff --git a/src/teams/urls.py b/src/teams/urls.py
index d2c116c2..37100380 100644
--- a/src/teams/urls.py
+++ b/src/teams/urls.py
@@ -36,6 +36,7 @@ from teams.views.shifts import (
ShiftUpdateView,
ShiftDeleteView,
MemberTakesShift,
+ MemberDropsShift,
)
app_name = 'teams'
@@ -186,6 +187,11 @@ urlpatterns = [
MemberTakesShift.as_view(),
name="shift_member_take"
),
+ path(
+ 'drop',
+ MemberDropsShift.as_view(),
+ name="shift_member_drop"
+ ),
])),
]))
]),
diff --git a/src/teams/views/shifts.py b/src/teams/views/shifts.py
index 0a3d3694..cb4fe026 100644
--- a/src/teams/views/shifts.py
+++ b/src/teams/views/shifts.py
@@ -286,7 +286,7 @@ class ShiftCreateMultipleView(LoginRequiredMixin, CampViewMixin, FormView):
return context
-class MemberTakesShift(CampViewMixin, View):
+class MemberTakesShift(LoginRequiredMixin, CampViewMixin, View):
http_methods = ['get']
@@ -309,3 +309,28 @@ class MemberTakesShift(CampViewMixin, View):
kwargs=kwargs
)
)
+
+
+class MemberDropsShift(LoginRequiredMixin, CampViewMixin, View):
+
+ http_methods = ['get']
+
+ def get(self, request, **kwargs):
+ shift = TeamShift.objects.get(id=kwargs['pk'])
+ team = Team.objects.get(
+ camp=self.camp,
+ slug=kwargs['team_slug']
+ )
+
+ team_member = TeamMember.objects.get(team=team, user=request.user)
+
+ shift.team_members.remove(team_member)
+
+ kwargs.pop('pk')
+
+ return HttpResponseRedirect(
+ reverse(
+ 'teams:shifts',
+ kwargs=kwargs
+ )
+ )