diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ecffacd004..8e2e8db443 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -14,6 +14,7 @@ Changelog * Fix: Preserve whitespace in rendered comments (Elhussein Almasri) * Fix: Remove search logging from project template so that new projects without the search promotions module will not error (Matt Westcott) * Fix: Ensure text only email notifications for updated comments do not escape HTML characters (Rohit Sharma) + * Fix: Use the latest draft when copying an unpublished page for translation (Andrey Nehaychik) * Docs: Document, for contributors, the use of translate string literals passed as arguments to tags and filters using `_()` within templates (Chiemezuo Akujobi) * Maintenance: Update BeautifulSoup upper bound to 4.12.x (scott-8) * Maintenance: Migrate initialization of classes (such as `body.ready`) from multiple JavaScript implementations to one Stimulus controller `w-init` (Chiemezuo Akujobi) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7d6a6c5888..ffd1d660b9 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -764,6 +764,7 @@ * Cameron Lamb * Sam Dudley * Varun Kumar +* Andrey Nehaychik ## Translators diff --git a/docs/releases/6.0.md b/docs/releases/6.0.md index 6aa0730b12..d713c4d286 100644 --- a/docs/releases/6.0.md +++ b/docs/releases/6.0.md @@ -27,6 +27,7 @@ depth: 1 * Preserve whitespace in rendered comments (Elhussein Almasri) * Remove search logging from project template so that new projects without the search promotions module will not error (Matt Westcott) * Ensure text only email notifications for updated comments do not escape HTML characters (Rohit Sharma) + * Use the latest draft when copying an unpublished page for translation (Andrey Nehaychik) ### Documentation diff --git a/wagtail/actions/copy_for_translation.py b/wagtail/actions/copy_for_translation.py index 6d147b1b22..0c1c41b06e 100644 --- a/wagtail/actions/copy_for_translation.py +++ b/wagtail/actions/copy_for_translation.py @@ -80,7 +80,9 @@ class CopyPageForTranslationAction: def walk(self, current_page): for child_page in current_page.get_children(): self._copy_for_translation( - child_page, + child_page + if child_page.live + else child_page.get_latest_revision_as_object(), self.locale, self.copy_parents, self.alias, @@ -151,7 +153,11 @@ class CopyPageForTranslationAction: self.check(skip_permission_checks=skip_permission_checks) translated_page = self._copy_for_translation( - self.page, self.locale, self.copy_parents, self.alias, self.exclude_fields + self.page if self.page.live else self.page.get_latest_revision_as_object(), + self.locale, + self.copy_parents, + self.alias, + self.exclude_fields, ) if self.include_subtree: diff --git a/wagtail/admin/tests/api/test_pages.py b/wagtail/admin/tests/api/test_pages.py index ba91a1af33..0d9affc775 100644 --- a/wagtail/admin/tests/api/test_pages.py +++ b/wagtail/admin/tests/api/test_pages.py @@ -17,6 +17,7 @@ from wagtail.api.v2.tests.test_pages import ( ) from wagtail.models import GroupPagePermission, Locale, Page, PageLogEntry from wagtail.test.demosite import models +from wagtail.test.i18n.models import TestPage from wagtail.test.testapp.models import ( EventIndex, EventPage, @@ -1775,6 +1776,76 @@ class TestCopyForTranslationAction(AdminAPITestCase, TestCase): content = json.loads(response.content.decode("utf-8")) self.assertEqual(content, {"message": "No Locale matches the given query."}) + def test_translating_latest_non_draft_page_revision(self): + old_index_title = self.en_eventindex.title + old_post_title = self.en_eventpage.title + new_index_title = old_index_title + "-77777" + new_post_title = old_post_title + "-77777" + self.en_eventindex.title = new_index_title + self.en_eventindex.save_revision(log_action=True) + self.en_eventpage.title = new_post_title + self.en_eventpage.save_revision(log_action=True) + + response = self.get_response( + self.en_eventindex.id, + {"locale": "fr", "copy_parents": True, "recursive": True}, + ) + + assert response.status_code == 201 + + new_index_page = [ + trans_page + for trans_page in self.en_eventindex.get_translations() + if trans_page.locale.language_code == "fr" + ][0] + assert new_index_page.title == old_index_title + new_post_page = [ + trans_page + for trans_page in self.en_eventpage.get_translations() + if trans_page.locale.language_code == "fr" + ][0] + assert new_post_page.title == old_post_title + + def test_translating_latest_draft_page_revision(self): + """In case when Page have only draft revisions""" + + draft_index_page = TestPage(title="Draft Blog", slug="draft_blog", live=False) + self.en_homepage.add_child(instance=draft_index_page) + draft_blog_post = TestPage( + title="Draft Blog post", slug="draft_blog-post", live=False + ) + draft_index_page.add_child(instance=draft_blog_post) + + old_index_title = draft_index_page.title + new_index_title = old_index_title + "-77777" + draft_index_page.title = new_index_title + draft_index_page.save_revision(log_action=True) + + old_page_title = draft_blog_post.title + new_page_title = old_page_title + "-77777" + draft_blog_post.title = new_page_title + draft_blog_post.save_revision(log_action=True) + + response = self.get_response( + draft_index_page.id, + {"locale": "fr", "copy_parents": True, "recursive": True}, + ) + + assert response.status_code == 201 + + new_index_page = [ + trans_page + for trans_page in draft_index_page.get_translations() + if trans_page.locale.language_code == "fr" + ][0] + assert new_index_page.title == new_index_title + new_post_page = [ + trans_page + for trans_page in draft_blog_post.get_translations() + if trans_page.locale.language_code == "fr" + ][0] + assert new_post_page.title == new_page_title + class TestCreatePageAliasAction(AdminAPITestCase, TestCase): fixtures = ["test.json"]