Skip to content

Commit

Permalink
Add deletion checks to even more loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamboy1 committed Dec 14, 2022
1 parent 04f00e2 commit 1e1acc3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
6 changes: 6 additions & 0 deletions csunplugged/at_home/management/commands/_ChallengeLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions csunplugged/at_home/management/commands/loadactivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]))
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,6 @@ def test_lesson_loader_missing_supporting_resources(self):
CouldNotFindYAMLFileError,
lesson_loader.load,
)

def test_lesson_loader_insert_start(self):

0 comments on commit 1e1acc3

Please sign in to comment.