Skip to content

Commit 733bd84

Browse files
authored
fix: Proper registration of third-party RTE (CKEditor4 or 5, or other) (#47)
1 parent f2fbbac commit 733bd84

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
0.5.1 (30-12-2024)
6+
==================
7+
8+
* fix: Proper registration of third-party RTE (CKEditor4 or 5, or other) by @fsbraun in https://github.com/django-cms/djangocms-text/pull/47
9+
510
0.5.0 (28-12-2024)
611
==================
712

djangocms_text/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
10. Github actions will publish the new package to pypi
1717
"""
1818

19-
__version__ = "0.5.0"
19+
__version__ = "0.5.1"

djangocms_text/cms_plugins.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from . import settings
5050
from .forms import ActionTokenValidationForm, RenderPluginForm, TextForm
5151
from .html import render_dynamic_attributes
52-
from .models import Text
52+
from .models import Text, _MAX_RTE_LENGTH
5353
from .utils import (
5454
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN,
5555
_plugin_tags_to_html,
@@ -712,7 +712,7 @@ def save_model(self, request, obj, form, change):
712712
# subclassing cms_plugin_instance (one to one relation)
713713
value = getattr(self.cms_plugin_instance, field.name)
714714
setattr(obj, field.name, value)
715-
obj.rte = rte_config.name
715+
obj.rte = rte_config.name[:_MAX_RTE_LENGTH]
716716
super().save_model(request, obj, form, change)
717717
# This must come after calling save
718718
# If `clean_plugins()` deletes child plugins, django-treebeard will call

djangocms_text/editors.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,15 @@ def get_editor_config(editor: Optional[str] = None) -> RTEConfig:
485485
"""
486486

487487
config = editor or getattr(settings, "TEXT_EDITOR", "tiptap")
488-
if "." in config and config not in configuration:
488+
config_name = config.rsplit(".", 1)[-1]
489+
if config_name not in configuration:
489490
# Load the configuration from the module
490491
module = __import__(config.rsplit(".", 1)[0], fromlist=[""])
491-
rte_config_instance = getattr(module, config.rsplit(".", 1)[-1])
492+
rte_config_instance = getattr(module, config_name)
492493
# Cache editor configuration
493-
rte_config_instance.name = config
494+
rte_config_instance.name = config_name
494495
register(rte_config_instance)
495-
return configuration[config]
496+
return configuration[config_name]
496497

497498

498499
def get_editor_base_config(editor: Optional[str] = None) -> dict:

djangocms_text/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from django.utils.text import Truncator
88
from django.utils.translation import gettext_lazy as _
99

10+
11+
_MAX_RTE_LENGTH = 16
12+
13+
1014
if apps.is_installed("cms"):
1115
from cms.models import CMSPlugin
1216

@@ -52,7 +56,7 @@ class AbstractText(CMSPlugin):
5256
rte = models.CharField(
5357
default="",
5458
blank=True,
55-
max_length=16,
59+
max_length=_MAX_RTE_LENGTH,
5660
help_text="The rich text editor used to create this text. JSON formats vary between editors.",
5761
)
5862

private/css/cms.tiptap.css

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
max-width: 100%; /* for djangocms-admin-style */
1313

1414
.ProseMirror {
15+
height: 100%;
1516
overflow-y: scroll;
1617
padding: 0 0.5rem;
1718

tests/integration/test_ckeditor4.py

+16
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,19 @@ def handle_console_message(msg):
3737
expect(page.locator(".cke_button.cke_button__bold")).to_be_visible() # a button in the menu bar
3838

3939
assert not console_errors, f"Console errors found: {console_errors}"
40+
41+
42+
@pytest.mark.django_db
43+
@pytest.mark.skipif(not DJANGO_CMS4, reason="Integration tests only work on Django CMS 4")
44+
def test_editor_saves(live_server, page, text_plugin, superuser, use_ckeditor4):
45+
"""Test that tiptap editor loads and initializes properly"""
46+
# Navigate to the text plugin add view
47+
login(live_server, page, superuser)
48+
49+
page.goto(f"{live_server.url}{admin_reverse('cms_placeholder_edit_plugin', args=(text_plugin.pk,))}")
50+
51+
save_button = page.locator('input[type="submit"]')
52+
save_button.click()
53+
54+
messagelist = page.locator("div.messagelist")
55+
assert '<div class="success"></div>' in messagelist.inner_html().strip()

0 commit comments

Comments
 (0)