Add a log action for copy_for_translation operation ()

Currently, when a user copies a page for translation, the 'copy' log action is used.

This adds a more specific 'copy_for_translation' operation to be used instead when the user is translating.
pull/7359/head
Karl Hobley 2021-07-20 18:14:29 +01:00 zatwierdzone przez Matt Westcott
rodzic 07e03bc683
commit bea17ac8b6
6 zmienionych plików z 38 dodań i 2 usunięć

Wyświetl plik

@ -5,6 +5,7 @@ Changelog
~~~~~~~~~~~~~~~~~
* Support `min_num` / `max_num` options on ListBlock (Matt Westcott)
* Added a distinct `wagtail.copy_for_translation` log action type (Karl Hobley)
* Fix: Delete button is now correct colour on snippets and modeladmin listings (Brandon Murch)

Wyświetl plik

@ -71,6 +71,7 @@ Action Notes
``wagtail.rename`` A page was renamed
``wagtail.revert`` The page was reverted to a previous draft
``wagtail.copy`` The page was copied to a new location
``wagtail.copy_for_translation`` The page was copied into a new locale for translation
``wagtail.move`` The page was moved to a new location
``wagtail.reorder`` The order of the page under it's parent was changed
``wagtail.view_restriction.create`` The page was restricted

Wyświetl plik

@ -16,6 +16,7 @@ Other features
~~~~~~~~~~~~~~
* Support ``min_num`` / ``max_num`` options on ListBlock (Matt Westcott)
* Added a distinct ``wagtail.copy_for_translation`` log action type (Karl Hobley)
Bug fixes
~~~~~~~~~

Wyświetl plik

@ -1681,11 +1681,19 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
data={
'page': {
'id': page_copy.id,
'title': page_copy.get_admin_display_title()
'title': page_copy.get_admin_display_title(),
'locale': {
'id': page_copy.locale_id,
'language_code': page_copy.locale.language_code
}
},
'source': {'id': parent.id, 'title': parent.specific_deferred.get_admin_display_title()} if parent else None,
'destination': {'id': to.id, 'title': to.specific_deferred.get_admin_display_title()} if to else None,
'keep_live': page_copy.live and keep_live
'keep_live': page_copy.live and keep_live,
'source_locale': {
'id': self.locale_id,
'language_code': self.locale.language_code
}
},
)
if page_copy.live and keep_live:
@ -1942,6 +1950,7 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
reset_translation_key=False,
process_child_object=process_child_object,
exclude_fields=exclude_fields,
log_action='wagtail.copy_for_translation',
)
copy_for_translation.alters_data = True

Wyświetl plik

@ -18,6 +18,7 @@ from django.test.utils import override_settings
from django.utils import timezone, translation
from freezegun import freeze_time
from wagtail.core.log_actions import page_log_action_registry
from wagtail.core.models import (
Comment, Locale, Page, PageLogEntry, PageManager, ParentNotTranslatedError, Site,
get_page_models, get_translatable_models)
@ -2225,6 +2226,12 @@ class TestCopyForTranslation(TestCase):
self.assertFalse(fr_homepage.live)
self.assertTrue(fr_homepage.has_unpublished_changes)
# Check log
log_entry = PageLogEntry.objects.get(action='wagtail.copy_for_translation')
self.assertEqual(log_entry.data['source_locale']['language_code'], 'en')
self.assertEqual(log_entry.data['page']['locale']['language_code'], 'fr')
self.assertEqual(page_log_action_registry.format_message(log_entry), "Copied for translation from Root (English)")
def test_copy_homepage_slug_exists(self):
# This test is the same as test_copy_homepage, but we will create another page with
# the slug "home-fr" before translating. copy_for_translation should pick a different slug
@ -2254,6 +2261,12 @@ class TestCopyForTranslation(TestCase):
# The slug should be the same when copying to another tree
self.assertEqual(self.en_eventindex.slug, fr_eventindex.slug)
# Check log
log_entry = PageLogEntry.objects.get(action='wagtail.copy_for_translation')
self.assertEqual(log_entry.data['source_locale']['language_code'], 'en')
self.assertEqual(log_entry.data['page']['locale']['language_code'], 'fr')
self.assertEqual(page_log_action_registry.format_message(log_entry), "Copied for translation from Welcome to the Wagtail test site! (English)")
def test_copy_childpage_without_parent(self):
# This test is the same as test_copy_childpage but we won't create the parent page first

Wyświetl plik

@ -9,6 +9,7 @@ from django.utils.translation import ngettext
from wagtail.core import hooks
from wagtail.core.models import PageViewRestriction
from wagtail.core.rich_text.pages import PageLinkHandler
from wagtail.core.utils import get_content_languages
def require_wagtail_login(next):
@ -127,6 +128,15 @@ def register_core_log_actions(actions):
except KeyError:
return _("Copied")
def copy_for_translation_message(data):
try:
return _('Copied for translation from %(title)s (%(locale)s)') % {
'title': data['source']['title'],
'locale': get_content_languages().get(data['source_locale']['language_code']) or '',
}
except KeyError:
return _("Copied for translation")
def create_alias_message(data):
try:
return _('Created an alias of %(title)s') % {
@ -312,6 +322,7 @@ def register_core_log_actions(actions):
actions.register_action('wagtail.rename', _('Rename'), rename_message)
actions.register_action('wagtail.revert', _('Revert'), revert_message)
actions.register_action('wagtail.copy', _('Copy'), copy_message)
actions.register_action('wagtail.copy_for_translation', _('Copy for translation'), copy_for_translation_message)
actions.register_action('wagtail.create_alias', _('Create alias'), create_alias_message)
actions.register_action('wagtail.convert_alias', _('Convert alias into ordinary page'), convert_alias_message)
actions.register_action('wagtail.move', _('Move'), move_message)