Skip to content

Commit

Permalink
Add two block types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Feb 15, 2024
1 parent 167edc8 commit fe8fcca
Show file tree
Hide file tree
Showing 8 changed files with 570 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ S3_BUCKET_NAME=
S3_BUCKET_REGION=eu-west-3
# S3_LOCATION: If the S3 bucket is shared, add a unique folder name
S3_LOCATION=

SF_ALLOW_RAW_HTML_BLOCKS=False
3 changes: 3 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"wagtail.search",
"wagtail",
"wagtail_modeladmin",
"wagtailmarkdown",
"wagtailmenus",
"taggit",
"django.contrib.auth",
Expand Down Expand Up @@ -234,3 +235,5 @@
CSRF_TRUSTED_ORIGINS = []
for host in ALLOWED_HOSTS:
CSRF_TRUSTED_ORIGINS.append("https://" + host)

SF_ALLOW_RAW_HTML_BLOCKS = os.getenv("SF_ALLOW_RAW_HTML_BLOCKS", "False").lower() == "true"
42 changes: 42 additions & 0 deletions content_manager/blocks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf import settings
from wagtail import blocks
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.blocks import ImageChooserBlock
from wagtailmarkdown.blocks import MarkdownBlock


# Wagtail Block Documentation : https://docs.wagtail.org/en/stable/reference/streamfield/blocks.html
Expand Down Expand Up @@ -221,3 +223,43 @@ class MultiColumnsWithTitleBlock(blocks.StructBlock):
)
title = blocks.CharBlock(label="Titre", required=False)
columns = MultiColumnsBlock(label="Multi-colonnes")


STREAMFIELD_BLOCKS = [
("hero", HeroBlock(label="Section promotionnelle")),
("title", TitleBlock(label="Titre de page")),
("paragraph", blocks.RichTextBlock(label="Texte avec mise en forme")),
(
"paragraphlarge",
blocks.RichTextBlock(label="Texte avec mise en forme (large)"),
),
("image", ImageBlock()),
(
"imageandtext",
ImageAndTextBlock(label="Bloc image à gauche et texte à droite"),
),
("alert", AlertBlock(label="Message d'alerte")),
("callout", CalloutBlock(label="Texte mise en avant")),
("quote", QuoteBlock(label="Citation")),
("video", VideoBlock(label="Vidéo")),
("multicolumns", MultiColumnsWithTitleBlock(label="Multi-colonnes")),
("accordions", AccordionsBlock(label="Accordéons")),
("stepper", StepperBlock(label="Étapes")),
("separator", SeparatorBlock(label="Séparateur")),
("markdown", MarkdownBlock()),
]

# See warning on https://docs.wagtail.org/en/latest/reference/streamfield/blocks.html#wagtail.blocks.RawHTMLBlock
# There is currently no way to restrict a type of block depending on user permissions,
# pending issue https://github.com/wagtail/wagtail/issues/6323
if settings.SF_ALLOW_RAW_HTML_BLOCKS is True:
STREAMFIELD_BLOCKS += [
(
"html",
blocks.RawHTMLBlock(
readonly=True,
help_text="""Avertissement : Utilisez le bloc HTML avec précaution.
Un code malveillant peut compromettre la sécurité du site.""",
),
)
]
464 changes: 464 additions & 0 deletions content_manager/migrations/0012_alter_contentpage_body.py

Large diffs are not rendered by default.

39 changes: 2 additions & 37 deletions content_manager/models.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,17 @@
from django.db import models
from django.forms.widgets import Textarea
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.contrib.settings.models import BaseSiteSetting, register_setting
from wagtail.fields import StreamField
from wagtail.models import Page
from wagtail.search import index

from content_manager.blocks import (
AccordionsBlock,
AlertBlock,
CalloutBlock,
HeroBlock,
ImageAndTextBlock,
ImageBlock,
MultiColumnsWithTitleBlock,
QuoteBlock,
SeparatorBlock,
StepperBlock,
TitleBlock,
VideoBlock,
)
from content_manager.blocks import STREAMFIELD_BLOCKS


class ContentPage(Page):
body = StreamField(
[
("hero", HeroBlock(label="Section promotionnelle")),
("title", TitleBlock(label="Titre de page")),
("paragraph", blocks.RichTextBlock(label="Texte avec mise en forme")),
(
"paragraphlarge",
blocks.RichTextBlock(label="Texte avec mise en forme (large)"),
),
("image", ImageBlock()),
(
"imageandtext",
ImageAndTextBlock(label="Bloc image à gauche et texte à droite"),
),
("alert", AlertBlock(label="Message d'alerte")),
("callout", CalloutBlock(label="Texte mise en avant")),
("quote", QuoteBlock(label="Citation")),
("video", VideoBlock(label="Vidéo")),
("multicolumns", MultiColumnsWithTitleBlock(label="Multi-colonnes")),
("accordions", AccordionsBlock(label="Accordéons")),
("stepper", StepperBlock(label="Étapes")),
("separator", SeparatorBlock(label="Séparateur")),
],
STREAMFIELD_BLOCKS,
blank=True,
use_json_field=True,
)
Expand Down
6 changes: 5 additions & 1 deletion content_manager/templates/content_manager/content_page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}

{% load static dsfr_tags wagtailcore_tags wagtailimages_tags %}
{% load static dsfr_tags wagtailcore_tags wagtailimages_tags wagtailmarkdown %}

{% block title %}
<title>{{ page.seo_title|default:page.title }} — {{ settings.content_manager.CmsDsfrConfig.site_title }}</title>
Expand Down Expand Up @@ -102,6 +102,10 @@ <h1 class="fr-display--sm">{{ block.value.title }}</h1>
<div class="fr-container">
<hr class="fr-mt-{{ block.value.top_margin }}w fr-mb-{{ block.value.bottom_margin }}w fr-py-1v">
</div>
{% elif block.block_type == 'markdown' %}
<div class="fr-container">{{ block.value|markdown }}</div>
{% elif block.block_type == 'html' %}
<div class="fr-container">{{ block.value|safe }}</div>
{% endif %}
{% endfor %}
{% endblock content %}
52 changes: 51 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ wagtailmenus = "^3.1.9"
boto3 = "^1.29.1"
django-storages = "^1.14.2"
wagtail-modeladmin = "^1.0.0"
wagtail-markdown = "^0.11.1"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit fe8fcca

Please sign in to comment.