elhussein 2024-05-02 09:35:51 +00:00 zatwierdzone przez GitHub
commit 32a7a2ea3e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
4 zmienionych plików z 26 dodań i 2 usunięć

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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