Skip to content

Commit

Permalink
Fix copying of language tree nodes in the region form (#3203)
Browse files Browse the repository at this point in the history
When creating a new region which copies contents from another region
and only the root languages should be included, the `lft` and `rgt`
values of the new language node must be set to `1` and `2`, respectively.
Otherwise, it would behave as if it still contained child nodes.
  • Loading branch information
david-venhoff authored Nov 13, 2024
1 parent 2bcb475 commit b93c816
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion integreat_cms/cms/forms/regions/region_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def duplicate_language_tree(
" " if i == num_source_nodes - 1 else "│ "
)
if target_parent:
# If the target parent already exist, we inherit its tree id for all its sub nodes
# If the target parent already exists, we inherit its tree id for all its sub nodes
target_tree_id = target_parent.tree_id
else:
# If the language tree node is a root node, we need to assign a new tree id
Expand All @@ -724,6 +724,11 @@ def duplicate_language_tree(
target_node.tree_id = target_tree_id
# Delete the primary key to force an insert
target_node.pk = None
# Fix lft and rgt of the tree if the children of this node should not be cloned
# Otherwise, the tree structure will be inconsistent
if only_root:
target_node.lft = 1
target_node.rgt = 2
# Check if the resulting node is valid
target_node.full_clean()
# Save the duplicated node
Expand Down

0 comments on commit b93c816

Please sign in to comment.