Skip to content

Commit

Permalink
Fixes #6027 - Removes prevent_descendant_update flag (#6043)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteinRobert authored and czpython committed Aug 15, 2017
1 parent 3fe2140 commit fbd21da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -13,6 +13,7 @@
* Fixed a regression where the code following a ``{% placeholder x or %}`` declaration,
was rendered before attempting to inherit content from parent pages.
* Changed page/placeholder cache keys to use sha1 hash instead of md5 to be FIPS compliant.
* Fixed a bug where the change of a slug would not propagate to all descendant pages


=== 3.4.4 (unreleased) ===
Expand Down
6 changes: 1 addition & 5 deletions cms/signals/title.py
Expand Up @@ -51,8 +51,7 @@ def pre_save_title(instance, raw, **kwargs):

def post_save_title(instance, raw, created, **kwargs):
# Update descendants only if path changed
prevent_descendants = hasattr(instance, 'tmp_prevent_descendant_update')
if instance.path != getattr(instance, 'tmp_path', None) and not prevent_descendants:
if instance.path != getattr(instance, 'tmp_path', None):
child_titles = Title.objects.filter(
page__depth=instance.page.depth + 1,
page__path__range=Page._get_children_path_interval(instance.page.path),
Expand All @@ -62,14 +61,11 @@ def post_save_title(instance, raw, created, **kwargs):

for child_title in child_titles:
child_title.path = '' # just reset path
child_title.tmp_prevent_descendant_update = True
child_title._publisher_keep_state = True
child_title.save()
# remove temporary attributes
if hasattr(instance, 'tmp_path'):
del instance.tmp_path
if prevent_descendants:
del instance.tmp_prevent_descendant_update
apphook_post_title_checker(instance, **kwargs)


Expand Down
26 changes: 26 additions & 0 deletions cms/tests/test_page.py
Expand Up @@ -1065,6 +1065,32 @@ def test_rename_node(self):
self.assertEqual(child.get_absolute_url(language='en'), '/en/father/child/')
self.assertEqual(child.publisher_public.get_absolute_url(language='en'), '/en/father/child/')

def test_rename_node_alters_descendants(self):
create_page('grandpa', 'nav_playground.html', 'en', slug='home', published=True)
parent = create_page('parent', 'nav_playground.html', 'en', slug='parent', published=True)
child = create_page('child', 'nav_playground.html', 'en', slug='child', published=True, parent=parent)
grandchild_1 = create_page('grandchild-1', 'nav_playground.html', 'en', slug='grandchild-1', published=True,
parent=child)
grandchild_2 = create_page('grandchild-2', 'nav_playground.html', 'en', slug='grandchild-2', published=True,
parent=child.reload())
grandchild_3 = create_page('grandchild-3', 'nav_playground.html', 'en', slug='grandchild-3', published=True,
parent=child.reload())

page_title = Title.objects.get(page=parent)
page_title.slug = "father"
page_title.save()

# Draft pages
self.assertEqual(grandchild_1.get_absolute_url(language='en'), '/en/father/child/grandchild-1/')
self.assertEqual(grandchild_2.get_absolute_url(language='en'), '/en/father/child/grandchild-2/')
self.assertEqual(grandchild_3.get_absolute_url(language='en'), '/en/father/child/grandchild-3/')

parent.reload().publish('en')

# Public pages
self.assertEqual(grandchild_1.publisher_public.get_absolute_url(language='en'), '/en/father/child/grandchild-1/')
self.assertEqual(grandchild_2.publisher_public.get_absolute_url(language='en'), '/en/father/child/grandchild-2/')
self.assertEqual(grandchild_3.publisher_public.get_absolute_url(language='en'), '/en/father/child/grandchild-3/')

def test_move_node(self):
home = create_page('grandpa', 'nav_playground.html', 'en', slug='home', published=True)
Expand Down

0 comments on commit fbd21da

Please sign in to comment.