Skip to content

Commit f02acbc

Browse files
Copilotfsbraun
andcommitted
Fix template retrieval for CarouselSlide and TabItem plugins
Co-authored-by: fsbraun <[email protected]>
1 parent c127133 commit f02acbc

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

djangocms_frontend/contrib/carousel/cms_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CarouselSlidePlugin(
8686

8787
def get_render_template(self, context, instance, placeholder):
8888
return get_plugin_template(
89-
instance.parent or instance,
89+
instance.parent.get_plugin_instance()[0] if instance.parent else instance,
9090
"carousel",
9191
"slide",
9292
CAROUSEL_TEMPLATE_CHOICES,

djangocms_frontend/contrib/tabs/cms_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TabItemPlugin(mixin_factory("TabItem"), AttributesMixin, PaddingMixin, CMS
7171

7272
def get_render_template(self, context, instance, placeholder):
7373
return get_plugin_template(
74-
instance.parent or instance,
74+
instance.parent.get_plugin_instance()[0] if instance.parent else instance,
7575
"tabs",
7676
"item",
7777
TAB_TEMPLATE_CHOICES,

tests/carousel/test_plugins.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from cms.api import add_plugin
22
from cms.test_utils.testcases import CMSTestCase
3+
from django.test import override_settings
34

45
from djangocms_frontend.contrib.carousel.cms_plugins import (
56
CarouselPlugin,
67
CarouselSlidePlugin,
78
)
9+
from djangocms_frontend.contrib.carousel.constants import CAROUSEL_TEMPLATE_CHOICES
810
from djangocms_frontend.contrib.carousel.forms import CarouselForm, CarouselSlideForm
911

1012
from ..fixtures import TestFixture
@@ -129,3 +131,47 @@ def test_carousel_slide_plugin(self):
129131
response = self.client.get(self.request_url)
130132
self.assertEqual(response.status_code, 200)
131133
self.assertContains(response, 'href="https://www.divio.com"')
134+
135+
@override_settings(
136+
DJANGOCMS_FRONTEND_CAROUSEL_TEMPLATES=(
137+
("default", "Default"),
138+
("custom", "Custom"),
139+
)
140+
)
141+
def test_carousel_slide_inherits_parent_template(self):
142+
"""Test that CarouselSlidePlugin correctly retrieves parent's template."""
143+
# Create a carousel with a custom template
144+
carousel = add_plugin(
145+
placeholder=self.placeholder,
146+
plugin_type=CarouselPlugin.__name__,
147+
language=self.language,
148+
template="custom",
149+
)
150+
carousel.initialize_from_form(CarouselForm).save()
151+
152+
# Create a slide as child of the carousel
153+
slide = add_plugin(
154+
target=carousel,
155+
placeholder=self.placeholder,
156+
plugin_type=CarouselSlidePlugin.__name__,
157+
language=self.language,
158+
config=dict(carousel_image=dict(pk=self.image.id, model="filer.Image")),
159+
)
160+
slide.initialize_from_form(CarouselSlideForm).save()
161+
162+
# Get the plugin instance
163+
plugin_instance = CarouselSlidePlugin()
164+
165+
# Test that get_render_template uses the parent's template
166+
template_path = plugin_instance.get_render_template(
167+
context={},
168+
instance=slide,
169+
placeholder=self.placeholder
170+
)
171+
172+
# The template path should use 'custom' from the parent, not 'default'
173+
self.assertIn("custom", template_path)
174+
self.assertEqual(
175+
template_path,
176+
"djangocms_frontend/bootstrap5/carousel/custom/slide.html"
177+
)

tests/tabs/test_plugins.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from cms.api import add_plugin
22
from cms.test_utils.testcases import CMSTestCase
3+
from django.test import override_settings
34

45
from djangocms_frontend.contrib.tabs.cms_plugins import TabItemPlugin, TabPlugin
56
from djangocms_frontend.contrib.tabs.forms import TabForm, TabItemForm
@@ -42,3 +43,47 @@ def test_tab_item_plugin(self):
4243
self.assertEqual(response.status_code, 200)
4344
self.assertContains(response, '<div class="tab-content">')
4445
self.assertContains(response, "tab-pane")
46+
47+
@override_settings(
48+
DJANGOCMS_FRONTEND_TAB_TEMPLATES=(
49+
("default", "Default"),
50+
("custom", "Custom"),
51+
)
52+
)
53+
def test_tab_item_inherits_parent_template(self):
54+
"""Test that TabItemPlugin correctly retrieves parent's template."""
55+
# Create a tab container with a custom template
56+
tab_container = add_plugin(
57+
placeholder=self.placeholder,
58+
plugin_type=TabPlugin.__name__,
59+
language=self.language,
60+
template="custom",
61+
)
62+
tab_container.initialize_from_form(TabForm).save()
63+
64+
# Create a tab item as child of the tab container
65+
tab_item = add_plugin(
66+
target=tab_container,
67+
placeholder=self.placeholder,
68+
plugin_type=TabItemPlugin.__name__,
69+
language=self.language,
70+
config=dict(tab_title="Test Tab"),
71+
)
72+
tab_item.initialize_from_form(TabItemForm).save()
73+
74+
# Get the plugin instance
75+
plugin_instance = TabItemPlugin()
76+
77+
# Test that get_render_template uses the parent's template
78+
template_path = plugin_instance.get_render_template(
79+
context={},
80+
instance=tab_item,
81+
placeholder=self.placeholder
82+
)
83+
84+
# The template path should use 'custom' from the parent, not 'default'
85+
self.assertIn("custom", template_path)
86+
self.assertEqual(
87+
template_path,
88+
"djangocms_frontend/bootstrap5/tabs/custom/item.html"
89+
)

0 commit comments

Comments
 (0)