diff --git a/src/wagtail_bynder/static/bynder/js/video-chooser-modal.js b/src/wagtail_bynder/static/bynder/js/video-chooser-modal.js index b962096..867a97f 100644 --- a/src/wagtail_bynder/static/bynder/js/video-chooser-modal.js +++ b/src/wagtail_bynder/static/bynder/js/video-chooser-modal.js @@ -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 { diff --git a/src/wagtail_bynder/static/wagtailadmin/js/chooser-modal-handler-factory.js b/src/wagtail_bynder/static/wagtailadmin/js/chooser-modal-handler-factory.js index 78b5ced..a70bbb3 100644 --- a/src/wagtail_bynder/static/wagtailadmin/js/chooser-modal-handler-factory.js +++ b/src/wagtail_bynder/static/wagtailadmin/js/chooser-modal-handler-factory.js @@ -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) { @@ -49,6 +50,9 @@ class BynderChooserModalOnloadHandlerFactory { } else { url = chosenSingleUrl + assets[0].databaseId; + if (chosenUrlAppendSlash) { + url += "/"; + } } modal.loadUrl(url, params); return false; diff --git a/src/wagtail_bynder/static/wagtaildocs/js/document-chooser-modal.js b/src/wagtail_bynder/static/wagtaildocs/js/document-chooser-modal.js index 520798f..746b86b 100644 --- a/src/wagtail_bynder/static/wagtaildocs/js/document-chooser-modal.js +++ b/src/wagtail_bynder/static/wagtaildocs/js/document-chooser-modal.js @@ -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 { diff --git a/src/wagtail_bynder/static/wagtailimages/js/image-chooser-modal.js b/src/wagtail_bynder/static/wagtailimages/js/image-chooser-modal.js index 08d08b8..e6c08e5 100644 --- a/src/wagtail_bynder/static/wagtailimages/js/image-chooser-modal.js +++ b/src/wagtail_bynder/static/wagtailimages/js/image-chooser-modal.js @@ -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 { diff --git a/src/wagtail_bynder/templates/wagtailadmin/admin_base.html b/src/wagtail_bynder/templates/wagtailadmin/admin_base.html index a0035e9..4035c74 100644 --- a/src/wagtail_bynder/templates/wagtailadmin/admin_base.html +++ b/src/wagtail_bynder/templates/wagtailadmin/admin_base.html @@ -6,6 +6,10 @@ diff --git a/src/wagtail_bynder/templatetags/bynder_tags.py b/src/wagtail_bynder/templatetags/bynder_tags.py index c190ee3..93a37fe 100644 --- a/src/wagtail_bynder/templatetags/bynder_tags.py +++ b/src/wagtail_bynder/templatetags/bynder_tags.py @@ -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() @@ -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() diff --git a/src/wagtail_bynder/wagtail_hooks.py b/src/wagtail_bynder/wagtail_hooks.py index 1a91988..df00d8c 100644 --- a/src/wagtail_bynder/wagtail_hooks.py +++ b/src/wagtail_bynder/wagtail_hooks.py @@ -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 @@ -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( """ - - + """, - reverse( - f"{model.snippet_viewset.get_chooser_admin_url_namespace()}:choose" - ), static("bynder/js/video-chooser-modal.js"), ) diff --git a/tox.ini b/tox.ini index dba0f16..09e8f66 100644 --- a/tox.ini +++ b/tox.ini @@ -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 = @@ -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