Skip to content

Commit

Permalink
Coordinators must remove all students manually for a delete section r…
Browse files Browse the repository at this point in the history
…equest to go through
  • Loading branch information
KartavyaSharma committed Sep 19, 2023
1 parent e2e56b3 commit e53cc8b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions csm_web/scheduler/views/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def destroy(self, request, pk=None):
"""
section = get_object_or_error(self.get_queryset(), pk=pk)
course = section.mentor.course
# If the course has students, we cannot delete the section
if section.students.count() > 0:
logger.error(
(
"<Section Deletion:Failure> Could not delete section %s, it has"
" students. Remove all students manually first."
),
log_str(section),
)
is_coordinator = course.coordinator_set.filter(user=request.user).exists()
if not is_coordinator:
logger.error(
Expand All @@ -138,9 +147,6 @@ def destroy(self, request, pk=None):
raise PermissionDenied(
"You must be a coordinator to delete this spacetime!"
)
# Delete all students in the section
for student in section.students.all():
student.delete()
# Delete all spacetimes in the section
for spacetime in section.spacetimes.all():
spacetime.delete()
Expand Down

0 comments on commit e53cc8b

Please sign in to comment.