Fix visibiility of custom and default objectives

This commit is contained in:
Lorenz Padberg 2024-01-29 17:17:52 +01:00
parent 9f16573b92
commit eef536b801
1 changed files with 24 additions and 27 deletions

View File

@ -64,46 +64,42 @@ class Command(BaseCommand):
merged_objectives = visible_default_objectives_by_class[school_class] + owner_objectives
merged_objectives_ids = tuple(objective.id for objective in merged_objectives)
if merged_objectives_ids == default_objectives_ids:
print(f" Objective: Reuse default content block")
# custom_content_block = default_content_block
# Create content block if that set of objectives has not been created yet
if merged_objectives_ids not in contentblocks_by_merged_objectives_ids:
if merged_objectives_ids not in contentblocks_by_merged_objectives_ids and merged_objectives_ids != default_objectives_ids:
for objective in merged_objectives:
print(f" Objective: {objective} {objective.owner}")
if merged_objectives_ids:
custom_content_block = create_content_block_from_objective(objective_group, chapter,
owner=owner, prefix=f"CUSTOM {owner.username} ")
contentblocks_by_merged_objectives_ids[merged_objectives_ids] = custom_content_block
custom_content_block = create_content_block_from_objective(objective_group,
chapter,
owner=owner,
prefix=f"CUSTOM {owner.username} ")
contentblocks_by_merged_objectives_ids[
merged_objectives_ids] = custom_content_block
create_text_in_content_block(merged_objectives, custom_content_block)
created_content_blocks += 1
else:
print(f" Objective: Reuse content block")
custom_content_block = contentblocks_by_merged_objectives_ids[merged_objectives_ids]
if merged_objectives_ids != default_objectives_ids:
print(f" Objective: Reuse content block")
custom_content_block = contentblocks_by_merged_objectives_ids[
merged_objectives_ids]
else:
print(f" Objective: Reuse default content block")
# set visibility
# hide default objectives if custom objectives exist
current_block = contentblocks_by_merged_objectives_ids.get(merged_objectives_ids)
if current_block:
# default_content_block.hidden_for.add(school_class)
# default_content_block.save_revision().publish()
# default_content_block.save()
# created_default_content_blocks[default_objectives_ids] = default_content_block
pass
current_block.visible_for.add(school_class)
current_block.save_revision().publish()
current_block.save()
if custom_content_block:
pass
# default_content_block.hidden_for.add(school_class)
# default_content_block.save()
#
# custom_content_block.visible_for.add(school_class)
# custom_content_block.save()
default_content_block.hidden_for.add(school_class)
default_content_block.save_revision().publish()
default_content_block.save()
custom_content_block.visible_for.add(school_class)
custom_content_block.save_revision().publish()
custom_content_block.save()
except ValidationError as e:
@ -123,7 +119,8 @@ def create_default_content(objective_group, chapter):
print(f" Objective group: {objective_group}")
print(" Default objectives:")
default_objectives = list(objective_group.objectives.filter(owner__isnull=True, objectivesnapshot__isnull=True).order_by('id'))
default_objectives = list(
objective_group.objectives.filter(owner__isnull=True, objectivesnapshot__isnull=True).order_by('id'))
default_content_block = create_content_block_from_objective(objective_group, chapter, prefix="XXX YYY ")
create_text_in_content_block(default_objectives, default_content_block)