Skip to content

Commit 3937f62

Browse files
committed
Update docs
1 parent 793ae0b commit 3937f62

File tree

11 files changed

+34
-15
lines changed

11 files changed

+34
-15
lines changed

djangocms_frontend/common/bootstrap5/spacing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class Meta:
196196
margin_devices = DeviceChoiceField(
197197
label=_("Apply margin on device"),
198198
required=False,
199+
initial=[size for size, _ in settings.DEVICE_CHOICES],
199200
help_text=_(
200201
"Select only devices on which the margin should be applied. On other devices "
201202
"larger than the first selected device the margin will be set to zero."
@@ -228,6 +229,7 @@ class Meta:
228229
padding_devices = DeviceChoiceField(
229230
label=_("Apply padding on device"),
230231
required=False,
232+
initial=[size for size, _ in settings.DEVICE_CHOICES],
231233
help_text=_(
232234
"Select only devices on which the padding should be applied. On other devices "
233235
"larger than the first selected device the padding will be set to zero."

djangocms_frontend/component_base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class CMSFrontendComponent(forms.Form):
5050
_admin_form = None
5151
_model = None
5252
_plugin = None
53+
META_FIELDS = ["is_local", "disable_edit", "disable_child_plugins", "show_plugin_add_form",
54+
"frontend_editable_fields", "link_fieldset_position", "require_parent",
55+
"parent_classes"]
5356

5457
@classmethod
5558
def admin_form_factory(cls, **kwargs) -> type:
@@ -138,17 +141,17 @@ def plugin_factory(cls) -> type:
138141
"module": getattr(cls._component_meta, "module", _("Components")),
139142
"model": cls.plugin_model_factory(),
140143
"form": cls.admin_form_factory(),
141-
"allow_children": getattr(cls._component_meta, "allow_children", False) or slots,
142-
"require_parent": getattr(cls._component_meta, "require_parent", False),
144+
"allow_children": slots or getattr(cls._component_meta, "allow_children", False),
143145
"child_classes": getattr(cls._component_meta, "child_classes", []) + list(slots.keys()),
144-
"parent_classes": getattr(cls._component_meta, "parent_classes", []),
145146
"render_template": getattr(cls._component_meta, "render_template", CMSUIPluginBase.render_template),
146147
"fieldsets": getattr(cls, "fieldsets", cls._generate_fieldset()),
147148
"change_form_template": "djangocms_frontend/admin/base.html",
148149
"slots": slots,
149-
"frontend_editable_fields": getattr(cls._component_meta, "frontend_editable_fields", []),
150150
"save_model": cls.save_model,
151-
"link_fieldset_position": getattr(cls._component_meta, "link_fieldset_position", 1),
151+
**{
152+
field: getattr(cls._component_meta, field) for field in cls.META_FIELDS
153+
if hasattr(cls._component_meta, field)
154+
},
152155
**(
153156
{
154157
"get_render_template": cls.get_render_template,

djangocms_frontend/contrib/accordion/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Meta:
7676

7777
accordion_item_header = forms.CharField(
7878
label=_("Header"),
79+
initial=_("New accordion item"),
7980
required=True,
8081
)
8182
accordion_item_open = forms.BooleanField(

djangocms_frontend/contrib/accordion/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ class Meta:
1313
proxy = True
1414
verbose_name = _("Accordion")
1515

16-
def get_children_count(self):
17-
return self.cmsplugin_set.count()
18-
1916
def get_short_description(self):
20-
return _("({} entries)").format(self.get_children_count())
17+
return _("({} entries)").format(len(self.child_plugin_instances or []))
2118

2219

2320
class AccordionItem(FrontendUIItem):

djangocms_frontend/contrib/utilities/cms_plugins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class HeadingPlugin(mixin_factory("Heading"), AttributesMixin, SpacingMixin, CMS
6262

6363
render_template = "djangocms_frontend/heading.html"
6464
allow_children = True
65+
is_local = False
6566

6667
fieldsets = [
6768
(
@@ -129,6 +130,7 @@ class TOCPlugin(mixin_factory("TOC"), AttributesMixin, CMSUIPlugin):
129130

130131
fieldsets = settings.EMPTY_FIELDSET
131132
edit_disabled = True
133+
is_local = False
132134

133135
def render(self, context, instance, placeholder):
134136
if hasattr(context["request"], "TOC"):

djangocms_frontend/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_related_object(scope, field_name):
2626
try:
2727
Model = apps.get_model(scope[field_name]["model"])
2828
relobj = Model.objects.get(pk=scope[field_name]["pk"])
29-
except (ObjectDoesNotExist, LookupError):
29+
except (ObjectDoesNotExist, LookupError, TypeError):
3030
relobj = None
3131
return relobj
3232

djangocms_frontend/templatetags/frontend.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,17 @@ class Plugin(AsTag):
156156
)
157157

158158
def message(self, message):
159+
import warnings
160+
161+
warnings.warn(message, stacklevel=5)
159162
return f"<!-- {message} -->" if django_settings.DEBUG else ""
160163

161164
def get_value(self, context, name, kwargs, nodelist):
162165
from djangocms_frontend.plugin_tag import plugin_tag_pool
163166

164167
if name not in plugin_tag_pool:
165-
return self.message(f'Plugin "{name}" not found in pool for plugins usable with {{% plugin %}}')
168+
return self.message(f'To use "{name}" with the {{% plugin %}} template tag, add its plugin class to '
169+
f'the CMS_COMPONENT_PLUGINS setting')
166170
context.push()
167171
instance = plugin_tag_pool[name]["defaults"]
168172
plugin_class = plugin_tag_pool[name]["class"]

docs/source/components.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ documentation.
1717

1818
.. note::
1919

20-
Custom components can easily be added using the components contrib
21-
package. For more information see :ref:`custom_components`.
20+
Custom components can easily be added using :ref:`custom_components`.
2221

2322
.. index::
2423
single: Accordion

docs/source/custom_components.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _custom_components: Custom Components
2+
13
#################
24
Custom Components
35
#################

docs/source/getting_started.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,21 @@ otherwise. This is useful if you want use exactly the same markup for, say,
445445
buttons, links, the grid both in pages managed with django CMS and in
446446
other parts of your project without duplicating HTML code.
447447

448-
This feature introduces a simple and flexible way to re-use djangocms-frontend
448+
This feature introduces a simple and flexible way to reuse django CMS
449449
plugins directly in templates without needing to create database entries for
450450
them. This allows developers to maintain clean, reusable, and dynamic
451451
components, such as buttons, cards, links, and more, while minimizing code
452452
repetition.
453453

454+
.. note::
455+
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.
462+
454463
To use a frontend plugin in a template you need to load the ``frontend`` tags
455464
and then use the ``plugin`` template tag to render a frontend plugin.
456465

0 commit comments

Comments
 (0)