From cc4e44d67bbd689249d5e2b2336b72d107fe6d9b Mon Sep 17 00:00:00 2001 From: Philip Dolbel Date: Thu, 15 Dec 2022 10:31:19 +1300 Subject: [PATCH] Add deletion checks to even more loaders --- .../management/commands/load_at_a_distance_data.py | 5 +++++ csunplugged/at_home/management/commands/_ChallengeLoader.py | 6 ++++++ csunplugged/at_home/management/commands/loadactivities.py | 5 +++++ 3 files changed, 16 insertions(+) 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 8c05c15ed..f717751de 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 88f50d52b..e793dd336 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 c6b550f9b..2fa74c966 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"]))