0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Remove legacy content_type handling from AdminPageChooser

This commit is contained in:
Matt Westcott 2016-08-09 16:44:39 +01:00
parent 498ced15fb
commit 545c1601da
2 changed files with 1 additions and 52 deletions

View File

@ -1,12 +1,8 @@
from __future__ import absolute_import, unicode_literals
import warnings
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from wagtail.tests.testapp.models import EventPage, SimplePage
from wagtail.utils.deprecation import RemovedInWagtail17Warning
from wagtail.wagtailadmin import widgets
from wagtail.wagtailcore.models import Page
@ -70,30 +66,6 @@ class TestAdminPageChooserWidget(TestCase):
js_init, "createPageChooser(\"test-id\", [\"tests.simplepage\", \"tests.eventpage\"], null, false);"
)
def test_render_js_init_with_content_type(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('always')
content_type = ContentType.objects.get_for_model(SimplePage)
widget = widgets.AdminPageChooser(content_type=content_type)
self.assertEqual(len(ws), 1)
self.assertIs(ws[0].category, RemovedInWagtail17Warning)
self.assertEqual(widget.target_models, [SimplePage])
def test_render_js_init_with_multiple_content_types(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('always')
content_types = [
# Not using get_for_models as we need deterministic ordering
ContentType.objects.get_for_model(SimplePage),
ContentType.objects.get_for_model(EventPage),
]
widget = widgets.AdminPageChooser(content_type=content_types)
self.assertEqual(len(ws), 1)
self.assertIs(ws[0].category, RemovedInWagtail17Warning)
self.assertEqual(widget.target_models, [SimplePage, EventPage])
def test_render_js_init_with_can_choose_root(self):
widget = widgets.AdminPageChooser(can_choose_root=True)

View File

@ -2,22 +2,18 @@ from __future__ import absolute_import, unicode_literals
import itertools
import json
import warnings
from functools import total_ordering
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.forms import widgets
from django.forms.utils import flatatt
from django.template.loader import render_to_string
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import get_format
from django.utils.functional import cached_property
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from taggit.forms import TagWidget
from wagtail.utils.deprecation import RemovedInWagtail17Warning
from wagtail.utils.widgets import WidgetWithScript
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page
@ -137,31 +133,12 @@ class AdminPageChooser(AdminChooser):
choose_another_text = _('Choose another page')
link_to_chosen_text = _('Edit this page')
def __init__(self, target_models=None, content_type=None, can_choose_root=False, **kwargs):
def __init__(self, target_models=None, can_choose_root=False, **kwargs):
super(AdminPageChooser, self).__init__(**kwargs)
self.target_models = list(target_models or [Page])
if content_type is not None:
if target_models is not None:
raise ValueError("Can not set both target_models and content_type")
warnings.warn(
'The content_type argument for AdminPageChooser() is deprecated. Use the target_models argument instead',
category=RemovedInWagtail17Warning)
if isinstance(content_type, ContentType):
self.target_models = [content_type.model_class()]
else:
self.target_models = [ct.model_class() for ct in content_type]
self.can_choose_root = can_choose_root
@cached_property
def target_content_types(self):
warnings.warn(
'AdminPageChooser.target_content_types is deprecated. Use AdminPageChooser.target_models instead',
category=RemovedInWagtail17Warning)
return list(ContentType.objects.get_for_models(*self.target_models).values())
def _get_lowest_common_page_class(self):
"""
Return a Page class that is an ancestor for all Page classes in