Skip to content

Commit

Permalink
Merge eaa4edd into 5ce5586
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed May 7, 2024
2 parents 5ce5586 + eaa4edd commit a6d41a1
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 62 deletions.
14 changes: 8 additions & 6 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 All @@ -17,7 +18,7 @@
)
from django.shortcuts import get_list_or_404, get_object_or_404, render
from django.template.response import TemplateResponse
from django.urls import re_path
from django.urls import include, re_path
from django.utils.decorators import method_decorator
from django.utils.encoding import force_str
from django.utils.html import conditional_escape
Expand All @@ -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 @@ -221,6 +222,7 @@ def get_urls(self):
def pat(regex, fn):
return re_path(regex, self.admin_site.admin_view(fn), name="%s_%s" % (info, fn.__name__))
url_patterns = [
re_path(r'^cms_wizard/', include('cms.wizards.urls')),
pat(r'^copy-plugins/$', self.copy_plugins),
pat(r'^add-plugin/$', self.add_plugin),
pat(r'^edit-plugin/([0-9]+)/$', self.edit_plugin),
Expand Down Expand Up @@ -451,8 +453,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 @@ -734,8 +736,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: 5 additions & 2 deletions cms/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def add_wizard_button(self):
disabled = True

url = '{url}?page={page}&language={lang}&edit'.format(
url=reverse("cms_wizard_create"),
url=admin_reverse("cms_wizard_create"),
page=page_pk,
lang=self.toolbar.site_language,
)
Expand Down Expand Up @@ -435,7 +435,10 @@ def get_on_delete_redirect_url(self):

# else redirect to root, do not redirect to Page.objects.get_home() because user could have deleted the last
# page, if DEBUG == False this could cause a 404
return reverse('pages-root')
try:
return reverse('pages-root')
except NoReverseMatch:
return admin_reverse("cms_pagecontent_changelist")

@property
def title(self):
Expand Down
22 changes: 14 additions & 8 deletions cms/models/pagemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db.models.base import ModelState
from django.db.models.functions import Concat
from django.forms import model_to_dict
from django.urls import reverse
from django.urls import NoReverseMatch, reverse
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.utils.timezone import now
Expand Down Expand Up @@ -360,10 +360,13 @@ def get_absolute_url(self, language=None, fallback=True):
language = get_current_language()

with force_language(language):
if self.is_home:
return reverse('pages-root')
path = self.get_path(language, fallback) or self.get_slug(language, fallback) # TODO: Disallow get_slug
return reverse('pages-details-by-slug', kwargs={"slug": path}) if path else None
try:
if self.is_home:
return reverse('pages-root')
path = self.get_path(language, fallback) or self.get_slug(language, fallback) # TODO: Disallow get_slug
return reverse('pages-details-by-slug', kwargs={"slug": path}) if path else None
except NoReverseMatch:
return None

def set_tree_node(self, site, target=None, position='first-child'):
assert position in ('last-child', 'first-child', 'left', 'right')
Expand Down Expand Up @@ -1085,9 +1088,12 @@ def get_absolute_url(self, language=None, fallback=True):
language = get_current_language()

with force_language(language):
if self.path == '':
return reverse('pages-root')
return reverse('pages-details-by-slug', kwargs={"slug": self.path})
try:
if self.path == '':
return reverse('pages-root')
return reverse('pages-details-by-slug', kwargs={"slug": self.path})
except NoReverseMatch:
return None

def get_path_for_base(self, base_path=''):
old_base, sep, slug = self.path.rpartition('/')
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 %}
2 changes: 1 addition & 1 deletion cms/templates/cms/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h2 class="cms-hidden">{% trans "Installation Notes" %}</h2>
e.preventDefault();
var modal = new CMS.Modal();
modal.open({
url: '{% url "cms_wizard_create" %}?language={{ LANGUAGE_CODE }}',
url: '{% url "admin:cms_wizard_create" %}?language={{ LANGUAGE_CODE }}',
title: '{% trans "Welcome to django CMS" %}'
});
});
Expand Down
2 changes: 1 addition & 1 deletion cms/templates/cms/wizards/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block wizard %}
<h1>{% trans "Create" %} {{ wizard_entry.title }}</h1>

<form action="{% url 'cms_wizard_create' %}" method="post" enctype="multipart/form-data" novalidate>
<form action="{% url 'admin:cms_wizard_create' %}" method="post" enctype="multipart/form-data" novalidate>
{% csrf_token %}

{{ wizard.management_form }}
Expand Down
2 changes: 1 addition & 1 deletion cms/templates/cms/wizards/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block wizard %}
<h1>{% trans "Create" %}</h1>

<form action="{% url 'cms_wizard_create' %}" method="post" class="modal-body">
<form action="{% url 'admin:cms_wizard_create' %}" method="post" class="modal-body">
{% csrf_token %}
{{ wizard.management_form }}
{{ form.page }}
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_get_model(self):
self.title_wizard.get_model()

def test_endpoint_auth_required(self):
endpoint = reverse('cms_wizard_create')
endpoint = reverse('admin:cms_wizard_create')
staff_active = self._create_user("staff-active", is_staff=True, is_superuser=False, is_active=True)

response = self.client.get(endpoint)
Expand Down
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
48 changes: 48 additions & 0 deletions docs/upgrade/4.2.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. _upgrade-to-4.2:

*******************
4.2.0 release notes
*******************

*December 20, 2024*

Welcome to django CMS 4.2!

These release notes cover the new features, as well as some backwards
incompatible changes you’ll want to be aware of when upgrading from
django CMS 4.1. If you are upgrading from django CMS 3.11 or earlier
please urgently read the release notes of django CMS 4.0.


Django and Python compatibility
===============================

django CMS supports **Django 4.2 to 5.1**. We highly recommend and only
support the latest release of each series.

It supports **Python 3.10, 3.11, and 3.12**. As for Django we highly recommend and only
support the latest release of each series.

What's new in 4.2
=================

Support of headless projects
----------------------------

* ...

Bug Fixes
---------

* ...

Backward incompatible changes in 4.2
====================================

Wizards
-------

The wizard system's urls have been moved to the placeholder admin. As a
consequence it's reverse name has changed from ``cms_wizard_create`` to
``admin:cms_wizard_create``. If you are accessing the the create wizard url
directly in your project you will need to update the reverse name.

0 comments on commit a6d41a1

Please sign in to comment.