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

Fix nightly errors #536

Merged
merged 4 commits into from Mar 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion wagtail_localize/models.py
Expand Up @@ -514,7 +514,11 @@ def as_instance(self):
raise SourceDeletedError

if isinstance(instance, Page):
return instance.with_content_json(self.content_json)
content_json = self.content_json
if WAGTAIL_VERSION >= (2, 17):
# see https://github.com/wagtail/wagtail/pull/8024
content_json = json.loads(content_json)
return instance.with_content_json(content_json)

elif isinstance(instance, ClusterableModel):
new_instance = instance.__class__.from_json(self.content_json)
Expand Down
12 changes: 11 additions & 1 deletion wagtail_localize/views/convert.py
@@ -1,9 +1,12 @@
import json

from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.translation import gettext as _
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin import messages
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
from wagtail.core.models import (
Expand Down Expand Up @@ -102,6 +105,10 @@ def sync_alias(source_page, alias_page, revision=None, _content_json=None):
if _content_json is None:
_content_json = source_page.to_json()

if WAGTAIL_VERSION >= (2, 17):
# see https://github.com/wagtail/wagtail/pull/8024
_content_json = json.loads(_content_json)

# FIXME: update when core adds better mechanism for the exclusions
exclude_fields = [
"id",
Expand Down Expand Up @@ -166,4 +173,7 @@ def process_child_object(child_object):
)

# Update any aliases of that alias
alias_page.update_aliases(revision=revision, _content_json=_content_json)
if WAGTAIL_VERSION >= (2, 17):
alias_page.update_aliases(revision=revision, _content=_content_json)
else:
alias_page.update_aliases(revision=revision, _content_json=_content_json)
45 changes: 39 additions & 6 deletions wagtail_localize/views/edit_translation.py
Expand Up @@ -27,6 +27,7 @@
)
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin import messages
from wagtail.admin.edit_handlers import (
BaseCompositeEditHandler,
Expand Down Expand Up @@ -268,15 +269,47 @@ def widget_from_field(field):
if issubclass(field.related_model, Page):
edit_handler = tab_helper.get_field_edit_handler(field.name)

if WAGTAIL_VERSION >= (2, 17):
# @see https://github.com/wagtail/wagtail/pull/7684
# the target_models is set in the ModelFieldRegistry for ForeignKeys

# Check for explicit `page_types` kwarg in PageChooserPanel
if field.name in edit_handler.widget_overrides() and hasattr(
edit_handler.widget_overrides()[field.name], "target_models"
):
allowed_page_types = [
"{app}.{model}".format(
app=model._meta.app_label,
model=model._meta.model_name,
)
for model in edit_handler.widget_overrides()[
field.name
].target_models
]
else:
from wagtail.admin.forms.models import registry

allowed_page_types = [
"{app}.{model}".format(
app=model._meta.app_label,
model=model._meta.model_name,
)
for model in registry.foreign_key_lookup(field)[
"widget"
].target_models
]
else:
allowed_page_types = [
"{app}.{model}".format(
app=model._meta.app_label, model=model._meta.model_name
)
for model in edit_handler.target_models()
]

if isinstance(edit_handler, PageChooserPanel):
return {
"type": "page_chooser",
"allowed_page_types": [
"{app}.{model}".format(
app=model._meta.app_label, model=model._meta.model_name
)
for model in edit_handler.target_models()
],
"allowed_page_types": allowed_page_types,
}

else:
Expand Down