kopia lustrzana https://github.com/wagtail/wagtail
Remove uses of StreamFieldPanel, including the check that you're using it
rodzic
5fe7aef030
commit
b8fd95ee86
|
@ -1,7 +1,6 @@
|
|||
import os
|
||||
|
||||
from django.core.checks import Error, Tags, Warning, register
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
|
||||
|
||||
@register("staticfiles")
|
||||
|
@ -165,54 +164,3 @@ There are no default tabs on non-Page models so there will be no \
|
|||
errors.append(error)
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
@register("panels")
|
||||
def panel_type_check(app_configs, **kwargs):
|
||||
from wagtail.core.models import get_page_models
|
||||
|
||||
errors = []
|
||||
|
||||
for cls in get_page_models():
|
||||
errors += traverse_edit_handlers(cls.get_edit_handler())
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def traverse_edit_handlers(edit_handler):
|
||||
errors = []
|
||||
|
||||
try:
|
||||
for child in edit_handler.children:
|
||||
errors += traverse_edit_handlers(child)
|
||||
except AttributeError:
|
||||
error = check_stream_field_panel_type(edit_handler)
|
||||
if error:
|
||||
errors.append(error)
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def check_stream_field_panel_type(edit_handler):
|
||||
from wagtail.admin.edit_handlers import StreamFieldPanel
|
||||
from wagtail.core.fields import StreamField
|
||||
|
||||
try:
|
||||
db_field = getattr(edit_handler, "db_field", None)
|
||||
if isinstance(db_field, StreamField) and not isinstance(
|
||||
edit_handler, StreamFieldPanel
|
||||
):
|
||||
return Warning(
|
||||
"{model}.{field_name} is a StreamField, but uses {edit_handler}".format(
|
||||
model=edit_handler.model.__name__,
|
||||
field_name=edit_handler.field_name,
|
||||
edit_handler=edit_handler.__class__.__name__,
|
||||
),
|
||||
hint="Ensure that it uses a StreamFieldPanel, or change the field type",
|
||||
obj=edit_handler.model,
|
||||
id="wagtailadmin.W003",
|
||||
)
|
||||
except FieldDoesNotExist:
|
||||
# Doesn't check any fields not on the model, such as in
|
||||
# wagtail.tests.testapp.modelsFormClassAdditionalFieldPage
|
||||
pass
|
||||
|
|
|
@ -35,7 +35,6 @@ from wagtail.admin.widgets import (
|
|||
from wagtail.core.models import Comment, CommentReply, Page, Site
|
||||
from wagtail.tests.testapp.forms import ValidatedPageForm
|
||||
from wagtail.tests.testapp.models import (
|
||||
DefaultStreamPage,
|
||||
EventPage,
|
||||
EventPageChooserModel,
|
||||
EventPageSpeaker,
|
||||
|
@ -254,33 +253,6 @@ class TestPageEditHandlers(TestCase):
|
|||
|
||||
self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])
|
||||
|
||||
@clear_edit_handler(DefaultStreamPage)
|
||||
def test_check_invalid_streamfield_edit_handler(self):
|
||||
"""
|
||||
Set the edit handler for body (a StreamField) to be
|
||||
a FieldPanel instead of a StreamFieldPanel.
|
||||
Check that the correct warning is raised.
|
||||
"""
|
||||
|
||||
invalid_edit_handler = checks.Warning(
|
||||
"DefaultStreamPage.body is a StreamField, but uses FieldPanel",
|
||||
hint="Ensure that it uses a StreamFieldPanel, or change the field type",
|
||||
obj=DefaultStreamPage,
|
||||
id="wagtailadmin.W003",
|
||||
)
|
||||
|
||||
with mock.patch.object(
|
||||
DefaultStreamPage, "content_panels", new=[FieldPanel("body")]
|
||||
):
|
||||
checks_result = checks.run_checks(tags=["panels"])
|
||||
|
||||
# Only look at warnings for DefaultStreamPage
|
||||
warning = [
|
||||
warning for warning in checks_result if warning.obj == DefaultStreamPage
|
||||
]
|
||||
|
||||
self.assertEqual(warning, [invalid_edit_handler])
|
||||
|
||||
@clear_edit_handler(ValidatedPage)
|
||||
def test_custom_edit_handler_form_class(self):
|
||||
"""
|
||||
|
|
|
@ -93,11 +93,6 @@ class StreamField(models.Field):
|
|||
def get_internal_type(self):
|
||||
return "TextField"
|
||||
|
||||
def get_panel(self):
|
||||
from wagtail.admin.edit_handlers import StreamFieldPanel
|
||||
|
||||
return StreamFieldPanel
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, _, kwargs = super().deconstruct()
|
||||
block_types = list(self.stream_block.child_blocks.items())
|
||||
|
|
|
@ -24,7 +24,6 @@ from wagtail.admin.edit_handlers import (
|
|||
InlinePanel,
|
||||
MultiFieldPanel,
|
||||
ObjectList,
|
||||
StreamFieldPanel,
|
||||
TabbedInterface,
|
||||
)
|
||||
from wagtail.admin.forms import WagtailAdminPageForm
|
||||
|
@ -1184,7 +1183,7 @@ class StreamPage(Page):
|
|||
|
||||
content_panels = [
|
||||
FieldPanel("title"),
|
||||
StreamFieldPanel("body"),
|
||||
FieldPanel("body"),
|
||||
]
|
||||
|
||||
preview_modes = []
|
||||
|
@ -1202,7 +1201,7 @@ class DefaultStreamPage(Page):
|
|||
|
||||
content_panels = [
|
||||
FieldPanel("title"),
|
||||
StreamFieldPanel("body"),
|
||||
FieldPanel("body"),
|
||||
]
|
||||
|
||||
|
||||
|
@ -1400,7 +1399,7 @@ class DefaultRichBlockFieldPage(Page):
|
|||
]
|
||||
)
|
||||
|
||||
content_panels = Page.content_panels + [StreamFieldPanel("body")]
|
||||
content_panels = Page.content_panels + [FieldPanel("body")]
|
||||
|
||||
|
||||
class CustomRichTextFieldPage(Page):
|
||||
|
@ -1421,7 +1420,7 @@ class CustomRichBlockFieldPage(Page):
|
|||
|
||||
content_panels = [
|
||||
FieldPanel("title", classname="full title"),
|
||||
StreamFieldPanel("body"),
|
||||
FieldPanel("body"),
|
||||
]
|
||||
|
||||
|
||||
|
@ -1463,7 +1462,7 @@ class InlineStreamPageSection(Orderable):
|
|||
("image", ImageChooserBlock()),
|
||||
]
|
||||
)
|
||||
panels = [StreamFieldPanel("body")]
|
||||
panels = [FieldPanel("body")]
|
||||
|
||||
|
||||
class InlineStreamPage(Page):
|
||||
|
@ -1476,7 +1475,7 @@ class InlineStreamPage(Page):
|
|||
class TableBlockStreamPage(Page):
|
||||
table = StreamField([("table", TableBlock())])
|
||||
|
||||
content_panels = [StreamFieldPanel("table")]
|
||||
content_panels = [FieldPanel("table")]
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
|
@ -1701,7 +1700,7 @@ class DeadlyStreamPage(Page):
|
|||
]
|
||||
)
|
||||
content_panels = Page.content_panels + [
|
||||
StreamFieldPanel("body"),
|
||||
FieldPanel("body"),
|
||||
]
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue