Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Améliorations mineures #55

Merged
merged 9 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
exclude: /migrations/
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

INSTALLED_APPS = [
"storages",
"dashboard",
"wagtail.contrib.redirects",
"wagtail.contrib.settings",
"wagtail.embeds",
Expand All @@ -51,7 +52,7 @@
"wagtail.admin",
"wagtail.search",
"wagtail",
"wagtail.contrib.modeladmin",
"wagtail_modeladmin",
"wagtailmenus",
"taggit",
"django.contrib.auth",
Expand Down
217 changes: 217 additions & 0 deletions content_manager/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
from wagtail import blocks
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.blocks import ImageChooserBlock


# Wagtail Block Documentation : https://docs.wagtail.org/en/stable/reference/streamfield/blocks.html


## Basic blocks
class AccordionBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre")
content = blocks.RichTextBlock(label="Contenu")


class AccordionsBlock(blocks.StreamBlock):
title = blocks.CharBlock(label="Titre")
accordion = AccordionBlock(label="Accordéon", min_num=1, max_num=15)


level_choices = [
("error", "Erreur"),
("success", "Succès"),
("info", "Information"),
("warning", "Attention"),
]


class AlertBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre du message", required=False)
description = blocks.TextBlock(label="Texte du message", required=False)
level = blocks.ChoiceBlock(label="Type de message", choices=level_choices)


badge_level_choices = [
("error", "Erreur"),
("success", "Succès"),
("info", "Information"),
("warning", "Attention"),
("new", "Nouveau"),
("grey", "Gris"),
("green-emeraude", "Vert"),
("blue-ecume", "Bleu"),
]


class BadgeBlock(blocks.StructBlock):
text = blocks.CharBlock(label="Texte du badge", required=False)
color = blocks.ChoiceBlock(label="Couleur de badge", choices=badge_level_choices, required=False)
hide_icon = blocks.BooleanBlock(label="Masquer l'icon du badge", required=False)


class BadgesListBlock(blocks.StreamBlock):
badge = BadgeBlock(label="Badge")


heading_choices = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça m'embête un peu, ces variables qui se promènent entre deux définitions de classe. Y a-t-il moyen de les définir directement dans leurs classes ?
Un peu comme dans Django quand on a des CharField avec des choix :

class Student(models.Model):
    class YearInSchool(models.TextChoices):
        FRESHMAN = "FR", _("Freshman")
        SOPHOMORE = "SO", _("Sophomore")
        JUNIOR = "JR", _("Junior")
        SENIOR = "SR", _("Senior")
        GRADUATE = "GR", _("Graduate")

    year_in_school = models.CharField(
        max_length=2,
        choices=YearInSchool.choices,
        default=YearInSchool.FRESHMAN,
    )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça m'embête aussi un peu, je les ai laissées avant leur classe (comme elles étaient quand j'ai déplacé le tout depuis models.py), mais je serai effectivement d'avis de soi les intégrer dans la classe, soit les déplacer dans un constants.py

("h2", "En-tête 2"),
("h3", "En-tête 3"),
("h4", "En-tête 4"),
("h5", "En-tête 5"),
("h6", "En-tête 6"),
("p", "Paragraphe"),
]


class CalloutBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre de la mise en vant", required=False)
text = blocks.TextBlock(label="Texte mis en avant", required=False)
heading_tag = blocks.ChoiceBlock(
label="Niveau de titre",
choices=heading_choices,
default="h3",
help_text="À adapter à la structure de la page. Par défaut en-tête 3.",
)


class CardBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre")
description = blocks.TextBlock(label="Texte")
image = ImageChooserBlock(label="Image")
url = blocks.URLBlock(label="Lien", required=False)
document = DocumentChooserBlock(
label="ou Document",
help_text=(
"Sélectionnez un document pour rendre la carte cliquable vers "
"celui ci (si le champ `Lien` n'est pas renseigné)."
),
required=False,
)


class HeroBlock(blocks.StructBlock):
bg_image = ImageChooserBlock(label="Image d'arrière plan")
bg_color = blocks.RegexBlock(
label="Couleur d'arrière plan au format hexa (Ex: #f5f5fe)",
regex=r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",
error_messages={"invalid": "La couleur n'est pas correcte, le format doit être #fff ou #f5f5fe"},
required=False,
)
title = blocks.CharBlock(label="Titre")
text = blocks.CharBlock(label="Texte", required=False)
cta_label = blocks.CharBlock(label="Texte du bouton", required=False)
cta_link = blocks.URLBlock(label="Lien du bouton", required=False)


class IframeBlock(blocks.StructBlock):
title = blocks.CharBlock(
label="Titre",
help_text="Accessibilité : Le titre doit décrire, de façon claire et concise, le contenu embarqué.",
)
url = blocks.URLBlock(
label="Lien du cadre intégré",
help_text="Exemple pour Tally : https://tally.so/embed/w2jMRa",
)
height = blocks.IntegerBlock(label="Hauteur en pixels")


class ImageAndTextBlock(blocks.StructBlock):
image = ImageChooserBlock(label="Illustration (à gauche)")
image_ratio = blocks.ChoiceBlock(
label="Largeur de l'image",
choices=[
("3", "3/12"),
("5", "5/12"),
("6", "6/12"),
],
)
text = blocks.RichTextBlock(label="Texte avec mise en forme (à droite)")
link_label = blocks.CharBlock(
label="Titre du lien",
help_text="Le lien apparait en bas du bloc de droite, avec une flèche",
required=False,
)
link_url = blocks.URLBlock(label="Lien", required=False)


class ImageBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre", required=False)
image = ImageChooserBlock(label="Illustration")
alt = blocks.CharBlock(label="Texte alternatif (description textuelle de l'image)", required=False)
caption = blocks.CharBlock(label="Légende", required=False)
url = blocks.URLBlock(label="Lien", required=False)


class QuoteBlock(blocks.StructBlock):
image = ImageChooserBlock(label="Illustration (à gauche)", required=False)
quote = blocks.CharBlock(label="Citation")
author_name = blocks.CharBlock(label="Nom de l'auteur")
author_title = blocks.CharBlock(label="Titre de l'auteur")


class SeparatorBlock(blocks.StructBlock):
top_margin = blocks.IntegerBlock(label="Espacement au dessus", min_value=0, max_value=15, default=3)
bottom_margin = blocks.IntegerBlock(label="Espacement en dessous", min_value=0, max_value=15, default=3)


class StepBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre de l'étape")
detail = blocks.TextBlock(label="Détail")


class StepsListBlock(blocks.StreamBlock):
step = StepBlock(label="Étape")


class StepperBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre")
total = blocks.IntegerBlock(label="Nombre d'étape")
current = blocks.IntegerBlock(label="Étape en cours")
steps = StepsListBlock(label="Les étapes")


class TextAndCTA(blocks.StructBlock):
text = blocks.RichTextBlock(label="Texte avec mise en forme", required=False)
cta_label = blocks.CharBlock(
label="Titre de l'appel à l'action",
help_text="Le lien apparait comme un bouton sous le bloc de texte",
required=False,
)
cta_url = blocks.CharBlock(label="Lien", required=False)


class TitleBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre")
large = blocks.BooleanBlock(label="Large", required=False)


class VideoBlock(blocks.StructBlock):
title = blocks.CharBlock(label="Titre", required=False)
caption = blocks.CharBlock(label="Légende")
url = blocks.URLBlock(
label="Lien de la vidéo",
help_text="URL au format 'embed' (Ex. : https://www.youtube.com/embed/gLzXOViPX-0)",
)


## Multi-column blocks
class MultiColumnsBlock(blocks.StreamBlock):
text = blocks.RichTextBlock(label="Texte avec mise en forme")
image = ImageBlock(label="Image")
video = VideoBlock(label="Vidéo")
card = CardBlock(label="Carte")
quote = QuoteBlock(label="Citation")
text_cta = TextAndCTA(label="Texte et appel à l'action")
iframe = IframeBlock(label="Cadre intégré")


class MultiColumnsWithTitleBlock(blocks.StructBlock):
bg_image = ImageChooserBlock(label="Image d'arrière plan", required=False)
bg_color = blocks.RegexBlock(
label="Couleur d'arrière plan au format hexa (Ex: #f5f5fe)",
regex=r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",
error_messages={"invalid": "La couleur n'est pas correcte, le format doit être #fff ou #f5f5fe"},
required=False,
)
title = blocks.CharBlock(label="Titre", required=False)
columns = MultiColumnsBlock(label="Multi-colonnes")
Loading