Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wagtail mainline] keep up with mainline #557

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions wagtail_localize/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db import models
from django.utils.translation import gettext_lazy
from modelcluster.fields import ParentalKey
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin.edit_handlers import (
FieldPanel,
InlinePanel,
Expand Down Expand Up @@ -178,6 +179,9 @@ def get_translatable_segments(self, value):
return [StringSegmentValue("foo", "{} and some extra".format(value))]


SF_KWARGS = {"use_json_field": True} if WAGTAIL_VERSION >= (4, 0) else {}


class TestPage(Page):
test_charfield = models.CharField(
gettext_lazy("char field"), max_length=255, blank=True, null=True, default=""
Expand All @@ -188,7 +192,7 @@ class TestPage(Page):
test_urlfield = models.URLField(blank=True)

test_richtextfield = RichTextField(blank=True)
test_streamfield = StreamField(TestStreamBlock, blank=True)
test_streamfield = StreamField(TestStreamBlock, blank=True, **SF_KWARGS)

test_snippet = models.ForeignKey(
TestSnippet, null=True, blank=True, on_delete=models.SET_NULL
Expand All @@ -204,7 +208,9 @@ class TestPage(Page):
test_synchronized_urlfield = models.URLField(blank=True)

test_synchronized_richtextfield = RichTextField(blank=True)
test_synchronized_streamfield = StreamField(TestStreamBlock, blank=True)
test_synchronized_streamfield = StreamField(
TestStreamBlock, blank=True, **SF_KWARGS
)

test_synchronized_image = models.ForeignKey(
"wagtailimages.Image",
Expand Down Expand Up @@ -280,7 +286,9 @@ class TestPage(Page):
FieldPanel("test_slugfield"),
FieldPanel("test_urlfield"),
FieldPanel("test_richtextfield"),
StreamFieldPanel("test_streamfield"),
FieldPanel("test_streamfield")
if WAGTAIL_VERSION >= (3, 0)
else StreamFieldPanel("test_streamfield"),
FieldPanel("test_snippet"),
InlinePanel("test_childobjects"),
FieldPanel("test_customfield"),
Expand All @@ -290,7 +298,9 @@ class TestPage(Page):
FieldPanel("test_synchronized_slugfield"),
FieldPanel("test_synchronized_urlfield"),
FieldPanel("test_synchronized_richtextfield"),
StreamFieldPanel("test_synchronized_streamfield"),
FieldPanel("test_synchronized_streamfield")
if WAGTAIL_VERSION >= (3, 0)
else StreamFieldPanel("test_synchronized_streamfield"),
FieldPanel("test_synchronized_image"),
FieldPanel("test_synchronized_document"),
FieldPanel("test_synchronized_snippet"),
Expand Down Expand Up @@ -384,7 +394,7 @@ class TestGenerateTranslatableFieldsPage(Page):
test_urlfield = models.URLField(blank=True)

test_richtextfield = RichTextField(blank=True)
test_streamfield = StreamField(TestStreamBlock, blank=True)
test_streamfield = StreamField(TestStreamBlock, blank=True, **SF_KWARGS)

test_snippet = models.ForeignKey(
TestSnippet, null=True, blank=True, on_delete=models.SET_NULL
Expand Down
8 changes: 7 additions & 1 deletion wagtail_localize/views/edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from wagtail.snippets.blocks import SnippetChooserBlock
from wagtail.snippets.models import get_snippet_models
from wagtail.snippets.permissions import get_permission_name, user_can_edit_snippet_type
from wagtail.snippets.views.snippets import get_snippet_edit_handler

from wagtail_localize.compat import DATE_FORMAT
from wagtail_localize.machine_translators import get_machine_translator
Expand All @@ -58,6 +57,13 @@
from wagtail_localize.segments import StringSegmentValue


if WAGTAIL_VERSION >= (4, 0):
from wagtail.snippets.views.snippets import (
get_snippet_panel as get_snippet_edit_handler,
)
else:
from wagtail.snippets.views.snippets import get_snippet_edit_handler

if WAGTAIL_VERSION >= (3, 0):
# TODO: tidy this up once we drop support for Wagtail < 3.0
from wagtail.admin.panels import FieldPanel, ObjectList, PageChooserPanel
Expand Down