diff --git a/wagtail/tests/testapp/migrations/0017_businessnowherepage.py b/wagtail/tests/testapp/migrations/0017_businessnowherepage.py new file mode 100644 index 0000000000..bf33fb4cca --- /dev/null +++ b/wagtail/tests/testapp/migrations/0017_businessnowherepage.py @@ -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',), + ), + ] diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index 9ade4324aa..e1ad8a3276 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -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') diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 5c14f7d44a..a05841af7b 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -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 diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index f5a0c7c2f4..8536e3bc71 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -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() diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index 92bbe54849..1b2f72bded 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -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())