Skip to content

Commit

Permalink
Allow get_render_template for components
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 29, 2024
1 parent 5012df4 commit fcffc51
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions djangocms_frontend/contrib/component/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _get_mixin_classes(mixins: list, suffix: str = "") -> list[type]:

class Slot:
"""Slat class as syntactic surgar to more easily define slot plugins"""

def __init__(self, name, verbose_name, **kwargs):
self.name = name
self.verbose_name = verbose_name
Expand Down Expand Up @@ -67,22 +68,24 @@ def admin_form_factory(cls, **kwargs) -> type:

@classmethod
def get_slot_plugins(cls) -> dict[str:str]:
slots : list[Slot] = [
slots: list[Slot] = [
slot if isinstance(slot, Slot) else Slot(*slot) for slot in getattr(cls._component_meta, "slots", [])
]
return {
f"{cls.__name__}{slot.name.capitalize()}Plugin": slot for slot in slots
}
return {f"{cls.__name__}{slot.name.capitalize()}Plugin": slot for slot in slots}

@classmethod
def plugin_model_factory(cls) -> type:
from djangocms_frontend.models import FrontendUIItem

app_config = apps.get_containing_app_config(cls.__module__)
if app_config is None:
raise ValueError(f"Cannot find app_config for {cls.__module__}")

Check warning on line 82 in djangocms_frontend/contrib/component/components.py

View check run for this annotation

Codecov / codecov/patch

djangocms_frontend/contrib/component/components.py#L82

Added line #L82 was not covered by tests
model_class = type(
cls.__name__,
(*cls._model_mixins, FrontendUIItem,),
(
*cls._model_mixins,
FrontendUIItem,
),
{
"Meta": type(
"Meta",
Expand Down Expand Up @@ -129,6 +132,14 @@ def plugin_factory(cls) -> type:
"frontend_editable_fields": getattr(cls._component_meta, "frontend_editable_fields", []),
"save_model": cls.save_model,
"link_fieldset_position": getattr(cls._component_meta, "link_fieldset_position", 1),
**(
{
"get_render_template": cls.get_render_template,
"TEMPLATES": cls.TEMPLATES,
}
if hasattr(cls, "get_render_template")
else {}
),
},
)

Expand All @@ -146,7 +157,7 @@ def slot_plugin_factory(cls) -> list[type]:
"edit_disabled": True,
"parent_classes": cls.__name__ + "Plugin",
"render_template": cls.slot_template,
**slot.kwargs
**slot.kwargs,
},
)
for name, slot in slots.items()
Expand Down

0 comments on commit fcffc51

Please sign in to comment.