Add edit/delete actions to the teams list
Admin-only, matching TeamCreateView/TeamUpdateView's existing gate. Deleting cascades away the team's roster and staff assignments -- no ProtectedError to catch, unlike a Member that orders/invoices can still reference. Edit links to the detail page rather than the edit form directly, same convention as the news and member lists.
This commit is contained in:
@@ -713,6 +713,19 @@ class TeamUpdateView(ClubAdminRequiredMixin, UpdateView):
|
||||
return super().get_context_data(update_view=True, **kwargs)
|
||||
|
||||
|
||||
class TeamDeleteView(ClubAdminRequiredMixin, View):
|
||||
def post(self, request, pk):
|
||||
team = get_object_or_404(Team.objects.filter(club=request.club), pk=pk)
|
||||
name = str(team)
|
||||
# TeamMembership/StaffAssignment cascade away with the team -- no ProtectedError
|
||||
# to catch, unlike a Member (which orders/invoices can still reference).
|
||||
team.delete()
|
||||
|
||||
body = _("“%(team)s” has been deleted.") % {"team": name}
|
||||
notify(request, f"w|{_('Team deleted')}|{body}")
|
||||
return redirect("management:team_list")
|
||||
|
||||
|
||||
class TeamDetailView(ClubStaffRequiredMixin, DetailView):
|
||||
template_name = "management/team_detail.html"
|
||||
context_object_name = "team"
|
||||
|
||||
Reference in New Issue
Block a user