From c8d5fceea8addd93b9c9fa60ce904fbd616313b4 Mon Sep 17 00:00:00 2001 From: Marco Bonetti Date: Wed, 30 Nov 2022 14:14:26 +0100 Subject: [PATCH] fix: Delay importing models.CMSPlugin in utils. (#637) --- CHANGELOG.rst | 3 ++ djangocms_text_ckeditor/utils.py | 52 ++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 83cfcf91a..30f927c3c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,9 @@ Changelog Unreleased ========== +* Fix `468 `_ via `637 `_: Delay importing models.CMSPlugin in utils to allow adding an HTMLField to a custom user model. + + 5.1.1 (2022-06-22) ================== diff --git a/djangocms_text_ckeditor/utils.py b/djangocms_text_ckeditor/utils.py index 844965d37..3f4d99e83 100644 --- a/djangocms_text_ckeditor/utils.py +++ b/djangocms_text_ckeditor/utils.py @@ -8,19 +8,19 @@ from django.template.loader import render_to_string from django.utils.functional import LazyObject -from cms.models import CMSPlugin - from classytags.utils import flatten_context OBJ_ADMIN_RE_PATTERN = r'.*?' -OBJ_ADMIN_WITH_CONTENT_RE_PATTERN = r'(?P.*?)' +OBJ_ADMIN_WITH_CONTENT_RE_PATTERN = ( + r'(?P.*?)' +) OBJ_ADMIN_RE = re.compile(OBJ_ADMIN_RE_PATTERN, flags=re.DOTALL) def _render_cms_plugin(plugin, context): context = flatten_context(context) - context['plugin'] = plugin + context["plugin"] = plugin # This my fellow ckeditor enthusiasts is a hack.. @@ -34,9 +34,9 @@ def _render_cms_plugin(plugin, context): # and thus calls context processors AND render the plugin manually with the context # after it's been bound to a template. response = render_to_string( - 'cms/plugins/render_plugin_preview.html', + "cms/plugins/render_plugin_preview.html", context, - request=context['request'], + request=context["request"], ) return response @@ -49,10 +49,11 @@ def wrapped_view(*args, **kwargs): response = view_func(*args, **kwargs) response._random_comment_exempt = True return response + return wraps(view_func, assigned=WRAPPER_ASSIGNMENTS)(wrapped_view) -def plugin_to_tag(obj, content='', admin=False): +def plugin_to_tag(obj, content="", admin=False): plugin_attrs = OrderedDict( id=obj.pk, icon_alt=force_escape(obj.get_instance_icon_alt()), @@ -62,12 +63,12 @@ def plugin_to_tag(obj, content='', admin=False): if admin: # Include extra attributes when rendering on the admin plugin_class = obj.get_plugin_class() - preview = getattr(plugin_class, 'text_editor_preview', True) + preview = getattr(plugin_class, "text_editor_preview", True) plugin_tag = ( '%(content)s' ) - plugin_attrs['preview'] = 'true' if preview else 'false' + plugin_attrs["preview"] = "true" if preview else "false" else: plugin_tag = ( '