Skip to content

Commit

Permalink
feat(cms): ajout de page de FAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa committed Jul 15, 2024
1 parent 9fb6b62 commit 83644eb
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lemarche/cms/blocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# common blocks
from uuid import uuid4

from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock

Expand Down Expand Up @@ -232,3 +234,35 @@ class Meta:
template = "cms/streams/section_why_call_siaes.html"
icon = "pen"
label = "Pourquoi faire appel à un prestataire inclusif ?"


class FAQBlock(blocks.StructBlock):
# id = blocks.CharBlock(required=True, default=uuid4(), help_text="L'identifiant unique pour cette question.")
question = blocks.CharBlock(required=True, help_text="La question fréquemment posée.")
answer = blocks.RichTextBlock(required=True, help_text="La réponse à la question.")

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context=parent_context)
context["faq_id"] = f"faq-{str(uuid4())[:6]}"
return context

class Meta:
icon = "help"
label = "Question/Réponse"
template = "cms/streams/faq_block.html"


class FAQGroupBlock(blocks.StructBlock):
# id = blocks.CharBlock(required=True, default=uuid4(), help_text="L'identifiant unique pour cette question.")
group_title = blocks.CharBlock(required=True, help_text="Le titre du groupe de questions-réponses.")
faqs = blocks.ListBlock(FAQBlock())

def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context=parent_context)
context["group_id"] = f"group-{str(uuid4())[:6]}"
return context

class Meta:
icon = "folder"
label = "Groupe de FAQ"
template = "cms/streams/faq_group_block.html"
80 changes: 80 additions & 0 deletions lemarche/cms/migrations/0012_faqpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generated by Django 4.2.13 on 2024-07-15 16:10

import django.db.models.deletion
import wagtail.blocks
import wagtail.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0093_uploadedfile"),
("cms", "0011_infocard"),
]

operations = [
migrations.CreateModel(
name="FAQPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
(
"body",
wagtail.fields.StreamField(
[
(
"faq_group",
wagtail.blocks.StructBlock(
[
(
"group_title",
wagtail.blocks.CharBlock(
help_text="Le titre du groupe de questions-réponses.", required=True
),
),
(
"faqs",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
(
"question",
wagtail.blocks.CharBlock(
help_text="La question fréquemment posée.",
required=True,
),
),
(
"answer",
wagtail.blocks.RichTextBlock(
help_text="La réponse à la question.", required=True
),
),
]
)
),
),
]
),
)
],
blank=True,
),
),
],
options={
"verbose_name": "FAQ Page",
"verbose_name_plural": "FAQ Pages",
},
bases=("wagtailcore.page",),
),
]
17 changes: 17 additions & 0 deletions lemarche/cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,20 @@ def get_context(self, request, *args, **kwargs):
except PageFragment.DoesNotExist:
pass
return context


class FAQPage(Page):
body = StreamField(
[
("faq_group", blocks.FAQGroupBlock()),
],
blank=True,
)

content_panels = Page.content_panels + [
FieldPanel("body"),
]

class Meta:
verbose_name = "FAQ Page"
verbose_name_plural = "FAQ Pages"
7 changes: 7 additions & 0 deletions lemarche/templates/cms/faq_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "layouts/base.html" %}
{% block content %}
<div class="container pt-2 faq-page">
<h1>{{ page.title }}</h1>
{% for block in page.body %}{{ block }}{% endfor %}
</div>
{% endblock %}
17 changes: 17 additions & 0 deletions lemarche/templates/cms/streams/faq_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="card">
<div class="card-header" id="heading{{ faq_id }}">
<h2 class="mb-0">
<button class="btn btn-link"
type="button"
data-toggle="collapse"
data-target="#collapse{{ faq_id }}"
aria-expanded="true"
aria-controls="collapse{{ faq_id }}">{{ self.question }}</button>
</h2>
</div>
<div id="collapse{{ faq_id }}"
class="collapse"
aria-labelledby="heading{{ faq_id }}">
<div class="card-body">{{ self.answer }}</div>
</div>
</div>
10 changes: 10 additions & 0 deletions lemarche/templates/cms/streams/faq_group_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load wagtailcore_tags %}
<div class="faq-group mb-3">
<h3>{{ self.group_title }}</h3>
<div class="accordion" id="accordion{{ group_id }}">
{% for faq in self.faqs %}
{% comment %} <p>{{ faq.title }}</p> {% endcomment %}
{% include_block faq with parent_id=group_id %}
{% endfor %}
</div>
</div>

0 comments on commit 83644eb

Please sign in to comment.