kopia lustrzana https://github.com/wagtail/wagtail
Remove special case allowing all page types to be children of Page.
This was required when Page was absent from PAGE_MODEL_CLASSES (due to it being 'abstract' / non-creatable) and thus never appeared in a parent_page_types list. Now it appears in PAGE_MODEL_CLASSES, and is a valid parent page type for page types that do not specify parent_page_types (or explicitly include Page in the list).pull/1978/head
rodzic
5104643438
commit
1bb74ee4d0
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0020_add_index_on_page_first_published_at'),
|
||||
('tests', '0016_mtibasepage_verbose_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='BusinessNowherePage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(serialize=False, auto_created=True, to='wagtailcore.Page', primary_key=True, parent_link=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
|
@ -359,8 +359,8 @@ register_snippet(Advert)
|
|||
|
||||
|
||||
class StandardIndex(Page):
|
||||
""" Index for the site, not allowed to be placed anywhere """
|
||||
parent_page_types = []
|
||||
""" Index for the site """
|
||||
pass
|
||||
|
||||
|
||||
# A custom panel setup where all Promote fields are placed in the Content tab instead;
|
||||
|
@ -403,6 +403,11 @@ class BusinessChild(Page):
|
|||
parent_page_types = ['tests.BusinessIndex', BusinessSubIndex]
|
||||
|
||||
|
||||
class BusinessNowherePage(Page):
|
||||
""" Not allowed to be placed anywhere """
|
||||
parent_page_types = []
|
||||
|
||||
|
||||
class TaggedPageTag(TaggedItemBase):
|
||||
content_object = ParentalKey('tests.TaggedPage', related_name='tagged_items')
|
||||
|
||||
|
|
|
@ -207,6 +207,40 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
self.assertNotContains(response, "MTI Base Page")
|
||||
# List of available page types should not contain abstract pages
|
||||
self.assertNotContains(response, "Abstract Page")
|
||||
# List of available page types should not contain pages whose parent_page_types forbid it
|
||||
self.assertNotContains(response, "Business Child")
|
||||
|
||||
def test_add_subpage_with_subpage_types(self):
|
||||
# Add a BusinessIndex to test business rules in
|
||||
business_index = BusinessIndex(
|
||||
title="Hello world!",
|
||||
slug="hello-world",
|
||||
)
|
||||
self.root_page.add_child(instance=business_index)
|
||||
|
||||
response = self.client.get(reverse('wagtailadmin_pages:add_subpage', args=(business_index.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self.assertContains(response, "Business Child")
|
||||
# List should not contain page types not in the subpage_types list
|
||||
self.assertNotContains(response, "Simple Page")
|
||||
|
||||
def test_add_subpage_with_one_valid_subpage_type(self):
|
||||
# Add a BusinessSubIndex to test business rules in
|
||||
business_index = BusinessIndex(
|
||||
title="Hello world!",
|
||||
slug="hello-world",
|
||||
)
|
||||
self.root_page.add_child(instance=business_index)
|
||||
business_subindex = BusinessSubIndex(
|
||||
title="Hello world!",
|
||||
slug="hello-world",
|
||||
)
|
||||
business_index.add_child(instance=business_subindex)
|
||||
|
||||
response = self.client.get(reverse('wagtailadmin_pages:add_subpage', args=(business_subindex.id, )))
|
||||
# Should be redirected to the 'add' page for BusinessChild, the only valid subpage type
|
||||
self.assertRedirects(response, reverse('wagtailadmin_pages:add', args=('tests', 'businesschild', business_subindex.id)))
|
||||
|
||||
def test_add_subpage_bad_permissions(self):
|
||||
# Remove privileges from user
|
||||
|
|
|
@ -721,11 +721,6 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
|
|||
Returns the list of page types that this page type can be a parent of,
|
||||
as a list of model classes
|
||||
"""
|
||||
# Special case the 'Page' class, such as the Root page or Home page -
|
||||
# otherwise you can not add initial pages when setting up a site
|
||||
if cls == Page:
|
||||
return get_page_models()
|
||||
|
||||
return [
|
||||
subpage_model for subpage_model in cls.clean_subpage_models()
|
||||
if cls in subpage_model.clean_parent_page_models()
|
||||
|
|
|
@ -16,7 +16,7 @@ from wagtail.tests.testapp.models import (
|
|||
BusinessIndex, BusinessSubIndex, BusinessChild, StandardIndex,
|
||||
MTIBasePage, MTIChildPage, AbstractPage, TaggedPage,
|
||||
BlogCategory, BlogCategoryBlogPage, Advert, ManyToManyBlogPage,
|
||||
GenericSnippetPage)
|
||||
GenericSnippetPage, BusinessNowherePage)
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
|
@ -765,9 +765,9 @@ class TestSubpageTypeBusinessRules(TestCase, WagtailTestUtils):
|
|||
# BusinessChild cannot be a parent of anything
|
||||
self.assertNotIn(BusinessChild, SimplePage.allowed_parent_page_models())
|
||||
|
||||
# StandardIndex does not allow anything as a parent
|
||||
self.assertNotIn(SimplePage, StandardIndex.allowed_parent_page_models())
|
||||
self.assertNotIn(StandardIndex, StandardIndex.allowed_parent_page_models())
|
||||
# BusinessNowherePage does not allow anything as a parent
|
||||
self.assertNotIn(SimplePage, BusinessNowherePage.allowed_parent_page_models())
|
||||
self.assertNotIn(StandardIndex, BusinessNowherePage.allowed_parent_page_models())
|
||||
|
||||
# BusinessSubIndex only allows BusinessIndex as a parent
|
||||
self.assertNotIn(SimplePage, BusinessSubIndex.allowed_parent_page_models())
|
||||
|
@ -787,9 +787,9 @@ class TestSubpageTypeBusinessRules(TestCase, WagtailTestUtils):
|
|||
# BusinessChild cannot be a parent of anything
|
||||
self.assertNotIn(ContentType.objects.get_for_model(BusinessChild), SimplePage.allowed_parent_page_types())
|
||||
|
||||
# StandardIndex does not allow anything as a parent
|
||||
self.assertNotIn(ContentType.objects.get_for_model(SimplePage), StandardIndex.allowed_parent_page_types())
|
||||
self.assertNotIn(ContentType.objects.get_for_model(StandardIndex), StandardIndex.allowed_parent_page_types())
|
||||
# BusinessNowherePage does not allow anything as a parent
|
||||
self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessNowherePage.allowed_parent_page_types())
|
||||
self.assertNotIn(ContentType.objects.get_for_model(StandardIndex), BusinessNowherePage.allowed_parent_page_types())
|
||||
|
||||
# BusinessSubIndex only allows BusinessIndex as a parent
|
||||
self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_parent_page_types())
|
||||
|
|
Ładowanie…
Reference in New Issue