Skip to content

Commit

Permalink
[NEW] Added useful option for Accordion, fixed tests and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sveetch committed Aug 29, 2024
1 parent b021fd5 commit a3ecc34
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Changelog
Version 1.4.0 - Unreleased
--------------------------

* Added Accordion plugin;
* Added new plugin *Accordion*;
* Disabled annoying Carousel autoplay in Slider template for sandbox;


Version 1.3.2 - 2024/07/12
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ test:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Tests <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) -vv --reuse-db tests/
$(PYTEST_BIN) --reuse-db tests/
rm -Rf var/media-tests/
.PHONY: test

test-initial:
@echo ""
@printf "$(FORMATBLUE)$(FORMATBOLD)---> Running Tests from zero <---$(FORMATRESET)\n"
@echo ""
$(PYTEST_BIN) -vv --reuse-db --create-db tests/
$(PYTEST_BIN) --reuse-db --create-db tests/
rm -Rf var/media-tests/
.PHONY: test-initial

Expand Down
1 change: 1 addition & 0 deletions cmsplugin_blocks/admin/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def get_fieldsets(self, request, obj=None):
(_("Options"), {
"fields": (
"order",
"opened",
"image_alt",
),
}),
Expand Down
2 changes: 1 addition & 1 deletion cmsplugin_blocks/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

BLOCKS_KNOWED_FEATURES_PLUGINS = [
"Accordion"
"Accordion",
"Album",
"Card",
"Container",
Expand Down
2 changes: 2 additions & 0 deletions cmsplugin_blocks/factories/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AccordionFactory(factory.django.DjangoModelFactory):
"""
template = get_accordion_template_default()
title = factory.Faker("text", max_nb_chars=20)
keep_open = False

class Meta:
model = Accordion
Expand Down Expand Up @@ -88,6 +89,7 @@ class AccordionItemFactory(factory.django.DjangoModelFactory):
content = factory.Faker("text", max_nb_chars=42)
order = factory.Sequence(lambda n: 10 * n)
image_alt = factory.Faker("text", max_nb_chars=10)
opened = False

class Meta:
model = AccordionItem
Expand Down
2 changes: 2 additions & 0 deletions cmsplugin_blocks/forms/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Meta:
fields = [
"title",
"template",
"keep_open",
"size_features",
"color_features",
"extra_features",
Expand All @@ -35,6 +36,7 @@ class Meta:
fields = [
"accordion",
"title",
"opened",
"order",
"image",
"image_alt",
Expand Down
53 changes: 53 additions & 0 deletions cmsplugin_blocks/migrations/0012_accordion_add_more_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 5.0.7 on 2024-08-29 01:31

import cmsplugin_blocks.modelfields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"cmsplugin_blocks",
"0011_accordion_alter_feature_plugins_accordionitem_and_more",
),
]

operations = [
migrations.AddField(
model_name="accordion",
name="keep_open",
field=models.BooleanField(
default=False,
help_text="When enabled, the already opened items are not closed when opening other items. On defaut, once an item is opened all other items are closed.",
verbose_name="Keep items opened",
),
),
migrations.AddField(
model_name="accordionitem",
name="opened",
field=models.BooleanField(
default=False,
help_text="On default all accordion item are closed and need to be opened manually.This option enables this item to be initially opened.",
verbose_name="Initially opened",
),
),
migrations.AlterField(
model_name="feature",
name="plugins",
field=cmsplugin_blocks.modelfields.CommaSeparatedStringsField(
blank=True,
choices=[
("Accordion", "Accordion"),
("Album", "Album"),
("Card", "Card"),
("Container", "Container"),
("Hero", "Hero"),
("Slider", "Slider"),
],
default="",
max_length=50,
verbose_name="Allowed for plugins",
),
),
]
6 changes: 3 additions & 3 deletions cmsplugin_blocks/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from .accordion import Accordion, AccordionItem
from .album import Album, AlbumItem
from .card import Card
from .accordion import Accordion, AccordionItem
from .container import Container
from .feature import Feature
from .hero import Hero
from .slider import Slider, SlideItem


__all__ = [
"Accordion",
"AccordionItem",
"Album",
"AlbumItem",
"Card",
Expand All @@ -16,6 +18,4 @@
"Hero",
"Slider",
"SlideItem",
"Accordion",
"AccordionItem"
]
24 changes: 24 additions & 0 deletions cmsplugin_blocks/models/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ class Accordion(FeatureMixinModel, CMSPlugin):
``BLOCKS_ACCORDION_TEMPLATES``. Default to the first choice item.
"""

keep_open = models.BooleanField(
_("Keep items opened"),
default=False,
help_text=_(
"When enabled, the already opened items are not closed when opening other "
"items. On defaut, once an item is opened all other items are closed."
),
)
"""
Checkbox to enable "keep items opened" behavior.
"""

size_features = models.ManyToManyField(
"cmsplugin_blocks.Feature",
verbose_name=_("size features"),
Expand Down Expand Up @@ -172,6 +184,18 @@ class AccordionItem(SmartFormatMixin, models.Model):
Number for order position in item list.
"""

opened = models.BooleanField(
_("Initially opened"),
default=False,
help_text=_(
"On default all accordion item are closed and need to be opened manually."
"This option enables this item to be initially opened."
),
)
"""
Checkbox to initially open item.
"""

def __str__(self):
return Truncator(strip_tags(self.title)).words(
settings.BLOCKS_MODEL_TRUNCATION_LENGTH,
Expand Down
1 change: 1 addition & 0 deletions cmsplugin_blocks/plugins/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_fieldsets(self, request, obj=None):
(None, {
"fields": (
"template",
"keep_open",
),
}),
(_("Content"), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<div class="accordion{% if features %} {{ features }}{% endif %}">
<p class="accordion__title">{{ instance.title }}</p>

<div class="accordion__items">
<div class="accordion__items{% if instance.keep_open %} accordion__items--keepopen{% endif %}">
{% for item in slides %}
{% media_thumb item.image "1200x400" as thumb %}
<div class="accordion__item"
<div class="accordion__item{% if item.opened %} accordion__item--open{% endif %}"
style="background-image: url({{ thumb.url }})">
<p class="accordion__item-title">{{ item.title }}</p>
{% if item.content %}
Expand Down
18 changes: 9 additions & 9 deletions sandbox/settings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@


# Fill cmsplugin blocks settings for test only
BLOCKS_ACCORDIONITEM_FEATURES = [
("foo", "Foo"),
("bar", "Bar"),
]

BLOCKS_ALBUM_FEATURES = [
("foo", "Foo"),
("bar", "Bar"),
Expand Down Expand Up @@ -65,13 +70,12 @@
("bar", "Bar"),
]

BLOCKS_ACCORDIONITEM_FEATURES = [
("foo", "Foo"),
("bar", "Bar"),
]

# Add required template for test at the top at the list (so they are the
# default ones picked up by tests)
BLOCKS_ACCORDION_TEMPLATES = [
("cmsplugin_blocks/accordion/test.html", "Test"),
] + BLOCKS_ACCORDION_TEMPLATES # noqa: F405

BLOCKS_ALBUM_TEMPLATES = [
("cmsplugin_blocks/album/test.html", "Test"),
] + BLOCKS_ALBUM_TEMPLATES # noqa: F405
Expand All @@ -91,7 +95,3 @@
BLOCKS_SLIDER_TEMPLATES = [
("cmsplugin_blocks/slider/test.html", "Test"),
] + BLOCKS_SLIDER_TEMPLATES # noqa: F405

BLOCKS_ACCORDION_TEMPLATES = [
("cmsplugin_blocks/accordion/test.html", "Test"),
] + BLOCKS_ACCORDION_TEMPLATES # noqa: F405
4 changes: 2 additions & 2 deletions sandbox/templates/cmsplugin_blocks/accordion/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ <h3 class="accordion-header" id="accordion-{{ instance.id }}-{{ item.id }}-head
</h3>

<div id="accordion-{{ instance.id }}-{{ item.id }}-body"
class="accordion-collapse collapse {% comment %}show{% endcomment %}"
class="accordion-collapse collapse{% if item.opened %} show{% endif %}"
aria-labelledby="accordion-{{ instance.id }}-{{ item.id }}-heading"
data-bs-parent="#accordion-{{ instance.id }}">
{% if not instance.keep_open %}data-bs-parent="#accordion-{{ instance.id }}"{% endif %}>
<div class="accordion-body">
<div class="row">
{% if item.image %}
Expand Down
3 changes: 1 addition & 2 deletions sandbox/templates/cmsplugin_blocks/slider/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<h2 class="slider__title border-bottom border-3 text-center mb-3">{{ instance.title }}</h2>

<div id="slider-{{ instance.id }}"
class="carousel carousel-dark mb-4 slide{% if features %} {{ features }}{% endif %}"
data-bs-ride="carousel">
class="carousel carousel-dark mb-4 slide{% if features %} {{ features }}{% endif %}">
<div class="carousel-indicators bg-light p-2" style="--bs-bg-opacity: .7;">
{% for item in slides %}
<button type="button"
Expand Down
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;;
[metadata]
name = cmsplugin-blocks
version = 1.4.0-pre.2
version = 1.4.0-pre.3
description = A set of DjangoCMS plugins for structured contents in CMS pages
long_description = file:README.rst
long_description_content_type = text/x-rst
Expand Down Expand Up @@ -56,8 +56,8 @@ quality =
tox
doc =
sphinx
furo==2023.7.26
sphinx-copybutton==0.5.2
furo
sphinx-copybutton
doc-live =
livereload
release =
Expand Down Expand Up @@ -88,7 +88,7 @@ exclude =

[tool:pytest]
DJANGO_SETTINGS_MODULE = sandbox.settings.tests
addopts = -vv
addopts = -v --tb=long
python_files =
*.py
testpaths =
Expand Down

0 comments on commit a3ecc34

Please sign in to comment.