From 60ea0427fba25b891c5316595f04ae470def1f52 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 20 Nov 2015 17:26:17 +0000 Subject: [PATCH] Formally deprecate ContentType-returning methods in wagtailcore --- docs/releases/1.3.rst | 11 ++++ wagtail/wagtailcore/models.py | 27 +++++++++- wagtail/wagtailcore/tests/test_page_model.py | 55 +++++++++++--------- 3 files changed, 66 insertions(+), 27 deletions(-) diff --git a/docs/releases/1.3.rst b/docs/releases/1.3.rst index a84a5f01e..9742d816c 100644 --- a/docs/releases/1.3.rst +++ b/docs/releases/1.3.rst @@ -31,3 +31,14 @@ Bug fixes Upgrade considerations ====================== + +ContentType-returning methods in wagtailcore are deprecated +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following internal functions and methods in ``wagtail.wagtailcore.models``, which return a list of ``ContentType`` objects, have been deprecated. Any uses of these in your code should be replaced by the corresponding new function which returns a list of model classes instead: + + * ``get_page_types()`` - replaced by ``get_page_models()`` + * ``Page.clean_subpage_types()`` - replaced by ``Page.clean_subpage_models()`` + * ``Page.clean_parent_page_types()`` - replaced by ``Page.clean_parent_page_models()`` + * ``Page.allowed_parent_page_types()`` - replaced by ``Page.allowed_parent_page_models()`` + * ``Page.allowed_subpage_types()`` - replaced by ``Page.allowed_subpage_models()`` diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index fca629351..11e4852e6 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -42,7 +42,7 @@ from wagtail.wagtailcore.signals import page_published, page_unpublished from wagtail.wagtailsearch import index from wagtail.wagtailsearch.backends import get_search_backend -from wagtail.utils.deprecation import RemovedInWagtail14Warning +from wagtail.utils.deprecation import RemovedInWagtail14Warning, RemovedInWagtail15Warning logger = logging.getLogger('wagtail.core') @@ -180,9 +180,14 @@ def get_page_models(): def get_page_types(): """ + DEPRECATED. Returns a list of ContentType objects for all non-abstract Page model classes defined in this project. """ + warnings.warn( + "get_page_types is deprecated - please use get_page_models instead", + RemovedInWagtail15Warning, stacklevel=2) + return get_content_type_list(PAGE_MODEL_CLASSES) @@ -642,8 +647,13 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed @classmethod def clean_subpage_types(cls): """ + DEPRECATED. Returns the list of subpage types, normalised as ContentType objects """ + warnings.warn( + "clean_subpage_types is deprecated - please use clean_subpage_models instead", + RemovedInWagtail15Warning, stacklevel=2) + return get_content_type_list(cls.clean_subpage_models()) @classmethod @@ -672,8 +682,13 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed @classmethod def clean_parent_page_types(cls): """ + DEPRECATED. Returns the list of parent page types, normalised as ContentType objects """ + warnings.warn( + "clean_parent_page_types is deprecated - please use clean_parent_page_models instead", + RemovedInWagtail15Warning, stacklevel=2) + return get_content_type_list(cls.clean_parent_page_models()) @classmethod @@ -690,9 +705,14 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed @classmethod def allowed_parent_page_types(cls): """ + DEPRECATED. Returns the list of page types that this page type can be a subpage of, as a list of ContentType objects """ + warnings.warn( + "allowed_parent_page_types is deprecated - please use allowed_parent_page_models instead", + RemovedInWagtail15Warning, stacklevel=2) + return get_content_type_list(cls.allowed_parent_page_models()) @classmethod @@ -714,9 +734,14 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed @classmethod def allowed_subpage_types(cls): """ + DEPRECATED. Returns the list of page types that this page type can be a parent of, as a list of ContentType objects """ + warnings.warn( + "allowed_subpage_types is deprecated - please use allowed_subpage_models instead", + RemovedInWagtail15Warning, stacklevel=2) + return get_content_type_list(cls.allowed_subpage_models()) @classmethod diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index f028bb3c9..b90395c05 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -17,6 +17,7 @@ from wagtail.tests.testapp.models import ( MTIBasePage, MTIChildPage, AbstractPage, TaggedPage, BlogCategory, BlogCategoryBlogPage, Advert, ManyToManyBlogPage, GenericSnippetPage) +from wagtail.tests.utils import WagtailTestUtils class TestSiteRouting(TestCase): @@ -713,7 +714,7 @@ class TestCopyPage(TestCase): self.assertEqual(new_page.snippet_content_object, advert) -class TestSubpageTypeBusinessRules(TestCase): +class TestSubpageTypeBusinessRules(TestCase, WagtailTestUtils): def test_allowed_subpage_models(self): # SimplePage does not define any restrictions on subpage types # SimplePage is a valid subpage of SimplePage @@ -739,22 +740,23 @@ class TestSubpageTypeBusinessRules(TestCase): objects rather than model classes """ - # SimplePage does not define any restrictions on subpage types - # SimplePage is a valid subpage of SimplePage - self.assertIn(ContentType.objects.get_for_model(SimplePage), SimplePage.allowed_subpage_types()) - # BusinessIndex is a valid subpage of SimplePage - self.assertIn(ContentType.objects.get_for_model(BusinessIndex), SimplePage.allowed_subpage_types()) - # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types - self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex), SimplePage.allowed_subpage_types()) + with self.ignore_deprecation_warnings(): + # SimplePage does not define any restrictions on subpage types + # SimplePage is a valid subpage of SimplePage + self.assertIn(ContentType.objects.get_for_model(SimplePage), SimplePage.allowed_subpage_types()) + # BusinessIndex is a valid subpage of SimplePage + self.assertIn(ContentType.objects.get_for_model(BusinessIndex), SimplePage.allowed_subpage_types()) + # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types + self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex), SimplePage.allowed_subpage_types()) - # BusinessChild has an empty subpage_types list, so does not allow anything - self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessChild.allowed_subpage_types()) - self.assertNotIn(ContentType.objects.get_for_model(BusinessIndex), BusinessChild.allowed_subpage_types()) - self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex), BusinessChild.allowed_subpage_types()) + # BusinessChild has an empty subpage_types list, so does not allow anything + self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessChild.allowed_subpage_types()) + self.assertNotIn(ContentType.objects.get_for_model(BusinessIndex), BusinessChild.allowed_subpage_types()) + self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex), BusinessChild.allowed_subpage_types()) - # BusinessSubIndex only allows BusinessChild as subpage type - self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_subpage_types()) - self.assertIn(ContentType.objects.get_for_model(BusinessChild), BusinessSubIndex.allowed_subpage_types()) + # BusinessSubIndex only allows BusinessChild as subpage type + self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_subpage_types()) + self.assertIn(ContentType.objects.get_for_model(BusinessChild), BusinessSubIndex.allowed_subpage_types()) def test_allowed_parent_page_models(self): # SimplePage does not define any restrictions on parent page types @@ -778,19 +780,20 @@ class TestSubpageTypeBusinessRules(TestCase): with ContentType objects rather than model classes """ - # SimplePage does not define any restrictions on parent page types - # SimplePage is a valid parent page of SimplePage - self.assertIn(ContentType.objects.get_for_model(SimplePage), SimplePage.allowed_parent_page_types()) - # BusinessChild cannot be a parent of anything - self.assertNotIn(ContentType.objects.get_for_model(BusinessChild), SimplePage.allowed_parent_page_types()) + with self.ignore_deprecation_warnings(): + # SimplePage does not define any restrictions on parent page types + # SimplePage is a valid parent page of SimplePage + self.assertIn(ContentType.objects.get_for_model(SimplePage), SimplePage.allowed_parent_page_types()) + # 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()) + # 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()) - # BusinessSubIndex only allows BusinessIndex as a parent - self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_parent_page_types()) - self.assertIn(ContentType.objects.get_for_model(BusinessIndex), BusinessSubIndex.allowed_parent_page_types()) + # BusinessSubIndex only allows BusinessIndex as a parent + self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_parent_page_types()) + self.assertIn(ContentType.objects.get_for_model(BusinessIndex), BusinessSubIndex.allowed_parent_page_types()) class TestIssue735(TestCase):