Formally deprecate ContentType-returning methods in wagtailcore

This commit is contained in:
Matt Westcott 2015-11-20 17:26:17 +00:00
parent 9f1993ad10
commit 60ea0427fb
3 changed files with 66 additions and 27 deletions

View file

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

View file

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

View file

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