Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deletion checks to even more loaders #2070

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]))