Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Proper registration of third-party RTE (CKEditor4 or 5, or other) #47

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

0.5.1 (30-12-2024)
==================

* fix: Proper registration of third-party RTE (CKEditor4 or 5, or other) by @fsbraun in https://github.com/django-cms/djangocms-text/pull/47

0.5.0 (28-12-2024)
==================

Expand Down
2 changes: 1 addition & 1 deletion djangocms_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
10. Github actions will publish the new package to pypi
"""

__version__ = "0.5.0"
__version__ = "0.5.1"
4 changes: 2 additions & 2 deletions djangocms_text/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from . import settings
from .forms import ActionTokenValidationForm, RenderPluginForm, TextForm
from .html import render_dynamic_attributes
from .models import Text
from .models import Text, _MAX_RTE_LENGTH
from .utils import (
OBJ_ADMIN_WITH_CONTENT_RE_PATTERN,
_plugin_tags_to_html,
Expand Down Expand Up @@ -712,7 +712,7 @@ def save_model(self, request, obj, form, change):
# subclassing cms_plugin_instance (one to one relation)
value = getattr(self.cms_plugin_instance, field.name)
setattr(obj, field.name, value)
obj.rte = rte_config.name
obj.rte = rte_config.name[:_MAX_RTE_LENGTH]
super().save_model(request, obj, form, change)
# This must come after calling save
# If `clean_plugins()` deletes child plugins, django-treebeard will call
Expand Down
9 changes: 5 additions & 4 deletions djangocms_text/editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,15 @@ def get_editor_config(editor: Optional[str] = None) -> RTEConfig:
"""

config = editor or getattr(settings, "TEXT_EDITOR", "tiptap")
if "." in config and config not in configuration:
config_name = config.rsplit(".", 1)[-1]
if config_name not in configuration:
# Load the configuration from the module
module = __import__(config.rsplit(".", 1)[0], fromlist=[""])
rte_config_instance = getattr(module, config.rsplit(".", 1)[-1])
rte_config_instance = getattr(module, config_name)
# Cache editor configuration
rte_config_instance.name = config
rte_config_instance.name = config_name
register(rte_config_instance)
return configuration[config]
return configuration[config_name]


def get_editor_base_config(editor: Optional[str] = None) -> dict:
Expand Down
6 changes: 5 additions & 1 deletion djangocms_text/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from django.utils.text import Truncator
from django.utils.translation import gettext_lazy as _


_MAX_RTE_LENGTH = 16


if apps.is_installed("cms"):
from cms.models import CMSPlugin

Expand Down Expand Up @@ -52,7 +56,7 @@ class AbstractText(CMSPlugin):
rte = models.CharField(
default="",
blank=True,
max_length=16,
max_length=_MAX_RTE_LENGTH,
help_text="The rich text editor used to create this text. JSON formats vary between editors.",
)

Expand Down
1 change: 1 addition & 0 deletions private/css/cms.tiptap.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
max-width: 100%; /* for djangocms-admin-style */

.ProseMirror {
height: 100%;
overflow-y: scroll;
padding: 0 0.5rem;

Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_ckeditor4.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ def handle_console_message(msg):
expect(page.locator(".cke_button.cke_button__bold")).to_be_visible() # a button in the menu bar

assert not console_errors, f"Console errors found: {console_errors}"


@pytest.mark.django_db
@pytest.mark.skipif(not DJANGO_CMS4, reason="Integration tests only work on Django CMS 4")
def test_editor_saves(live_server, page, text_plugin, superuser, use_ckeditor4):
"""Test that tiptap editor loads and initializes properly"""
# Navigate to the text plugin add view
login(live_server, page, superuser)

page.goto(f"{live_server.url}{admin_reverse('cms_placeholder_edit_plugin', args=(text_plugin.pk,))}")

save_button = page.locator('input[type="submit"]')
save_button.click()

messagelist = page.locator("div.messagelist")
assert '<div class="success"></div>' in messagelist.inner_html().strip()
Loading