kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Fix page copy in Wagtail admin ignores `exclude_fields_in_copy`
							rodzic
							
								
									5c31aad368
								
							
						
					
					
						commit
						38f2e0b5b5
					
				|  | @ -59,6 +59,7 @@ Changelog | |||
|  * Fix: Add missing `lang` attributes to `<html>` elements (James Ray) | ||||
|  * Fix: Avoid 503 server error when entering tags over 100chars and instead show a user facing validation error (Vu Pham, Khanh Hoang) | ||||
|  * Fix: Ensure `thumb_col_header_text` is correctly used by `ThumbnailMixin` within `ModelAdmin` as the column header label (Kyle J. Roux) | ||||
|  * Fix: page copy in Wagtail admin ignores `exclude_fields_in_copy` (John-Scott Atlakson) | ||||
| 
 | ||||
| 
 | ||||
| 2.16.2 (xx.xx.xxxx) - IN DEVELOPMENT | ||||
|  |  | |||
|  | @ -94,6 +94,7 @@ class LandingPage(Page): | |||
|  * Add missing translation usage in Workflow templates (Anuja Verma, Saurabh Kumar) | ||||
|  * Avoid 503 server error when entering tags over 100chars and instead show a user facing validation error (Vu Pham, Khanh Hoang) | ||||
|  * Ensure `thumb_col_header_text` is correctly used by `ThumbnailMixin` within `ModelAdmin` as the column header label (Kyle J. Roux) | ||||
|  * Ensure page copy in Wagtail admin doesn't ignore `exclude_fields_in_copy` (John-Scott Atlakson) | ||||
| 
 | ||||
| 
 | ||||
| ## Upgrade considerations | ||||
|  |  | |||
|  | @ -103,12 +103,12 @@ class CopyPageAction: | |||
|     def _copy_page( | ||||
|         self, page, to=None, update_attrs=None, exclude_fields=None, _mpnode_attrs=None | ||||
|     ): | ||||
|         specific_page = page.specific | ||||
|         exclude_fields = ( | ||||
|             page.default_exclude_fields_in_copy | ||||
|             + page.exclude_fields_in_copy | ||||
|             specific_page.default_exclude_fields_in_copy | ||||
|             + specific_page.exclude_fields_in_copy | ||||
|             + (exclude_fields or []) | ||||
|         ) | ||||
|         specific_page = page.specific | ||||
|         if self.keep_live: | ||||
|             base_update_attrs = { | ||||
|                 "alias_of": None, | ||||
|  |  | |||
|  | @ -11,7 +11,13 @@ from wagtail import hooks | |||
| from wagtail.api.v2.tests.test_pages import TestPageDetail, TestPageListing | ||||
| from wagtail.models import GroupPagePermission, Locale, Page, PageLogEntry | ||||
| from wagtail.test.demosite import models | ||||
| from wagtail.test.testapp.models import EventIndex, EventPage, SimplePage, StreamPage | ||||
| from wagtail.test.testapp.models import ( | ||||
|     EventIndex, | ||||
|     EventPage, | ||||
|     PageWithExcludedCopyField, | ||||
|     SimplePage, | ||||
|     StreamPage, | ||||
| ) | ||||
| from wagtail.users.models import UserProfile | ||||
| 
 | ||||
| from .utils import AdminAPITestCase | ||||
|  | @ -1132,6 +1138,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.models import GroupPagePermission, Page | ||||
| from wagtail.test.testapp.models import SimplePage | ||||
| from wagtail.test.testapp.models import PageWithExcludedCopyField, SimplePage | ||||
| from wagtail.test.utils import WagtailTestUtils | ||||
| 
 | ||||
| 
 | ||||
|  | @ -153,6 +153,36 @@ class TestPageCopy(TestCase, WagtailTestUtils): | |||
|             any(Page.find_problems()), "treebeard found consistency problems" | ||||
|         ) | ||||
| 
 | ||||
|     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 | ||||
|         ) | ||||
| 
 | ||||
|     def test_page_copy_post_copy_subpages(self): | ||||
|         post_data = { | ||||
|             "new_title": "Hello world 2", | ||||
|  |  | |||
|  | @ -22,7 +22,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, | ||||
|  | @ -594,7 +594,6 @@ | |||
|       "content": "<p>collect logs</p>" | ||||
|     } | ||||
|   }, | ||||
| 
 | ||||
|   { | ||||
|     "pk": 20, | ||||
|     "model": "wagtailcore.page", | ||||
|  | @ -611,7 +610,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
	
	 John-Scott Atlakson
						John-Scott Atlakson