From f5080eca1eb2db18ac98c1fbb0962f0cbad1a8de Mon Sep 17 00:00:00 2001 From: Matt Linares Date: Wed, 23 Nov 2022 13:48:50 +0000 Subject: [PATCH 1/3] Enable setting to create draft, not live, pages on translation. --- docs/how-to/installation.md | 8 ++++++++ wagtail_localize/operations.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/how-to/installation.md b/docs/how-to/installation.md index 48d5f4a4..4019f789 100644 --- a/docs/how-to/installation.md +++ b/docs/how-to/installation.md @@ -54,6 +54,14 @@ class MyPage(Page): # ... ``` + +## Disabling default publication of tranlsated pages + +Live pages that are submitted for translation are made live immediately. If you wish pages to stay in draft form at that point, set `WAGTAIL_LOCALIZE_PUBLISH_TRANSLATIONS_OF_LIVE_PAGES = False` in your settings file. + + + + ## Control translation cleanup mode diff --git a/wagtail_localize/operations.py b/wagtail_localize/operations.py index ef77b4b9..ee495115 100644 --- a/wagtail_localize/operations.py +++ b/wagtail_localize/operations.py @@ -73,7 +73,11 @@ def create_translations(self, instance, include_related_objects=True): self.mappings[source].append(translation) # Determine whether or not to publish the translation. - publish = getattr(instance, "live", True) + publish_on_translate_setting = getattr(settings, "WAGTAIL_LOCALIZE_PUBLISH_TRANSLATIONS_OF_LIVE_PAGES", True) + if publish_on_translate_setting == True: + publish = getattr(instance, "live", True) + else: + publish = False try: translation.save_target(user=self.user, publish=publish) From 0fbd6ea1b3f8589b1f2c00180014a3a48b8db3d8 Mon Sep 17 00:00:00 2001 From: Matt Linares Date: Wed, 23 Nov 2022 14:53:48 +0000 Subject: [PATCH 2/3] Change new setting name to WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE --- docs/how-to/installation.md | 2 +- wagtail_localize/operations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/how-to/installation.md b/docs/how-to/installation.md index 4019f789..0a32aece 100644 --- a/docs/how-to/installation.md +++ b/docs/how-to/installation.md @@ -57,7 +57,7 @@ class MyPage(Page): ## Disabling default publication of tranlsated pages -Live pages that are submitted for translation are made live immediately. If you wish pages to stay in draft form at that point, set `WAGTAIL_LOCALIZE_PUBLISH_TRANSLATIONS_OF_LIVE_PAGES = False` in your settings file. +Live pages that are submitted for translation are made live immediately. If you wish pages to stay in draft form at that point, set `WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE = False` in your settings file. diff --git a/wagtail_localize/operations.py b/wagtail_localize/operations.py index ee495115..a5c5dd4a 100644 --- a/wagtail_localize/operations.py +++ b/wagtail_localize/operations.py @@ -73,7 +73,7 @@ def create_translations(self, instance, include_related_objects=True): self.mappings[source].append(translation) # Determine whether or not to publish the translation. - publish_on_translate_setting = getattr(settings, "WAGTAIL_LOCALIZE_PUBLISH_TRANSLATIONS_OF_LIVE_PAGES", True) + publish_on_translate_setting = getattr(settings, "WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE", True) if publish_on_translate_setting == True: publish = getattr(instance, "live", True) else: From a606f594261f8bd0980c1f040813397d5dc26c8e Mon Sep 17 00:00:00 2001 From: Matt Linares Date: Wed, 4 Jan 2023 10:46:43 +0000 Subject: [PATCH 3/3] Add test for draft publication of translations setting. --- .../tests/test_submit_translations.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wagtail_localize/tests/test_submit_translations.py b/wagtail_localize/tests/test_submit_translations.py index 981bce88..c07a431b 100644 --- a/wagtail_localize/tests/test_submit_translations.py +++ b/wagtail_localize/tests/test_submit_translations.py @@ -246,6 +246,25 @@ def test_post_submit_page_translation(self): response, reverse("wagtailadmin_pages:edit", args=[translated_page.id]) ) + @override_settings(WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE=False) + def test_post_submit_page_translation_draft(self): + response = self.client.post( + reverse( + "wagtail_localize:submit_page_translation", + args=[self.en_blog_index.id], + ), + {"locales": [self.fr_locale.id]}, + ) + + translation = Translation.objects.get() + self.assertEqual(translation.source.locale, self.en_locale) + self.assertEqual(translation.target_locale, self.fr_locale) + self.assertTrue(translation.created_at) + + # The translated page should've been created and published + translated_page = self.en_blog_index.get_translation(self.fr_locale) + self.assertFalse(translated_page.live) + def test_post_submit_page_translation_submits_linked_snippets(self): self.en_blog_index.test_snippet = TestSnippet.objects.create( field="My test snippet"