Skip to content

Commit d2de207

Browse files
Copilotfsbraun
andauthored
fix: CarouselSlidePlugin and TabItemPlugin template retrieval to respect parent template setting (#314)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: fsbraun <[email protected]> Co-authored-by: Fabian Braun <[email protected]>
1 parent 9844b4c commit d2de207

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

djangocms_frontend/contrib/carousel/cms_plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ 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,
90+
# instance.parent or instance once django-cms 4.1 support can be dropped
9091
"carousel",
9192
"slide",
9293
CAROUSEL_TEMPLATE_CHOICES,

djangocms_frontend/contrib/tabs/cms_plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ 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,
75+
# instance.parent or instance once django-cms 4.1 support can be dropped
7576
"tabs",
7677
"item",
7778
TAB_TEMPLATE_CHOICES,

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

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+
config=dict(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+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)