Add the chooser-url as a url path.
This commit is contained in:
parent
0d73e505ae
commit
0800764bd6
2 changed files with 29 additions and 15 deletions
|
@ -1,11 +1,25 @@
|
||||||
|
from django.urls import path
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from wagtail.snippets.views import chooser
|
||||||
|
|
||||||
from .views import choose_snippet_link_model, choose_snippet_embed_model
|
from .views import choose_snippet_link_model, choose_snippet_embed_model
|
||||||
|
|
||||||
|
|
||||||
app_name = "wagtaildraftailsnippet"
|
app_name = "wagtaildraftailsnippet"
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r"^choose-link-model/$", choose_snippet_link_model, name="choose-snippet-link-model"),
|
url(
|
||||||
url(r"^choose-embed-model/$", choose_snippet_embed_model, name="choose-snippet-embed-model"),
|
r"^choose-link-model/$",
|
||||||
|
choose_snippet_link_model,
|
||||||
|
name="choose-snippet-link-model",
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r"^choose-embed-model/$",
|
||||||
|
choose_snippet_embed_model,
|
||||||
|
name="choose-snippet-embed-model",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"choose/", chooser.ChooseView.as_view(), name="choose_generic"
|
||||||
|
), # This exists only to get the additional URL params added via JS in wagtail-draftail-snippet.js line 50
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,8 +8,10 @@ from wagtail.core import hooks
|
||||||
|
|
||||||
from . import urls
|
from . import urls
|
||||||
from .richtext import (
|
from .richtext import (
|
||||||
ContentstateSnippetLinkConversionRule, ContentstateSnippetEmbedConversionRule,
|
ContentstateSnippetLinkConversionRule,
|
||||||
SnippetLinkHandler, SnippetEmbedHandler,
|
ContentstateSnippetEmbedConversionRule,
|
||||||
|
SnippetLinkHandler,
|
||||||
|
SnippetEmbedHandler,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,18 +67,16 @@ def register_snippet_embed_feature(features):
|
||||||
|
|
||||||
@hooks.register("insert_editor_js")
|
@hooks.register("insert_editor_js")
|
||||||
def editor_js():
|
def editor_js():
|
||||||
return format_html(
|
|
||||||
"""
|
html = f"""
|
||||||
<script>
|
<script>
|
||||||
window.chooserUrls.snippetChooser = '{0}';
|
window.chooserUrls.snippetChooser = '{reverse('wagtaildraftailsnippet:choose_generic')}';
|
||||||
window.chooserUrls.snippetLinkModelChooser = '{1}';
|
window.chooserUrls.snippetLinkModelChooser = '{reverse("wagtaildraftailsnippet:choose-snippet-link-model")}';
|
||||||
window.chooserUrls.snippetEmbedModelChooser = '{2}';
|
window.chooserUrls.snippetEmbedModelChooser = '{reverse("wagtaildraftailsnippet:choose-snippet-embed-model")}';
|
||||||
</script>
|
</script>
|
||||||
""",
|
"""
|
||||||
reverse('wagtailsnippets:choose_generic'),
|
|
||||||
reverse("wagtaildraftailsnippet:choose-snippet-link-model"),
|
return format_html(html)
|
||||||
reverse("wagtaildraftailsnippet:choose-snippet-embed-model"),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.register("register_admin_urls")
|
@hooks.register("register_admin_urls")
|
||||||
|
|
Reference in a new issue