8000 Fixed #6131 -- Pages can be copied into any position on the page tree by czpython · Pull Request #6133 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixed #6131 -- Pages can be copied into any position on the page tree #6133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,14 @@ def copy_with_descendants(self, site, target_node=None, position=None,
# Otherwise, if the page is copied and pasted on itself, it will duplicate.
descendants = list(node.get_descendants().prefetch_related('page__title_set'))
new_root_page = self.copy(target_site, parent_node=parent_node)
nodes_by_id = {node.pk: new_root_page.get_node_object(target_site)}
new_root_node = new_root_page.get_node_object(target_site)

if target_node and position in ('left', 'last-child'):
# target node is a sibling
new_root_node.move(target_node, position)
new_root_node.refresh_from_db(fields=('path', 'depth'))

nodes_by_id = {node.pk: new_root_node}

for node in descendants:
parent = nodes_by_id[node.parent_id]
Expand Down
61 changes: 61 additions & 0 deletions cms/tests/test_page_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,67 @@ def test_copy_page(self):

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

def test_copy_page_to_explicit_position(self):
"""
User should be able to copy a single page and paste it
in a specific location on another page tree.
"""
superuser = self.get_superuser()
parent = create_page("parent", "nav_playground.html", "en", published=True)
child_0001 = create_page("child-0001", "nav_playground.html", "en", published=True, parent=parent)
child_0002 = create_page("child-0002", "nav_playground.html", "en", published=True, parent=parent)
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True, parent=parent)
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True)

with self.login_user_context(superuser):
child_0003 = self.copy_page(child_0003, parent, position=2)

tree = (
(parent, '0001'),
(child_0001, '00010001'),
(child_0002, '00010002'),
(child_0003, '00010003'),
(child_0004, '00010004'),
)

for page, path in tree:
self.assertEqual(self.reload(page.node).path, path)

def test_copy_page_tree_to_explicit_position(self):
"""
User should be able to copy a page with descendants and paste it
in a specific location on another page tree.
"""
superuser = self.get_superuser()
parent = create_page("parent", "nav_playground.html", "en", published=True)
child_0001 = create_page("child-0001", "nav_playground.html", "en", published=True, parent=parent)
child_0002 = create_page("child-0002", "nav_playground.html", "en", published=True, parent=parent)
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True, parent=parent)
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True)
create_page("child-00030001", "nav_playground.html", "en", published=True, parent=child_0003)
create_page("child-00030002", "nav_playground.html", "en", published=True, parent=child_0003)
create_page("child-00030003", "nav_playground.html", "en", published=True, parent=child_0003)

with self.login_user_context(superuser):
child_0003 = self.copy_page(child_0003, parent, position=2)
child_00030001 = child_0003.node.get_children()[0].page
child_00030002 = child_0003.node.get_children()[1].page
child_00030003 = child_0003.node.get_children()[2].page

tree = (
(parent, '0001'),
(child_0001, '00010001'),
(child_0002, '00010002'),
(child_0003, '00010003'),
(child_00030001, '000100030001'),
(child_00030002, '000100030002'),
(child_00030003, '000100030003'),
(child_0004, '00010004'),
)

for page, path in tree:
self.assertEqual(self.reload(page.node).path, path)

def test_copy_self_page(self):
"""
Test that a page can be copied via the admin
Expand Down
0