Skip to content

Commit

Permalink
Merge 798829e into d123d11
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Mar 21, 2024
2 parents d123d11 + 798829e commit 7816b8b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
11 changes: 6 additions & 5 deletions cms/admin/placeholderadmin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import uuid
import warnings
from urllib.parse import parse_qsl, urlparse
Expand Down Expand Up @@ -34,7 +35,7 @@
from cms.models.pluginmodel import CMSPlugin
from cms.plugin_pool import plugin_pool
from cms.signals import post_placeholder_operation, pre_placeholder_operation
from cms.toolbar.utils import get_plugin_tree_as_json
from cms.toolbar.utils import get_plugin_tree
from cms.utils import get_current_site
from cms.utils.compat.warnings import RemovedInDjangoCMS50Warning
from cms.utils.conf import get_cms_setting
Expand Down Expand Up @@ -441,8 +442,8 @@ def copy_plugins(self, request):
source_placeholder,
target_placeholder,
)
data = get_plugin_tree_as_json(request, new_plugins)
return HttpResponse(data, content_type='application/json')
data = get_plugin_tree(request, new_plugins)
return HttpResponse(json.dumps(data), content_type='application/json')

def _copy_plugin_to_clipboard(self, request, target_placeholder):
source_language = request.POST['source_language']
Expand Down Expand Up @@ -724,8 +725,8 @@ def move_plugin(self, request):
if new_plugin and fetch_tree:
root = (new_plugin.parent or new_plugin)
new_plugins = [root] + list(root.get_descendants())
data = get_plugin_tree_as_json(request, new_plugins)
return HttpResponse(data, content_type='application/json')
data = get_plugin_tree(request, new_plugins)
return HttpResponse(json.dumps(data), content_type='application/json')

def _paste_plugin(self, request, plugin, target_language,
target_placeholder, target_position, target_parent=None):
Expand Down
7 changes: 3 additions & 4 deletions cms/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from cms import operations
from cms.exceptions import SubClassNeededError
from cms.models import CMSPlugin
from cms.toolbar.utils import get_plugin_toolbar_info, get_plugin_tree_as_json
from cms.toolbar.utils import get_plugin_toolbar_info, get_plugin_tree, get_plugin_tree_as_json
from cms.utils.conf import get_cms_setting


Expand Down Expand Up @@ -429,12 +429,11 @@ def render_close_frame(self, request, obj, extra_context=None):
parents=parent_classes,
)
data['plugin_desc'] = escapejs(force_str(obj.get_short_description()))

data['structure'] = get_plugin_tree(request, plugins)
context = {
'plugin': obj,
'is_popup': True,
'plugin_data': json.dumps(data),
'plugin_structure': get_plugin_tree_as_json(request, plugins),
'data_bridge': data,
}

if extra_context:
Expand Down
69 changes: 32 additions & 37 deletions cms/templates/admin/cms/page/close_frame.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
{% extends "admin/change_form.html" %}
{% load i18n l10n static cms_static %}

{% block title %}{% trans "Change a page" %}{% endblock %}

{% block content %}
{# trick for cms to understand that the plugin was actually correctly saved #}
<div class="messagelist">
<div class="success"></div>
</div>
<script>
window.CMS || window.parent.CMS || document.write(
'<script src="{% static_with_version "cms/js/dist/bundle.admin.base.min.js" %}" type="text/javascript"><\/script>'
);
</script>
<script>
// we have a special case here cause the CMS namespace
// can be either inside the current window or the parent
(function(Window) {
// the dataBridge is used to access plugin information from different resources
// Do NOT move this!!!
Window.CMS.API.Helpers.dataBridge = {{ plugin_data|safe }};

{% if plugin_structure %}
Window.CMS.API.Helpers.dataBridge.structure = {{ plugin_structure|safe }};
{% endif %}

Window.CMS.$(document).ready(function () {
// make sure we're doing after the "modal" mechanism kicked in
setTimeout(function () {
// save current plugin
Window.CMS.API.Helpers.onPluginSave();
}, 100);
});
})(window.parent || window);
</script>
{% endblock %}
{% load i18n l10n static cms_static %}{% spaceless %}
<html>
<body>
{# trick for cms to understand that the plugin was actually correctly saved #}
<div class="messagelist">
<div class="success"></div>
</div>
{{ data_bridge|json_script:"data-bridge" }}
<script>
window.CMS || window.parent.CMS || document.write(
'<script src="{% static_with_version "cms/js/dist/bundle.admin.base.min.js" %}" type="text/javascript"><\/script>'
);
</script>
<script>
// we have a special case here cause the CMS namespace
// can be either inside the current window or the parent
(function(Window) {
// the dataBridge is used to access plugin information from different resources
// Do NOT move this!!!
Window.CMS.API.Helpers.dataBridge = JSON.parse(document.getElementById('data-bridge').textContent);
Window.CMS.$(document).ready(function () {
// make sure we're doing after the "modal" mechanism kicked in
setTimeout(function () {
// save current plugin
Window.CMS.API.Helpers.onPluginSave();
}, 100);
});
})(window.parent || window);
</script>
</body>
</html>
{% endspaceless %}
11 changes: 10 additions & 1 deletion cms/toolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from cms.constants import PLACEHOLDER_TOOLBAR_JS, PLUGIN_TOOLBAR_JS
from cms.models import PageContent
from cms.utils import get_language_list
from cms.utils.compat.warnings import RemovedInDjangoCMS43Warning
from cms.utils.conf import get_cms_setting
from cms.utils.urlutils import admin_reverse

Expand Down Expand Up @@ -64,6 +65,14 @@ def get_plugin_toolbar_js(plugin, children=None, parents=None):


def get_plugin_tree_as_json(request, plugins):
import warnings

warnings.warn("get_plugin_tree_as_json is deprecated. Use get_plugin_tree instead.",
RemovedInDjangoCMS43Warning, stacklevel=2)
return json.dumps(get_plugin_tree(request, plugins))


def get_plugin_tree(request, plugins):
from cms.utils.plugins import downcast_plugins, get_plugin_restrictions

tree_data = []
Expand Down Expand Up @@ -116,7 +125,7 @@ def collect_plugin_data(plugin):
}
tree_structure.append(template.render(context))
tree_data.reverse()
return json.dumps({'html': '\n'.join(tree_structure), 'plugins': tree_data})
return {'html': '\n'.join(tree_structure), 'plugins': tree_data}


def get_toolbar_from_request(request):
Expand Down

0 comments on commit 7816b8b

Please sign in to comment.