Fix several bugs migrate_objective snapshots command

This commit is contained in:
Lorenz Padberg 2024-02-05 10:46:18 +01:00
parent e338f2e2ad
commit d3b51b1006
1 changed files with 30 additions and 19 deletions

View File

@ -57,10 +57,18 @@ class Command(BaseCommand):
createed_content_blocks = 0
visible_objectives_by_ids = {}
snapshot_counter = 0
for module in Module.objects.all(): # .filter(title__contains="Politik mitbestimmen"):
for snapshot in Snapshot.objects.filter(module=module):
for objective_group_snapshot in snapshot.objective_groups.through.objects.filter(objective_group__module=module,snapshot=snapshot):
group_counter = snapshot.objective_groups.through.objects.filter(objective_group__module=module,
snapshot=snapshot).count()
print(
f"{snapshot_counter} Snapshot id: {snapshot.id} Module: {module.title} {group_counter} groups {snapshot.creator} {snapshot.title}")
snapshot_counter += 1
for objective_group_snapshot in snapshot.objective_groups.through.objects.filter(
objective_group__module=module, snapshot=snapshot):
header = f"{count} {module.title:50} {objective_group_snapshot.objective_group.get_title_display():25} {str(snapshot.creator):40} {objective_group_snapshot.hidden} "
count += 1
objective_group = objective_group_snapshot.objective_group
@ -72,7 +80,6 @@ class Command(BaseCommand):
group=objective_group_snapshot.objective_group)
group_is_hidden = objective_group_snapshot.hidden
info = f"{hidden_default_objectives.count()} {visible_custom_objectives.count()}"
if (not hidden_default_objectives and not visible_custom_objectives and not group_is_hidden):
@ -91,11 +98,14 @@ class Command(BaseCommand):
if hidden_default_objectives or visible_custom_objectives:
print(header + f"Case 3 - {info} create custom content blocks")
case3_count += 1
# Verlags Lernziele
default_objectives = Objective.objects.filter(group=objective_group,
group__module=module,
owner__isnull=True)
visible_default_objectives = [objective for objective in default_objectives if objective.id not in hidden_default_objectives.values_list("id", flat=True)]
owner__isnull=True,
objectivesnapshot__isnull=True)
visible_default_objectives = [objective for objective in default_objectives if
objective.id not in hidden_default_objectives.values_list("id",
flat=True)]
# Benutzerdefinierte Lernziele
visible_custom_objectives = list(snapshot.custom_objectives.filter(hidden=False))
@ -120,23 +130,24 @@ class Command(BaseCommand):
for objectives in visible_objectives_by_ids.values():
print("")
for objective in objectives:
print(f" Objective: {objective.group} {objective} {objective.owner}")
print(f" Objective: {objective.group} {objective} owner:{objective.owner}")
print("-")
print(f" visible_objectives_by_ids: {len(visible_objectives_by_ids.items())}")
# create custom content blocks with the objectives
created_content_blocks = 0
for objectives in visible_objectives_by_ids.values():
chapter = module.get_first_child()
if "Lernziele" not in chapter.title:
raise Exception(f"Chapter does not contain 'Lernziele' first title is {chapter.title}")
#
# Owner des custom blocks festlegen
custom_content_block_snapshot = create_content_block_snapshot_from_objective(
objectives[0].group, chapter, snapshot,
objective_group, chapter, snapshot,
owner=snapshot.creator,
prefix="SNAP ")
#
objectives = list(visible_objectives_by_ids.values())[0]
create_text_in_content_block(objectives, custom_content_block_snapshot, get_or_create=True)
created_content_blocks += 1
snapshot.save()