Skip to content
Snippets Groups Projects
Commit bebf4aca authored by Martin Juhás's avatar Martin Juhás
Browse files

feat: prevent deleting definition with running exercises

No API changes

Closes #209
parent 82942c55
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import os
from django.conf import settings
from common_lib.exceptions import ExerciseOperationException
from common_lib.logger import logger
from common_lib.utils import get_model
from exercise.lib.exercise_manager import ExerciseManager
......@@ -12,7 +13,17 @@ class DefinitionManager:
@staticmethod
def delete_definition(definition_id: int):
definition = get_model(Definition, id=definition_id)
for exercise in definition.exercises.all():
exercises = definition.exercises.all()
running_exercise_ids = [
exercise.id for exercise in exercises if exercise.running
]
if len(running_exercise_ids) != 0:
raise ExerciseOperationException(
f"Cannot delete this definition because "
f"these running exercises depend on it {running_exercise_ids}"
)
for exercise in exercises:
ExerciseManager.delete_exercise(exercise.id)
for file_info in definition.files.all():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment