kopia lustrzana https://github.com/wagtail/wagtail
Merge e0958c2cb8
into 196cb02d10
commit
32a7a2ea3e
|
@ -222,7 +222,11 @@ class CopyPageAction:
|
|||
)
|
||||
|
||||
for exclude_field in specific_page.exclude_fields_in_copy:
|
||||
if exclude_field in revision_content and hasattr(
|
||||
if hasattr(page_copy, exclude_field) and hasattr(
|
||||
getattr(page_copy, exclude_field), "all"
|
||||
):
|
||||
revision_content[exclude_field] = []
|
||||
elif exclude_field in revision_content and hasattr(
|
||||
page_copy, exclude_field
|
||||
):
|
||||
revision_content[exclude_field] = getattr(
|
||||
|
|
|
@ -66,6 +66,15 @@ class Migration(migrations.Migration):
|
|||
to="tests.gallerypage",
|
||||
),
|
||||
),
|
||||
(
|
||||
"exclude_field",
|
||||
modelcluster.fields.ParentalKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="related_manager",
|
||||
to="tests.pagewithexcludedcopyfield",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"ordering": ["sort_order"],
|
||||
|
|
|
@ -217,12 +217,13 @@ class PageWithExcludedCopyField(Page):
|
|||
|
||||
# Exclude this field from being copied
|
||||
special_field = models.CharField(blank=True, max_length=255, default="Very Special")
|
||||
exclude_fields_in_copy = ["special_field"]
|
||||
exclude_fields_in_copy = ["special_field", "related_manager"]
|
||||
|
||||
content_panels = [
|
||||
FieldPanel("title", classname="title"),
|
||||
FieldPanel("special_field"),
|
||||
FieldPanel("content"),
|
||||
MultipleChooserPanel("related_manager", chooser_field_name="image"),
|
||||
]
|
||||
|
||||
|
||||
|
@ -2266,6 +2267,12 @@ class GalleryPageImage(Orderable):
|
|||
page = ParentalKey(
|
||||
"tests.GalleryPage", related_name="gallery_images", on_delete=models.CASCADE
|
||||
)
|
||||
exclude_field = ParentalKey(
|
||||
"tests.PageWithExcludedCopyField",
|
||||
related_name="related_manager",
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
)
|
||||
image = models.ForeignKey(
|
||||
"wagtailimages.Image",
|
||||
on_delete=models.CASCADE,
|
||||
|
|
|
@ -1971,6 +1971,9 @@ class TestCopyPage(TestCase):
|
|||
page.save_revision()
|
||||
new_page = page.copy(to=homepage, update_attrs={"slug": "disco-2"})
|
||||
exclude_field = new_page.latest_revision.content["special_field"]
|
||||
exclude_field_related_manager = new_page.latest_revision.content[
|
||||
"related_manager"
|
||||
]
|
||||
|
||||
self.assertEqual(page.title, new_page.title)
|
||||
self.assertNotEqual(page.id, new_page.id)
|
||||
|
@ -1978,6 +1981,7 @@ class TestCopyPage(TestCase):
|
|||
# special_field is in the list to be excluded
|
||||
self.assertNotEqual(page.special_field, new_page.special_field)
|
||||
self.assertEqual(new_page.special_field, exclude_field)
|
||||
self.assertEqual(exclude_field_related_manager, [])
|
||||
|
||||
def test_page_with_generic_relation(self):
|
||||
"""Test that a page with a GenericRelation will have that relation ignored when
|
||||
|
|
Ładowanie…
Reference in New Issue