10000 Fixed #6131 -- Pages can be copied into any position in the page tree · django-cms/django-cms@d2f0004 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2f0004

Browse files
committed
Fixed #6131 -- Pages can be copied into any position in the page tree
1 parent 70b88a2 commit d2f0004

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

cms/models/pagemodel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,14 @@ def copy_with_descendants(self, site, target_node=None, position=None,
711711
# Otherwise, if the page is copied and pasted on itself, it will duplicate.
712712
descendants = list(node.get_descendants().prefetch_related('page__title_set'))
713713
new_root_page = self.copy(target_site, parent_node=parent_node)
714-
nodes_by_id = {node.pk: new_root_page.get_node_object(target_site)}
714+
new_root_node = new_root_page.get_node_object(target_site)
715+
716+
if target_node and position in ('left', 'last-child'):
717+
# target node is a sibling
718+
new_root_node.move(target_node, position)
719+
new_root_node.refresh_from_db(fields=('path', 'depth'))
720+
721+
nodes_by_id = {node.pk: new_root_node}
715722

716723
for node in descendants:
717724
parent = nodes_by_id[node.parent_id]

cms/tests/test_page_admin.py

Lines changed: 61 additions & 0 deletions
< 8000 td data-grid-cell-id="diff-4f8ee28fcf66d51c8ea90594450db4eaa52e069a2ad1786b5b66f8e6d36f899e-553-571-2" data-line-anchor="diff-4f8ee28fcf66d51c8ea90594450db4eaa52e069a2ad1786b5b66f8e6d36f899eR571" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
(child_0001, '00010001'),
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,67 @@ def test_copy_page(self):
551551

552552
self.assertEqual(Page.objects.drafts().count() - count, 3)
553553

554+
def test_copy_page_to_explicit_position(self):
555+
"""
556+
User should be able to copy a single page and paste it
557+
in a specific location on another page tree.
558+
"""
559+
superuser = self.get_superuser()
560+
parent = create_page("parent", "nav_playground.html", "en", published=True)
561+
child_0001 = create_page("child-0001", "nav_playground.html", "en", published=True, parent=parent)
562+
child_0002 = create_page("child-0002", "nav_playground.html", "en", published=True, parent=parent)
563+
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True, parent=parent)
564+
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True)
565+
566+
with self.login_user_context(superuser):
567+
child_0003 = self.copy_page(child_0003, parent, position=2)
568+
569+
tree = (
570+
(parent, '0001'),
571
572+
(child_0002, '00010002'),
573+
(child_0003, '00010003'),
574+
(child_0004, '00010004'),
575+
)
576+
577+
for page, path in tree:
578+
self.assertEqual(self.reload(page.node).path, path)
579+
580+
def test_copy_page_tree_to_explicit_position(self):
581+
"""
582+
User should be able to copy a page with descendants and paste it
583+
in a specific location on another page tree.
584+
"""
585+
superuser = self.get_superuser()
586+
parent = create_page("parent", "nav_playground.html", "en", published=True)
587+
child_0001 = create_page("child-0001", "nav_playground.html", "en", published=True, parent=parent)
588+
child_0002 = create_page("child-0002", "nav_playground.html", "en", published=True, parent=parent)
589+
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True, parent=parent)
590+
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True)
591+
create_page("child-00030001", "nav_playground.html", "en", published=True, parent=child_0003)
592+
create_page("child-00030002", "nav_playground.html", "en", published=True, parent=child_0003)
593+
create_page("child-00030003", "nav_playground.html", "en", published=True, parent=child_0003)
594+
595+
with self.login_user_context(superuser):
596+
child_0003 = self.copy_page(child_0003, parent, position=2)
597+
child_00030001 = child_0003.node.get_children()[0].page
598+
child_00030002 = child_0003.node.get_children()[1].page
599+
child_00030003 = child_0003.node.get_children()[2].page
600+
601+
tree = (
602+
(parent, '0001'),
603+
(child_0001, '00010001'),
604+
(child_0002, '00010002'),
605+
(child_0003, '00010003'),
606+
(child_00030001, '000100030001'),
607+
(child_00030002, '000100030002'),
608+
(child_00030003, '000100030003'),
609+
(child_0004, '00010004'),
610+
)
611+
612+
for page, path in tree:
613+
self.assertEqual(self.reload(page.node).path, path)
614+
554615
def test_copy_self_page(self):
555616
"""
556617
Test that a page can be copied via the admin

0 commit comments

Comments
 (0)
0