From a068e4e9ba33127b18a0734d9dc171bc97ede257 Mon Sep 17 00:00:00 2001 From: Tidiane Dia <71412737+Tijani-Dia@users.noreply.github.com> Date: Thu, 26 May 2022 16:03:49 +0100 Subject: [PATCH] [DUBS-521] Wagtail 3 and Django 4 compatibility (#25) * Update imports for Django 4 compatibility DUBS-521 * use globalThis as global object in js file DUBS-521 * Update package requirements to include Wagtail 3 DUBS-521 * Match requirements in pyproject.toml and setup.py files DUBS-521 --- pyproject.toml | 4 ++-- setup.py | 2 +- .../js/wagtail-draftail-snippet.js | 1 + wagtail_draftail_snippet/urls.py | 9 ++++----- wagtail_draftail_snippet/wagtail_hooks.py | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5f8b195..0920793 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,8 +8,8 @@ readme = "README.md" license = "BSD-3-Clause" [tool.poetry.dependencies] -python = "^3.6" -wagtail = "^2.5" +python = ">=3.6" +wagtail = ">=2.5.0 <4.0" [tool.poetry.dev-dependencies] pytest = "^3.0" diff --git a/setup.py b/setup.py index b88671d..59e69c7 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ setup( "templates/wagtail_draftail_snippet/*.html", ] }, - install_requires=["wagtail==2.*,>=2.5.0"], + install_requires=["wagtail>=2.5.0,<4.0"], extras_require={ "dev": [ "black==19.*,>=19.10.0", diff --git a/wagtail_draftail_snippet/static/wagtail_draftail_snippet/js/wagtail-draftail-snippet.js b/wagtail_draftail_snippet/static/wagtail_draftail_snippet/js/wagtail-draftail-snippet.js index c34e01c..d5696de 100644 --- a/wagtail_draftail_snippet/static/wagtail_draftail_snippet/js/wagtail-draftail-snippet.js +++ b/wagtail_draftail_snippet/static/wagtail_draftail_snippet/js/wagtail-draftail-snippet.js @@ -9,6 +9,7 @@ const TooltipEntity = window.draftail.TooltipEntity; + const global = globalThis; const $ = global.jQuery; const MUTABILITY = {}; diff --git a/wagtail_draftail_snippet/urls.py b/wagtail_draftail_snippet/urls.py index ddd4e83..2dda891 100644 --- a/wagtail_draftail_snippet/urls.py +++ b/wagtail_draftail_snippet/urls.py @@ -1,5 +1,4 @@ from django.urls import path -from django.conf.urls import url from wagtail.snippets.views import chooser @@ -9,13 +8,13 @@ from .views import choose_snippet_link_model, choose_snippet_embed_model app_name = "wagtaildraftailsnippet" urlpatterns = [ - url( - r"^choose-link-model/$", + path( + "choose-link-model/", choose_snippet_link_model, name="choose-snippet-link-model", ), - url( - r"^choose-embed-model/$", + path( + "choose-embed-model/", choose_snippet_embed_model, name="choose-snippet-embed-model", ), diff --git a/wagtail_draftail_snippet/wagtail_hooks.py b/wagtail_draftail_snippet/wagtail_hooks.py index bb7967a..e5c696e 100644 --- a/wagtail_draftail_snippet/wagtail_hooks.py +++ b/wagtail_draftail_snippet/wagtail_hooks.py @@ -1,7 +1,7 @@ -from django.conf.urls import include, url +from django.urls import include, path from django.urls import reverse from django.utils.html import format_html -from django.utils.translation import ugettext +from django.utils.translation import gettext from wagtail.admin.rich_text.editors.draftail import features as draftail_features from wagtail.core import hooks @@ -26,7 +26,7 @@ def register_snippet_link_feature(features): "draftail", feature_name, draftail_features.EntityFeature( - {"type": type_, "icon": "snippet", "description": ugettext("Snippet Link")}, + {"type": type_, "icon": "snippet", "description": gettext("Snippet Link")}, js=[ "wagtailsnippets/js/snippet-chooser-modal.js", "wagtail_draftail_snippet/js/snippet-model-chooser-modal.js", @@ -51,7 +51,7 @@ def register_snippet_embed_feature(features): "draftail", feature_name, draftail_features.EntityFeature( - {"type": type_, "icon": "code", "description": ugettext("Snippet Embed")}, + {"type": type_, "icon": "code", "description": gettext("Snippet Embed")}, js=[ "wagtailsnippets/js/snippet-chooser-modal.js", "wagtail_draftail_snippet/js/snippet-model-chooser-modal.js", @@ -81,4 +81,4 @@ def editor_js(): @hooks.register("register_admin_urls") def register_admin_urls(): - return [url(r"^snippets/", include(urls, namespace="wagtaildraftailsnippet"))] + return [path("snippets/", include(urls, namespace="wagtaildraftailsnippet"))]