8000 Fixed #6151 -- Pages can be copied as the first child of a parent page by czpython · Pull Request #6152 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixed #6151 -- Pages can be copied as the first child of a parent page #6152

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 21, 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 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed #6151 -- Pages can be copied as the first child of a parent page
  • Loading branch information
czpython committed Nov 21, 2017
commit cb1d7c1e7d31437ae0f7fce42d773c4cbf888861
6 changes: 6 additions & 0 deletions cms/models/pagemodel.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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