Skip to content

Commit 3e44163

Browse files
authored
fix: Carousel (#100)
* Fix: github actions * Fix: remove 4.1 from tests * Fix setup.py * Fix .tx/config * Fix: Allow other classes than "collapse" for fieldsets in tabbed admin * Fix carousel * Fix: isort * Simpler form * Update tests
1 parent 0549116 commit 3e44163

File tree

10 files changed

+59
-33
lines changed

10 files changed

+59
-33
lines changed

djangocms_frontend/contrib/carousel/cms_plugins.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ... import settings
77
from ...cms_plugins import CMSUIPlugin
88
from ...common.attributes import AttributesMixin
9+
from ...common.background import BackgroundMixin
910
from .. import carousel
1011
from ..link.cms_plugins import LinkPluginMixin
1112
from . import forms, models
@@ -37,7 +38,8 @@ class CarouselPlugin(mixin_factory("Carousel"), AttributesMixin, CMSUIPlugin):
3738
("carousel_aspect_ratio", "carousel_interval"),
3839
("carousel_controls", "carousel_indicators"),
3940
("carousel_keyboard", "carousel_wrap"),
40-
("carousel_ride", "carousel_pause"),
41+
("carousel_ride",),
42+
("carousel_transition", "carousel_pause",),
4143
)
4244
},
4345
),
@@ -51,7 +53,7 @@ def get_render_template(self, context, instance, placeholder):
5153

5254
@plugin_pool.register_plugin
5355
class CarouselSlidePlugin(
54-
mixin_factory("CarouselSlide"), AttributesMixin, LinkPluginMixin, CMSUIPlugin
56+
mixin_factory("CarouselSlide"), AttributesMixin, BackgroundMixin, LinkPluginMixin, CMSUIPlugin
5557
):
5658
"""
5759
Components > "Carousel Slide" Plugin

djangocms_frontend/contrib/carousel/constants.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22
from django.utils.translation import gettext_lazy as _
33

44
CAROUSEL_PAUSE_CHOICES = (
5-
("hover", "hover"),
6-
("mouseenter", "mouseenter"),
7-
("mouseleave", "mouseleave"),
8-
("false", "off"),
9-
)
10-
11-
CAROUSEL_RIDE_CHOICES = (
12-
("carousel", "carousel"),
13-
("false", "off"),
5+
("hover", _("On hover")),
6+
("false", _("Never")),
147
)
158

169
CAROUSEL_TEMPLATE_CHOICES = getattr(
@@ -38,3 +31,8 @@
3831
CAROUSEL_ASPECT_RATIO_CHOICES = tuple(
3932
(f"{x}x{y}", f"{x}x{y}") for x, y in CAROUSEL_ASPECT_RATIOS
4033
)
34+
35+
CAROUSEL_TRANSITION_CHOICES = (
36+
("", _("Slide")),
37+
("carousel-fade", _("Fade")),
38+
)

djangocms_frontend/contrib/carousel/forms.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
from djangocms_frontend.fields import (
99
AttributesFormField,
10+
ButtonGroup,
1011
TagTypeFormField,
1112
TemplateChoiceMixin,
1213
)
1314

1415
from ... import settings
16+
from ...common.background import BackgroundFormMixin
1517
from ...fields import HTMLFormField
1618
from ...helpers import first_choice
1719
from ...models import FrontendUIItem
@@ -20,8 +22,8 @@
2022
from .constants import (
2123
CAROUSEL_ASPECT_RATIO_CHOICES,
2224
CAROUSEL_PAUSE_CHOICES,
23-
CAROUSEL_RIDE_CHOICES,
2425
CAROUSEL_TEMPLATE_CHOICES,
26+
CAROUSEL_TRANSITION_CHOICES,
2527
)
2628

2729
mixin_factory = settings.get_forms(carousel)
@@ -46,6 +48,7 @@ class Meta:
4648
"carousel_pause",
4749
"carousel_ride",
4850
"carousel_wrap",
51+
"carousel_transition",
4952
"attributes",
5053
]
5154
}
@@ -93,11 +96,12 @@ class Meta:
9396
'"mouseleave". If set to "false", hovering over the carousel '
9497
"won't pause it."
9598
),
99+
widget=ButtonGroup(attrs=dict(property="text")),
96100
)
97-
carousel_ride = forms.ChoiceField(
98-
label=_("Ride"),
99-
choices=CAROUSEL_RIDE_CHOICES,
100-
initial=first_choice(CAROUSEL_RIDE_CHOICES),
101+
carousel_ride = forms.BooleanField(
102+
label=_("Auto start"),
103+
initial=True,
104+
required=False,
101105
help_text=_(
102106
"Autoplays the carousel after the user manually cycles the "
103107
'first item. If "carousel", autoplays the carousel on load.'
@@ -121,6 +125,16 @@ class Meta:
121125
"according to the selected ratio."
122126
),
123127
)
128+
carousel_transition = forms.ChoiceField(
129+
label=_("Transition"),
130+
choices=CAROUSEL_TRANSITION_CHOICES,
131+
required=False,
132+
initial=CAROUSEL_TRANSITION_CHOICES[0][0],
133+
help_text=_(
134+
"Determines if slides change by sliding or fading."
135+
),
136+
widget=ButtonGroup(attrs=dict(property="text")),
137+
)
124138
attributes = AttributesFormField(
125139
excluded_keys=[
126140
"id",
@@ -135,7 +149,7 @@ class Meta:
135149

136150

137151
class CarouselSlideForm(
138-
mixin_factory("CarouselSlide"), AbstractLinkForm, EntangledModelForm
152+
mixin_factory("CarouselSlide"), AbstractLinkForm, BackgroundFormMixin, EntangledModelForm
139153
):
140154
"""
141155
Components > "Slide" Plugin
@@ -160,6 +174,7 @@ class Meta:
160174
queryset=Image.objects.all(),
161175
to_field_name="id",
162176
label=_("Slide image"),
177+
required=False,
163178
)
164179
carousel_content = HTMLFormField(
165180
label=_("Content"),

djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
class CarouselRenderMixin:
55
def render(self, context, instance, placeholder):
66
instance.add_classes("carousel slide")
7+
if instance.config.get("carousel_transition", None):
8+
instance.add_classes(instance.carousel_transition)
79
return super().render(context, instance, placeholder)
810

911

djangocms_frontend/contrib/carousel/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_short_description(self):
2727
text += ", {}: {}".format(_("Keyboard"), self.carousel_keyboard)
2828
text += ", {}: {}".format(_("Pause"), self.carousel_pause)
2929
text += ", {}: {}".format(_("Ride"), self.carousel_ride)
30-
text += "{}: {}".format(_("Wrap"), self.carousel_wrap)
30+
text += ", {}: {}".format(_("Wrap"), self.carousel_wrap)
3131
return text
3232

3333

djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/carousel.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
data-bs-interval="{{ instance.carousel_interval|lower }}"
55
data-bs-keyboard="{{ instance.carousel_keyboard|lower }}"
66
data-bs-pause="{{ instance.carousel_pause|lower }}"
7-
data-bs-ride="{{ instance.carousel_ride|lower }}"
7+
data-bs-ride="{% if instance.carousel_ride %}carousel{% else %}false{% endif %}"
88
data-bs-wrap="{{ instance.carousel_wrap|lower }}"
99
>
1010
{% if instance.carousel_indicators %}

djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
<img class="d-block w-100" src="{{ thumbnail.url }}" alt="{{ instance.rel_image.default_alt_text|default:'' }}" />
66
{% else %}
7-
<div class="placeholder placeholder-wave d-block w-100"
8-
style="aspect-ratio: {{ aspect_ratio }}"></div>
7+
<div class="d-block w-100"
8+
style="aspect-ratio: {{ aspect_ratio }}">
9+
{% for plugin in instance.child_plugin_instances %}
10+
{% render_plugin plugin %}
11+
{% endfor %}
12+
</div>
913
{% endif %}{% endspaceless %}

djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/slide.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
{% endif %}
1414

1515
<div class="carousel-caption d-none d-md-block">
16-
{{ instance.link_target }}
1716
{% if instance.carousel_content %}
1817
{{ instance.carousel_content|html_safe }}
1918
{% endif %}
20-
21-
{% for plugin in instance.child_plugin_instances %}
22-
{% render_plugin plugin %}
23-
{% endfor %}
19+
{% if instance.rel_image %}
20+
{% for plugin in instance.child_plugin_instances %}
21+
{% render_plugin plugin %}
22+
{% endfor %}
23+
{% endif %}
2424
</div>
2525
</{{ instance.tag_type }}>{% endspaceless %}

docs/source/components.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ each collapsable section.
3232
.. image:: screenshots/accordion-plugins.png
3333
:width: 394
3434

35-
Also see Bootstrap 5 `Accordion <https://getbootstrap.com/docs/5.0/components/accordion/>`_
35+
Also see Bootstrap 5 `Accordion <https://getbootstrap.com/docs/5.3/components/accordion/>`_
3636
documentation.
3737

3838
.. index::
@@ -58,7 +58,7 @@ the right hand side.
5858
New features:
5959
Alerts can have **shadows** to optically lift them.
6060

61-
Also see Bootstrap 5 `Alerts <https://getbootstrap.com/docs/5.0/components/alerts/>`_
61+
Also see Bootstrap 5 `Alerts <https://getbootstrap.com/docs/5.3/components/alerts/>`_
6262
documentation.
6363

6464
.. index::
@@ -76,7 +76,7 @@ plugin, badges are useful, e.g., to mark featured or new headers.
7676
.. image:: screenshots/badge-example.png
7777
:width: 180
7878

79-
Also see Bootstrap 5 `Badge <https://getbootstrap.com/docs/5.0/components/badge/>`_
79+
Also see Bootstrap 5 `Badge <https://getbootstrap.com/docs/5.3/components/badge/>`_
8080
documentation.
8181

8282
.. index::
@@ -146,7 +146,7 @@ Here is an example of the new card **Image overlay** feature:
146146
.. image:: screenshots/card-overlay-example.png
147147
:width: 298
148148

149-
Also see Bootstrap 5 `Card <https://getbootstrap.com/docs/5.0/components/card/>`_
149+
Also see Bootstrap 5 `Card <https://getbootstrap.com/docs/5.3/components/card/>`_
150150
documentation.
151151

152152
.. index::
@@ -156,15 +156,20 @@ documentation.
156156
Carousel component
157157
******************
158158

159-
A `Carousel <https://getbootstrap.com/docs/5.0/components/carousel/>`_
159+
A `Carousel <https://getbootstrap.com/docs/5.3/components/carousel/>`_
160160
is a set of images (potentially with some description) that slide in
161161
(or fade in) one after the other after a certain amount of time.
162162

163+
Each slide requires a Carousel Slide child plugin. The simplest case specifies an image, potentially a caption and a link which is followed once the slide is clicked.
164+
165+
Since the design of carousels is somewhat opinionated template sets can be specified using the ``DJANGOCMS_FRONTEND_CAROUSEL_TEMPLATES`` setting.
166+
.. note:: A Carousel Slide plugin can have child plugins itself. If an image is specified the child plugins add to the caption. If no image is specified the child plugins make up the slide.
167+
163168
******************
164169
Collapse component
165170
******************
166171

167-
The `Collapse <https://getbootstrap.com/docs/5.0/components/collapse/>`_
172+
The `Collapse <https://getbootstrap.com/docs/5.3/components/collapse/>`_
168173
hides text behind its headline and offers the user a trigger (e.g., a
169174
button) to reveal itself.
170175

tests/carousel/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_carousel_instance(self):
2222
self.assertEqual(
2323
instance.get_short_description(),
2424
"(default) Interval: 5000, Controls: True, Indicators: True, "
25-
"Keyboard: True, Pause: hover, Ride: carouselWrap: True",
25+
"Keyboard: True, Pause: hover, Ride: True, Wrap: True",
2626
)
2727

2828
def test_carousel_slide_instance(self):

0 commit comments

Comments
 (0)