diff --git a/csunplugged/at_a_distance/management/commands/load_at_a_distance_data.py b/csunplugged/at_a_distance/management/commands/load_at_a_distance_data.py index 8c05c15edf..1e2bfaf6d2 100644 --- a/csunplugged/at_a_distance/management/commands/load_at_a_distance_data.py +++ b/csunplugged/at_a_distance/management/commands/load_at_a_distance_data.py @@ -7,6 +7,7 @@ from utils.LoaderFactory import LoaderFactory from utils.errors.MissingRequiredFieldError import MissingRequiredFieldError from utils.errors.InvalidYAMLValueError import InvalidYAMLValueError +from at_a_distance.models import Lesson class Command(BaseCommand): @@ -56,3 +57,7 @@ def handle(self, *args, **options): content_path=lesson_slug, structure_filename=lesson_structure_file, ).load() + + _, results = Lesson.objects.exclude(slug__in=structure_file["lessons"]).delete(); + if results.get("at_a_distance", 0) > 0: + print(f"Deleted {results['at_a_distance.Lesson']} lessons") diff --git a/csunplugged/at_home/management/commands/_ChallengeLoader.py b/csunplugged/at_home/management/commands/_ChallengeLoader.py index 88f50d52bc..e793dd336b 100644 --- a/csunplugged/at_home/management/commands/_ChallengeLoader.py +++ b/csunplugged/at_home/management/commands/_ChallengeLoader.py @@ -74,3 +74,9 @@ def load(self): self.log("Added challenge: {}".format(challenge.__str__()), 1) else: self.log("Updated challenge: {}".format(challenge.__str__()), 1) + + _, results = Challenge.objects.filter(activity=self.activity).exclude( + order_number__in=challenge_translations.keys() + ).delete() + if results.get("at_home.Challenge", 0) > 0: + self.log("Deleted {} challenges".format(results["at_home.Challenge"]), 1) diff --git a/csunplugged/at_home/management/commands/loadactivities.py b/csunplugged/at_home/management/commands/loadactivities.py index c6b550f9b8..2fa74c9660 100644 --- a/csunplugged/at_home/management/commands/loadactivities.py +++ b/csunplugged/at_home/management/commands/loadactivities.py @@ -6,6 +6,7 @@ from utils.BaseLoader import BaseLoader from utils.LoaderFactory import LoaderFactory from utils.errors.MissingRequiredFieldError import MissingRequiredFieldError +from at_home.models import Activity class Command(BaseCommand): @@ -61,3 +62,7 @@ def handle(self, *args, **options): lite_loader=lite_load, activity_data=activity_data, ).load() + + _, result = Activity.objects.exclude(slug__in=structure_file["activities"].keys()).delete() + if result.get("at_home.Activity", 0) > 0: + print("Deleted {} activities".format(result["at_home.Activity"])) diff --git a/csunplugged/tests/at_a_distance/loaders/test_lessons_loader.py b/csunplugged/tests/at_a_distance/loaders/test_lessons_loader.py index 2601d4e59d..cd71f75cfd 100644 --- a/csunplugged/tests/at_a_distance/loaders/test_lessons_loader.py +++ b/csunplugged/tests/at_a_distance/loaders/test_lessons_loader.py @@ -227,3 +227,6 @@ def test_lesson_loader_missing_supporting_resources(self): CouldNotFindYAMLFileError, lesson_loader.load, ) + + def test_lesson_loader_insert_start(self): +