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: Compatibility with Wagtail 6.1 #34

Merged
merged 6 commits into from
Jul 29, 2024
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
4 changes: 2 additions & 2 deletions src/wagtail_bynder/static/bynder/js/video-chooser-modal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const videoChooserModalOnloadHandlers = new window.BynderChooserModalOnloadHandlerFactory({
assetType: "video",
chosenMultipleUrl: `${window.chooserUrls.videoChooser}chosen-multiple/`,
chosenSingleUrl: `${window.chooserUrls.videoChooser}chosen/`,
chosenMultipleUrl: `${window.videoChosenBaseUrl}chosen-multiple/`,
chosenSingleUrl: `${window.videoChosenBaseUrl}chosen/`,
}).getOnLoadHandlers();

class VideoChooserModal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BynderChooserModalOnloadHandlerFactory {
this.assetType = opts?.assetType || null;
this.chosenMultipleUrl = opts?.chosenMultipleUrl || "/";
this.chosenSingleUrl = opts?.chosenSingleUrl || "/";
this.chosenUrlAppendSlash = window.chosenUrlappendSlash || true;
}

onLoadChooseStep(modal) {
Expand Down Expand Up @@ -49,6 +50,9 @@ class BynderChooserModalOnloadHandlerFactory {
}
else {
url = chosenSingleUrl + assets[0].databaseId;
if (chosenUrlAppendSlash) {
url += "/";
}
}
modal.loadUrl(url, params);
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const documentChooserModalOnloadHandlers = new window.BynderChooserModalOnloadHandlerFactory({
assetType: "document",
chosenMultipleUrl: `${window.chooserUrls.documentChooser}chosen-multiple/`,
chosenSingleUrl: `${window.chooserUrls.documentChooser}chosen/`,
chosenMultipleUrl: `${window.documentChosenBaseUrl}chosen-multiple/`,
chosenSingleUrl: `${window.documentChosenBaseUrl}chosen/`,
}).getOnLoadHandlers();

class DocumentChooserModal {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const imageChooserModalOnloadHandlers = new window.BynderChooserModalOnloadHandlerFactory({
assetType: "image",
chosenMultipleUrl: `${window.chooserUrls.imageChooser}chosen-multiple/`,
chosenSingleUrl: `${window.chooserUrls.imageChooser}chosen/`,
chosenMultipleUrl: `${window.imageChosenBaseUrl}chosen-multiple/`,
chosenSingleUrl: `${window.imageChosenBaseUrl}chosen/`,
}).getOnLoadHandlers();

class ImageChooserModal {
Expand Down
4 changes: 4 additions & 0 deletions src/wagtail_bynder/templates/wagtailadmin/admin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<script>
window.bynderAPIToken = '{% bynder_compactview_api_token %}';
window.bynderDomain = '{% bynder_domain %}';
window.chosenUrlAppendSlash = {% get_append_slash %};
window.imageChosenBaseUrl = "{% get_image_chosen_base_url %}";
window.documentChosenBaseUrl = "{% get_document_chosen_base_url %}";
window.videoChosenBaseUrl = "{% get_video_chosen_base_url %}";
</script>
<script src="{% static 'wagtailadmin/js/chooser-modal-handler-factory.js' %}"></script>

Expand Down
35 changes: 35 additions & 0 deletions src/wagtail_bynder/templatetags/bynder_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django import template
from django.conf import settings
from django.urls import reverse

from wagtail_bynder import get_video_model


register = template.Library()
Expand All @@ -13,3 +16,35 @@ def bynder_domain():
@register.simple_tag
def bynder_compactview_api_token():
return getattr(settings, "BYNDER_COMPACTVIEW_API_TOKEN", "")


@register.simple_tag
def get_image_chosen_base_url():
url = reverse("wagtailimages_chooser:choose")
if not url.endswith("/"):
url += "/"
return url


@register.simple_tag
def get_document_chosen_base_url():
url = reverse("wagtaildocs_chooser:choose")
if not url.endswith("/"):
url += "/"
return url


@register.simple_tag
def get_video_chosen_base_url():
model = get_video_model()
if model:
url = model.snippet_viewset.chooser_viewset.get_url_name("choose")
if not url.endswith("/"):
url += "/"
return url
return ""


@register.simple_tag
def get_append_slash():
return str(bool(settings.APPEND_SLASH)).lower()
11 changes: 2 additions & 9 deletions src/wagtail_bynder/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.conf import settings
from django.templatetags.static import static
from django.urls import reverse
from django.utils.html import format_html
from wagtail import hooks
from wagtail.admin.menu import MenuItem
Expand Down Expand Up @@ -50,17 +49,11 @@ def hide_image_and_document_summary_items(request, summary_items):

@hooks.register("insert_editor_js")
def editor_js():
if model := get_video_model():
if get_video_model():
return format_html(
"""
<script>
window.chooserUrls.videoChooser = '{0}';
</script>
<script src="{1}"></script>
<script src="{0}"></script>
""",
reverse(
f"{model.snippet_viewset.get_chooser_admin_url_namespace()}:choose"
),
static("bynder/js/video-chooser-modal.js"),
)

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
min_version = 4.11

envlist =
py{3.11,3.12}-django{4.2,5.0}-wagtail{5.2,6.0}
py{3.11,3.12}-django{4.2,5.0}-wagtail{5.2,6.1}

[gh-actions]
python =
Expand Down Expand Up @@ -35,7 +35,7 @@ deps =
django5.0: Django>=5.0,<5.1

wagtail5.2: wagtail>=5.2,<5.3
wagtail6.0: wagtail>=6.0,<6.1
wagtail6.1: wagtail>=6.1,<6.2
wagtailmain: git+https://github.com/wagtail/wagtail.git

postgres: psycopg2>=2.9
Expand Down