Skip to content

Commit

Permalink
Fixed #6151 -- Pages can be copied as the first child of a parent page (
Browse files Browse the repository at this point in the history
  • Loading branch information
czpython committed Nov 21, 2017
1 parent 9acbf6a commit d503b0f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cms/models/pagemodel.py
Expand Up @@ -711,6 +711,12 @@ def copy_with_descendants(self, site, target_node=None, position=None,
new_root_page = self.copy(target_site, parent_node=parent_node)
new_root_node = new_root_page.get_node_object(target_site)

if target_node and position in ('first-child'):
# target node is a parent and user has requested to
# insert the new page as its first child
new_root_node.move(target_node, position)
new_root_node.refresh_from_db(fields=('path', 'depth'))

if target_node and position in ('left', 'last-child'):
# target node is a sibling
new_root_node.move(target_node, position)
Expand Down
2 changes: 1 addition & 1 deletion cms/test_utils/testcases.py
Expand Up @@ -357,7 +357,7 @@ def copy_page(self, page, target_page, position=0):
Page.objects.all(),
pk=response_data['id'],
)
self.assertObjectExist(page.title_set.filter(language=language), slug=new_page_slug)
self.assertObjectExist(copied_page.title_set.filter(language=language), slug=new_page_slug)
page._clear_node_cache(page.site)
target_page._clear_node_cache(target_page.site)
return copied_page
Expand Down
55 changes: 38 additions & 17 deletions cms/tests/test_page_admin.py
Expand Up @@ -614,20 +614,26 @@ def test_copy_page_to_explicit_position(self):
"""
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)
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True, parent=parent)
child_0005 = create_page("child-0005", "nav_playground.html", "en", published=True, parent=parent)
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True)

with self.login_user_context(superuser):
child_0003 = self.copy_page(child_0003, parent, position=2)
# Copy the 0005 page and insert it as first child of parent
child_0001 = self.copy_page(child_0005, parent, position=0)

with self.login_user_context(superuser):
# Copy the 0004 page and insert it as fourth child of parent
child_0004 = self.copy_page(child_0004, parent, position=3)

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

for page, path in tree:
Expand All @@ -640,29 +646,44 @@ def test_copy_page_tree_to_explicit_position(self):
"""
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)
child_0003 = create_page("child-0003", "nav_playground.html", "en", published=True, parent=parent)
child_0005 = create_page("child-0005", "nav_playground.html", "en", published=True, parent=parent)
create_page("child-00050001", "nav_playground.html", "en", published=True, parent=child_0005)
create_page("child-00050002", "nav_playground.html", "en", published=True, parent=child_0005)
create_page("child-00050003", "nav_playground.html", "en", published=True, parent=child_0005)
child_0004 = create_page("child-0004", "nav_playground.html", "en", published=True)
create_page("child-00040001", "nav_playground.html", "en", published=True, parent=child_0004)
create_page("child-00040002", "nav_playground.html", "en", published=True, parent=child_0004)
create_page("child-00040003", "nav_playground.html", "en", published=True, parent=child_0004)

with self.login_user_context(superuser):
# Copy the 0005 page and insert it as first child of parent
child_0001 = self.copy_page(child_0005, parent, position=0)
child_00010001 = child_0001.node.get_children()[0].page
child_00010002 = child_0001.node.get_children()[1].page
child_00010003 = child_0001.node.get_children()[2].page

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
# Copy the 0004 page and insert it as fourth child of parent
child_0004 = self.copy_page(child_0004, parent, position=3)
child_00040001 = child_0004.node.get_children()[0].page
child_00040002 = child_0004.node.get_children()[1].page
child_00040003 = child_0004.node.get_children()[2].page

tree = (
(parent, '0001'),
(child_0001, '00010001'),
(child_00010001, '000100010001'),
(child_00010002, '000100010002'),
(child_00010003, '000100010003'),
(child_0002, '00010002'),
(child_0003, '00010003'),
(child_00030001, '000100030001'),
(child_00030002, '000100030002'),
(child_00030003, '000100030003'),
(child_0004, '00010004'),
(child_00040001, '000100040001'),
(child_00040002, '000100040002'),
(child_00040003, '000100040003'),
(child_0005, '00010005'),
)

for page, path in tree:
Expand Down

0 comments on commit d503b0f

Please sign in to comment.