Working. But too many content blocks... todo remove duplicates.
This commit is contained in:
parent
568564a64c
commit
2446b52596
|
|
@ -25,54 +25,83 @@ class Command(BaseCommand):
|
||||||
chapter = create_chapter_from_objective_group(module)
|
chapter = create_chapter_from_objective_group(module)
|
||||||
|
|
||||||
for objective_group in module.objective_groups.all():
|
for objective_group in module.objective_groups.all():
|
||||||
print(f" Objective group: {objective_group}")
|
default_content_block = create_default_content(objective_group, chapter)
|
||||||
print(" Default objectives:")
|
|
||||||
|
|
||||||
# create "Verlagsinhalt Lernziele"
|
|
||||||
|
|
||||||
default_objectives = objective_group.objectives.filter(owner__isnull=True)
|
|
||||||
|
|
||||||
default_content_block = create_content_block_from_objective(objective_group, chapter)
|
|
||||||
create_text_in_content_block(default_objectives, default_content_block)
|
|
||||||
|
|
||||||
for objective in default_objectives:
|
|
||||||
print(f" Objective: {objective} {objective.owner}")
|
|
||||||
|
|
||||||
# Create "Benutzerdefinierte Lernziele"
|
# Create "Benutzerdefinierte Lernziele"
|
||||||
custom_objectives = objective_group.objectives.filter(owner__isnull=False)
|
|
||||||
|
|
||||||
custom_objectives_by_owner = {}
|
custom_objectives_by_owner = get_objectives_by_owner(objective_group)
|
||||||
|
|
||||||
for objective in custom_objectives:
|
|
||||||
owner = objective.owner
|
|
||||||
owners_school_classes = owner.school_classes.all()
|
|
||||||
|
|
||||||
if owner not in custom_objectives_by_owner:
|
|
||||||
custom_objectives_by_owner[owner] = []
|
|
||||||
|
|
||||||
custom_objectives_by_owner[owner].append(objective)
|
|
||||||
|
|
||||||
for owner, owner_objectives in custom_objectives_by_owner.items():
|
for owner, owner_objectives in custom_objectives_by_owner.items():
|
||||||
print(f" Owner: {owner}")
|
print(f" Owner: {owner}")
|
||||||
print(f" Objectives: ")
|
print(f" Objectives: ")
|
||||||
default_objectives = objective_group.objectives.filter(owner__isnull=True)
|
|
||||||
owner_objectives.extend(default_objectives)
|
|
||||||
|
|
||||||
for objective in owner_objectives:
|
default_objectives = list(objective_group.objectives.filter(owner__isnull=True))
|
||||||
print(f" Objective: {objective} {objective.owner}")
|
|
||||||
#
|
|
||||||
custom_content_block = create_content_block_from_objective(objective_group, chapter, owner=owner)
|
|
||||||
create_text_in_content_block(owner_objectives, custom_content_block)
|
|
||||||
|
|
||||||
owners_school_classes = owner.school_classes.all()
|
visible_default_objectives_by_class = remove_hidden_objectives(default_objectives, owner)
|
||||||
for school_class in owners_school_classes:
|
|
||||||
custom_content_block.visible_for.add(school_class.id)
|
|
||||||
|
|
||||||
if objective.is_hidden_for_class(school_class):
|
for school_class in visible_default_objectives_by_class.keys():
|
||||||
custom_content_block.hidden_for.add(school_class.id)
|
print(f" School class: {school_class}")
|
||||||
|
school_class_objectives = visible_default_objectives_by_class[school_class] + owner_objectives
|
||||||
|
|
||||||
custom_content_block.save_revision().publish()
|
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)
|
||||||
|
|
||||||
|
if custom_content_block:
|
||||||
|
default_content_block.hidden_for.add(school_class)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_content(objective_group, chapter):
|
||||||
|
print(f" Objective group: {objective_group}")
|
||||||
|
print(" Default objectives:")
|
||||||
|
|
||||||
|
# create "Verlagsinhalt Lernziele"
|
||||||
|
|
||||||
|
default_objectives = objective_group.objectives.filter(owner__isnull=True)
|
||||||
|
|
||||||
|
default_content_block = create_content_block_from_objective(objective_group, chapter)
|
||||||
|
create_text_in_content_block(default_objectives, default_content_block)
|
||||||
|
|
||||||
|
for objective in default_objectives:
|
||||||
|
print(f" Objective: {objective} {objective.owner}")
|
||||||
|
|
||||||
|
return default_content_block
|
||||||
|
|
||||||
|
|
||||||
|
def remove_hidden_objectives(objectives, user):
|
||||||
|
school_classes = user.school_classes.all()
|
||||||
|
visible_objectives = {}
|
||||||
|
for school_class in school_classes:
|
||||||
|
if school_class not in visible_objectives:
|
||||||
|
visible_objectives[school_class] = []
|
||||||
|
objectives_vis = [objective for objective in objectives if not objective.is_hidden_for_class(school_class)]
|
||||||
|
visible_objectives[school_class].extend(objectives_vis)
|
||||||
|
return visible_objectives
|
||||||
|
|
||||||
|
|
||||||
|
def get_objectives_by_owner(objective_group):
|
||||||
|
custom_objectives = objective_group.objectives.filter(owner__isnull=False)
|
||||||
|
custom_objectives_by_owner = {}
|
||||||
|
|
||||||
|
for objective in custom_objectives:
|
||||||
|
owner = objective.owner
|
||||||
|
|
||||||
|
if owner not in custom_objectives_by_owner:
|
||||||
|
custom_objectives_by_owner[owner] = []
|
||||||
|
|
||||||
|
custom_objectives_by_owner[owner].append(objective)
|
||||||
|
|
||||||
|
return custom_objectives_by_owner
|
||||||
|
|
||||||
def create_chapter_from_objective_group(module):
|
def create_chapter_from_objective_group(module):
|
||||||
chapter = Chapter(title=f"XXX Lernziele")
|
chapter = Chapter(title=f"XXX Lernziele")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue