Skip to content

Commit

Permalink
Add setting to cascade actions
Browse files Browse the repository at this point in the history
currently: delete, move, unpublish
  • Loading branch information
zerolab committed May 20, 2022
1 parent dfb3665 commit 23b2d72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 24 additions & 1 deletion wagtail_localize/tests/test_synctree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.core.models import Locale, Page
Expand Down Expand Up @@ -307,6 +307,27 @@ def test_hook_returns_nothing_without_locale_synchronisation(self):
results = hook([self.en_aboutpage], action)
self.assertDictEqual(results, {})

def test_hook_returns_nothing_without_explicit_setting(self):
self.setup_locale_synchronisation(self.fr_locale, self.en_locale)
hook = self._get_hook_function()
for action in ["unpublish", "delete", "move"]:
with self.subTest(
f"Calling construct_translated_pages_to_cascade_actions with {action} "
f"without WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS set"
):
results = hook([self.en_aboutpage], action)
self.assertDictEqual(results, {})

with override_settings(WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS=False):
for action in ["unpublish", "delete", "move"]:
with self.subTest(
f"Calling construct_translated_pages_to_cascade_actions with {action} "
f"and WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS=False"
):
results = hook([self.en_aboutpage], action)
self.assertDictEqual(results, {})

@override_settings(WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS=True)
def test_hook_returns_relevant_pages_from_synced_locale_on_unpublish_action(self):
self.setup_locale_synchronisation(self.fr_locale, self.en_locale)
hook = self._get_hook_function()
Expand All @@ -323,6 +344,7 @@ def test_hook_returns_relevant_pages_from_synced_locale_on_unpublish_action(self
self.assertIsNotNone(results.get(self.en_aboutpage))
self.assertQuerysetEqual(results[self.en_aboutpage], Page.objects.none())

@override_settings(WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS=True)
def test_hook_returns_relevant_pages_from_synced_locale_on_move_action(self):
self.setup_locale_synchronisation(self.fr_locale, self.en_locale)
hook = self._get_hook_function()
Expand All @@ -332,6 +354,7 @@ def test_hook_returns_relevant_pages_from_synced_locale_on_move_action(self):
results[self.en_aboutpage], Page.objects.filter(pk=self.fr_aboutpage.pk)
)

@override_settings(WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS=True)
def test_hook_returns_relevant_pages_from_synced_locale_on_delete_action(self):
self.setup_locale_synchronisation(self.fr_locale, self.en_locale)
hook = self._get_hook_function()
Expand Down
7 changes: 6 additions & 1 deletion wagtail_localize/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,15 @@ def register_icons(icons):


if WAGTAIL_VERSION >= (4, 0):
from django.conf import settings

from .models import LocaleSynchronization

@hooks.register("construct_translated_pages_to_cascade_actions")
def construct_synced_page_tree_list(pages: List[Page], action: str):
def construct_synced_page_tree_list(pages: List[Page], action: str) -> dict:
if not getattr(settings, "WAGTAILLOCALIZE_CASCADE_PAGE_ACTIONS", False):
return {}

locale_sync_map = {}
for page in pages:
# TODO: what about locale C follows B which follows A, when we come in from A?
Expand Down

0 comments on commit 23b2d72

Please sign in to comment.