Make it possible to drop a shift.
This commit is contained in:
parent
25f40b381b
commit
ca33f8c5eb
|
@ -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()]
|
||||
|
|
|
@ -63,7 +63,12 @@
|
|||
<i class="fas fa-trash"></i> Delete
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if shift.people_required > shift.team_members.count %}
|
||||
{% if user in shift.users %}
|
||||
<a class="btn btn-danger"
|
||||
href="{% url 'teams:shift_member_drop' camp_slug=camp.slug team_slug=team.slug pk=shift.pk %}">
|
||||
<i class="fas fa-thumbs-down"></i> Drop it!
|
||||
</a>
|
||||
{% elif shift.people_required > shift.team_members.count %}
|
||||
<a class="btn btn-success"
|
||||
href="{% url 'teams:shift_member_take' camp_slug=camp.slug team_slug=team.slug pk=shift.pk %}">
|
||||
<i class="fas fa-thumbs-up"></i> Take it!
|
||||
|
|
|
@ -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"
|
||||
),
|
||||
])),
|
||||
]))
|
||||
]),
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue