Refactoring
This commit is contained in:
parent
2446b52596
commit
6069c47c5e
|
|
@ -20,6 +20,8 @@ class Command(BaseCommand):
|
|||
ContentBlock.objects.filter(title__startswith="XXX").delete()
|
||||
Chapter.objects.filter(title__startswith="XXX").delete()
|
||||
|
||||
createed_content_blocks = 0
|
||||
|
||||
for module in Module.objects.filter(title="Politische Streitfragen"):
|
||||
print(f"Module: {module}")
|
||||
chapter = create_chapter_from_objective_group(module)
|
||||
|
|
@ -27,38 +29,42 @@ class Command(BaseCommand):
|
|||
for objective_group in module.objective_groups.all():
|
||||
default_content_block = create_default_content(objective_group, chapter)
|
||||
|
||||
|
||||
# Create "Benutzerdefinierte Lernziele"
|
||||
|
||||
custom_objectives_by_owner = get_objectives_by_owner(objective_group)
|
||||
|
||||
|
||||
for owner, owner_objectives in custom_objectives_by_owner.items():
|
||||
print(f" Owner: {owner}")
|
||||
print(f" Objectives: ")
|
||||
|
||||
default_objectives = list(objective_group.objectives.filter(owner__isnull=True))
|
||||
|
||||
visible_default_objectives_by_class = remove_hidden_objectives(default_objectives, owner)
|
||||
contentblocks_by_merged_objectives_ids = {}
|
||||
|
||||
for school_class in visible_default_objectives_by_class.keys():
|
||||
print(f" School class: {school_class}")
|
||||
school_class_objectives = visible_default_objectives_by_class[school_class] + owner_objectives
|
||||
merged_objectives = visible_default_objectives_by_class[school_class] + owner_objectives
|
||||
merged_objectives_ids = tuple(objective.id for objective in merged_objectives)
|
||||
|
||||
for objective in school_class_objectives:
|
||||
print(f" Objective: {objective} {objective.owner}")
|
||||
custom_content_block = create_content_block_from_objective(objective_group, chapter,
|
||||
owner=owner)
|
||||
|
||||
create_text_in_content_block(school_class_objectives, custom_content_block)
|
||||
custom_content_block.visible_for.add(school_class)
|
||||
# Create content block if that set of objectives has not been created yet
|
||||
if merged_objectives_ids not in contentblocks_by_merged_objectives_ids:
|
||||
for objective in merged_objectives:
|
||||
print(f" Objective: {objective} {objective.owner}")
|
||||
custom_content_block = create_content_block_from_objective(objective_group, chapter,
|
||||
owner=owner)
|
||||
contentblocks_by_merged_objectives_ids[merged_objectives_ids] = custom_content_block
|
||||
create_text_in_content_block(merged_objectives, custom_content_block)
|
||||
createed_content_blocks += 1
|
||||
else:
|
||||
print(f" Objective: Reuse content block")
|
||||
|
||||
# set visibility
|
||||
current_content_block = contentblocks_by_merged_objectives_ids[merged_objectives_ids]
|
||||
current_content_block.visible_for.add(school_class)
|
||||
# hide default objectives content if custom content exists
|
||||
if custom_content_block:
|
||||
default_content_block.hidden_for.add(school_class)
|
||||
|
||||
|
||||
|
||||
|
||||
print(f"Created {createed_content_blocks} content blocks")
|
||||
|
||||
|
||||
def create_default_content(objective_group, chapter):
|
||||
|
|
@ -103,6 +109,7 @@ def get_objectives_by_owner(objective_group):
|
|||
|
||||
return custom_objectives_by_owner
|
||||
|
||||
|
||||
def create_chapter_from_objective_group(module):
|
||||
chapter = Chapter(title=f"XXX Lernziele")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue