Use the latest draft when copying an unpublished page for translation (#7755)

Fixes #7754

Co-authored-by: Andrey Nehaychik <andrey.nehaychik@vizor-games.com>
pull/11097/head
Matt Westcott 2023-11-08 18:31:20 +00:00
rodzic 582fe12749
commit 32c48e149d
5 zmienionych plików z 82 dodań i 2 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -764,6 +764,7 @@
* Cameron Lamb
* Sam Dudley
* Varun Kumar
* Andrey Nehaychik
## Translators

Wyświetl plik

@ -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

Wyświetl plik

@ -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:

Wyświetl plik

@ -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"]