kopia lustrzana https://github.com/wagtail/wagtail
Fix page copy in Wagtail admin ignores `exclude_fields_in_copy` (#8313)
Co-authored-by: John-Scott Atlakson <john-scott@greenlightgo.co>pull/8320/head
rodzic
947e254cc8
commit
491449ed4f
|
@ -9,6 +9,7 @@ Changelog
|
|||
* Fix: Allow bulk publishing of pages without revisions (Andy Chosak)
|
||||
* Fix: Ensure that all descendant pages are logged when deleting a page, not just immediate children (Jake Howard)
|
||||
* Fix: Refactor `FormPagesListView` in wagtail.contrib.forms to avoid undefined `locale` variable when subclassing (Dan Braghis)
|
||||
* Fix: page copy in Wagtail admin ignores `exclude_fields_in_copy` (John-Scott Atlakson)
|
||||
|
||||
|
||||
2.16.1 (11.02.2022)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* Allow bulk publishing of pages without revisions (Andy Chosak)
|
||||
* Ensure that all descendant pages are logged when deleting a page, not just immediate children (Jake Howard)
|
||||
* Refactor `FormPagesListView` in wagtail.contrib.forms to avoid undefined `locale` variable when subclassing (Dan Braghis)
|
||||
* Ensure page copy in Wagtail admin doesn't ignore `exclude_fields_in_copy` (John-Scott Atlakson)
|
||||
|
||||
## Upgrade considerations
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ from wagtail.api.v2.tests.test_pages import TestPageDetail, TestPageListing
|
|||
from wagtail.core import hooks
|
||||
from wagtail.core.models import GroupPagePermission, Locale, Page, PageLogEntry
|
||||
from wagtail.tests.demosite import models
|
||||
from wagtail.tests.testapp.models import EventIndex, EventPage, SimplePage, StreamPage
|
||||
from wagtail.tests.testapp.models import (
|
||||
EventIndex, EventPage, PageWithExcludedCopyField, SimplePage, StreamPage)
|
||||
from wagtail.users.models import UserProfile
|
||||
|
||||
from .utils import AdminAPITestCase
|
||||
|
@ -880,6 +881,20 @@ class TestCopyPageAction(AdminAPITestCase):
|
|||
new_page = Page.objects.get(id=content['id'])
|
||||
self.assertEqual(new_page.slug, 'new-slug')
|
||||
|
||||
def test_copy_page_with_exclude_fields_in_copy(self):
|
||||
response = self.get_response(21, {})
|
||||
|
||||
self.assertEqual(response.status_code, 201)
|
||||
content = json.loads(response.content.decode("utf-8"))
|
||||
|
||||
original_page = PageWithExcludedCopyField.objects.get(pk=21)
|
||||
new_page = PageWithExcludedCopyField.objects.get(id=content["id"])
|
||||
self.assertEqual(new_page.content, original_page.content)
|
||||
self.assertNotEqual(new_page.special_field, original_page.special_field)
|
||||
self.assertEqual(
|
||||
new_page.special_field, new_page._meta.get_field("special_field").default
|
||||
)
|
||||
|
||||
def test_copy_page_destination(self):
|
||||
response = self.get_response(3, {
|
||||
'destination_page_id': 3
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
|
||||
from wagtail.core.models import GroupPagePermission, Page
|
||||
from wagtail.tests.testapp.models import SimplePage
|
||||
from wagtail.tests.testapp.models import PageWithExcludedCopyField, SimplePage
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
|
@ -587,3 +587,33 @@ class TestPageCopy(TestCase, WagtailTestUtils):
|
|||
|
||||
# We only need to check that it didn't crash
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
def test_page_with_exclude_fields_in_copy(self):
|
||||
original_page = self.test_page.add_child(
|
||||
instance=PageWithExcludedCopyField(
|
||||
title="Page with exclude_fields_in_copy",
|
||||
slug="page-with-exclude-fields-in-copy",
|
||||
content="Copy me",
|
||||
special_field="Don't copy me",
|
||||
live=True,
|
||||
has_unpublished_changes=False,
|
||||
)
|
||||
)
|
||||
post_data = {
|
||||
"new_title": f"{original_page.title} 2",
|
||||
"new_slug": f"{original_page.slug}-2",
|
||||
"new_parent_page": str(self.root_page.id),
|
||||
"copy_subpages": False,
|
||||
"publish_copies": False,
|
||||
"alias": False,
|
||||
}
|
||||
self.client.post(
|
||||
reverse("wagtailadmin_pages:copy", args=(original_page.id,)), post_data
|
||||
)
|
||||
# Get copy
|
||||
page_copy = PageWithExcludedCopyField.objects.get(slug=post_data["new_slug"])
|
||||
self.assertEqual(page_copy.content, original_page.content)
|
||||
self.assertNotEqual(page_copy.special_field, original_page.special_field)
|
||||
self.assertEqual(
|
||||
page_copy.special_field, page_copy._meta.get_field("special_field").default
|
||||
)
|
||||
|
|
|
@ -73,8 +73,12 @@ class CopyPageAction:
|
|||
raise CopyPagePermissionError("You do not have permission to publish a page at the destination")
|
||||
|
||||
def _copy_page(self, page, to=None, update_attrs=None, exclude_fields=None, _mpnode_attrs=None):
|
||||
exclude_fields = page.default_exclude_fields_in_copy + page.exclude_fields_in_copy + (exclude_fields or [])
|
||||
specific_page = page.specific
|
||||
exclude_fields = (
|
||||
specific_page.default_exclude_fields_in_copy
|
||||
+ specific_page.exclude_fields_in_copy
|
||||
+ (exclude_fields or [])
|
||||
)
|
||||
if self.keep_live:
|
||||
base_update_attrs = {
|
||||
'alias_of': None,
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"fields": {
|
||||
"title": "Welcome to the Wagtail test site!",
|
||||
"draft_title": "Welcome to the Wagtail test site!",
|
||||
"numchild": 9,
|
||||
"numchild": 10,
|
||||
"show_in_menus": false,
|
||||
"live": true,
|
||||
"depth": 2,
|
||||
|
@ -616,7 +616,30 @@
|
|||
"slug": "does-not-exist"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pk": 21,
|
||||
"model": "wagtailcore.page",
|
||||
"fields": {
|
||||
"title": "This page has a field that shouldn't be copied",
|
||||
"draft_title": "This page has a field that shouldn't be copied",
|
||||
"numchild": 0,
|
||||
"show_in_menus": true,
|
||||
"live": true,
|
||||
"depth": 3,
|
||||
"content_type": ["tests", "pagewithexcludedcopyfield"],
|
||||
"path": "000100010010",
|
||||
"url_path": "/home/page-with-exclude-fields-in-copy/",
|
||||
"slug": "page-with-exclude-fields-in-copy"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 21,
|
||||
"model": "tests.pagewithexcludedcopyfield",
|
||||
"fields": {
|
||||
"content": "Copy me.",
|
||||
"special_field": "Don't copy me."
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "wagtailcore.site",
|
||||
|
|
Ładowanie…
Reference in New Issue