Skip to content

Commit 0160a9d

Browse files
committed
fix: Allow adding plugins to CMS_COMPONENT_PLUGINS by just their name
1 parent 434ec8a commit 0160a9d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

djangocms_frontend/plugin_tag.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
"ui_item",
2626
)
2727

28-
allowed_plugin_types = tuple(
29-
getattr(importlib.import_module(cls.rsplit(".", 1)[0]), cls.rsplit(".", 1)[-1]) if isinstance(cls, str) else cls
30-
for cls in getattr(settings, "CMS_COMPONENT_PLUGINS", [])
31-
)
32-
3328

3429
def _get_plugindefaults(instance):
3530
defaults = {
@@ -65,7 +60,20 @@ def patch_template(template):
6560
return copied_template if patch else template
6661

6762

63+
def get_plugin_class(settings_string: str | type) -> type:
64+
"""Get the plugin class from the settings string or import it if it's a dotted path."""
65+
if isinstance(settings_string, str):
66+
if "." in settings_string:
67+
# import the class if a dotted oath is given
68+
return importlib.import_module(*settings_string.rsplit(".", 1))
69+
# Get the plugin class from the plugin pool by its name
70+
return plugin_pool.get_plugin(settings_string)
71+
return settings_string
72+
73+
6874
def setup():
75+
allowed_plugin_types = tuple(get_plugin_class(cls) for cls in getattr(settings, "CMS_COMPONENT_PLUGINS", []))
76+
6977
for plugin in plugin_pool.get_all_plugins():
7078
if not issubclass(plugin, allowed_plugin_types):
7179
continue

docs/source/how-to/use-frontend-as-component.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ repetition.
2222

2323
To make plugins available as components, ensure that the
2424
``CMS_COMPONENT_PLUGINS`` setting in your project's ``settings.py``
25-
includes the necessary plugin classes and their subclasses. This setting
26-
allows you to specify which plugins can be used directly in templates
25+
is a list that includes the necessary plugin names or dotted path to
26+
a plugin parent class . Only plugins named in the listing or their
27+
child classes can be used directly in templates
2728
without creating database entries.
2829

2930
* To include all ``djangocms-frontend`` plugins, use

0 commit comments

Comments
 (0)