From f265e24c9b4015f7af2508d31f933acc9cf53bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20B=C3=B6hm?= Date: Wed, 21 May 2025 18:02:05 +0200 Subject: [PATCH] Fix AttributeError CMSPlugin (EditorNotePlugin) object has no attribute config. --- djangocms_frontend/ui_plugin_base.py | 14 ++++++++------ tests/test_settings.py | 2 ++ tests/utilities/test_plugins.py | 1 - 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/djangocms_frontend/ui_plugin_base.py b/djangocms_frontend/ui_plugin_base.py index c884232a..16881d8d 100644 --- a/djangocms_frontend/ui_plugin_base.py +++ b/djangocms_frontend/ui_plugin_base.py @@ -3,6 +3,7 @@ from django.utils.encoding import force_str from djangocms_frontend.helpers import get_related +from djangocms_frontend.models import AbstractFrontendUIItem try: from cms.admin.placeholderadmin import PlaceholderAdmin @@ -30,12 +31,13 @@ def __str__(self): return force_str(super().__str__()) def render(self, context, instance, placeholder): - for key, value in instance.config.items(): - if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}: - if key not in instance.__dir__(): # hasattr would return the value in the config dict - setattr(instance.__class__, key, get_related(key)) - if "instance" not in instance.config and isinstance(instance.config, dict): - context.update(instance.config) + if isinstance(instance, AbstractFrontendUIItem): + for key, value in instance.config.items(): + if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}: + if key not in instance.__dir__(): # hasattr would return the value in the config dict + setattr(instance.__class__, key, get_related(key)) + if "instance" not in instance.config and isinstance(instance.config, dict): + context.update(instance.config) return super().render(context, instance, placeholder) if not hasattr(PlaceholderAdmin, "edit_field"): diff --git a/tests/test_settings.py b/tests/test_settings.py index 0b13d57a..658c852e 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -119,6 +119,8 @@ SITE_ID = 1 +STATIC_URL = "/static/" + ROOT_URLCONF = "tests.urls" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/tests/utilities/test_plugins.py b/tests/utilities/test_plugins.py index a63799c6..75bfc722 100644 --- a/tests/utilities/test_plugins.py +++ b/tests/utilities/test_plugins.py @@ -164,6 +164,5 @@ def test_editor_note_with_cms4(self): with self.login_user_context(self.superuser): response = self.client.get(endpoint) - print(response.content) self.assertEqual(response.status_code, 200) self.assertContains(response, 'My private note')