Skip to content

Commit ccebb38

Browse files
committed
fix: Common base class for custom components created
1 parent b85bf8c commit ccebb38

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

djangocms_frontend/common/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from djangocms_frontend import settings
44

5-
from .attributes import AttributesMixin, AttributesFormMixin
5+
from .attributes import AttributesFormMixin, AttributesMixin
66
from .title import TitleFormMixin, TitleMixin
77

88
__common = {

djangocms_frontend/component_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.utils.translation import gettext_lazy as _
1010
from entangled.forms import EntangledModelForm
1111

12-
from .ui_plugin_base import CMSUIPluginBase
12+
from .ui_plugin_base import CMSUIComponent
1313

1414

1515
def _import_or_empty(module, name):
@@ -134,7 +134,7 @@ def plugin_factory(cls) -> type:
134134
(
135135
*mixins,
136136
*cls._plugin_mixins,
137-
CMSUIPluginBase,
137+
CMSUIComponent,
138138
),
139139
{
140140
"name": getattr(cls._component_meta, "name", cls.__name__),
@@ -143,7 +143,7 @@ def plugin_factory(cls) -> type:
143143
"form": cls.admin_form_factory(),
144144
"allow_children": slots or getattr(cls._component_meta, "allow_children", False),
145145
"child_classes": getattr(cls._component_meta, "child_classes", []) + list(slots.keys()),
146-
"render_template": getattr(cls._component_meta, "render_template", CMSUIPluginBase.render_template),
146+
"render_template": getattr(cls._component_meta, "render_template", CMSUIComponent.render_template),
147147
"fieldsets": getattr(cls, "fieldsets", cls._generate_fieldset()),
148148
"change_form_template": "djangocms_frontend/admin/base.html",
149149
"slots": slots,
@@ -207,7 +207,7 @@ def get_short_description(self) -> str:
207207
def save_model(self, request, obj, form: forms.Form, change: bool) -> None:
208208
"""Auto-creates slot plugins upon creation of component plugin instance"""
209209

210-
super(CMSUIPluginBase, self).save_model(request, obj, form, change)
210+
super(CMSUIComponent, self).save_model(request, obj, form, change)
211211
if not change:
212212
for slot in self.slots.keys():
213213
add_plugin(obj.placeholder, slot, obj.language, target=obj)

djangocms_frontend/ui_plugin_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ def _get_object_for_single_field(self, object_id, language):
5656
from .models import FrontendUIItem
5757

5858
return FrontendUIItem.objects.get(pk=object_id)
59+
60+
61+
class CMSUIComponent(CMSUIPluginBase):
62+
pass

docs/source/custom_components.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _custom_components: Custom Components
1+
.. _custom_components:
22

33
#################
44
Custom Components

docs/source/getting_started.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,17 @@ repetition.
453453

454454
.. note::
455455

456-
To make plugins available as components, ensure that the
457-
``CMS_COMPONENT_PLUGINS`` setting in your project's ``settings.py``
458-
includes the necessary plugin classes and their subclasses. This setting
459-
allows you to specify which plugins can be used directly in templates
460-
without creating database entries. To include all djangocms-frontend
461-
plugins, use ``djangocms_frontend.cms_plugins.CMSUIPlugin`` in the setting.
456+
To make plugins available as components, ensure that the
457+
``CMS_COMPONENT_PLUGINS`` setting in your project's ``settings.py``
458+
includes the necessary plugin classes and their subclasses. This setting
459+
allows you to specify which plugins can be used directly in templates
460+
without creating database entries.
461+
462+
* To include all djangocms-frontend plugins, use
463+
``djangocms_frontend.cms_plugins.CMSUIPlugin`` in the setting.
464+
465+
* To include all :ref:`custom_components`, use
466+
``djangocms_frontend.cms_plugins.CMSUIComponent`` in the setting.
462467

463468
To use a frontend plugin in a template you need to load the ``frontend`` tags
464469
and then use the ``plugin`` template tag to render a frontend plugin.

tests/test_plugin_tag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def test_non_existing_plugin(self):
101101
This should not be rendered.
102102
{% endplugin %}
103103
""")
104-
expected_result = "<!-- Plugin \"nonexisting\" not found in pool for plugins usable with {% plugin %} -->"
104+
expected_result = ('<!-- To use "nonexisting" with the {% plugin %} template tag, add its plugin class to the '
105+
'CMS_COMPONENT_PLUGINS setting -->')
105106

106107
result = template.render({"request": None})
107108

0 commit comments

Comments
 (0)