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

feat(cms): ajout de page de FAQ sur le cms #1342

Merged
merged 6 commits into from
Jul 17, 2024
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
32 changes: 32 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,33 @@ class Meta:
template = "cms/streams/section_why_call_siaes.html"
icon = "pen"
label = "Pourquoi faire appel à un prestataire inclusif ?"


class FAQBlock(blocks.StructBlock):
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):
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"
93 changes: 93 additions & 0 deletions lemarche/cms/migrations/0012_faqpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Generated by Django 4.2.13 on 2024-07-16 17:55

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


class Migration(migrations.Migration):
dependencies = [
("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",
),
),
("intro", models.TextField(blank=True, null=True, verbose_name="Introduction")),
(
"faqs",
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,
use_json_field=True,
),
),
("categories", modelcluster.fields.ParentalManyToManyField(blank=True, to="cms.articlecategory")),
(
"image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.image",
),
),
],
options={
"verbose_name": "FAQ Page",
"verbose_name_plural": "FAQ Pages",
},
bases=("wagtailcore.page",),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.13 on 2024-07-16 18:22

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cms", "0012_faqpage"),
]

operations = [
migrations.AlterField(
model_name="articlepage",
name="intro",
field=models.TextField(blank=True, null=True, verbose_name="Introduction de la page"),
),
migrations.AlterField(
model_name="faqpage",
name="intro",
field=models.TextField(blank=True, null=True, verbose_name="Introduction de la page"),
),
]
39 changes: 36 additions & 3 deletions lemarche/cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@
from lemarche.pages.models import PageFragment


class ArticlePage(Page):
intro = models.TextField(verbose_name="Introduction", null=True, blank=True)
class ArticleBase(Page):
intro = models.TextField(verbose_name="Introduction de la page", null=True, blank=True)
image = models.ForeignKey(
"wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+"
)
categories = ParentalManyToManyField("cms.ArticleCategory", blank=True)

content_panels = Page.content_panels + [
FieldPanel("intro", classname="full"),
MultiFieldPanel([FieldPanel("categories", widget=forms.CheckboxSelectMultiple)], heading="Categories"),
FieldPanel(
"image",
classname="collapsible",
),
]

class Meta:
abstract = True


class ArticlePage(ArticleBase):
is_static_page = models.BooleanField(verbose_name="c'est une page statique ?", default=False)
with_cta_tender = models.BooleanField(verbose_name="avec un CTA pour les besoins ?", default=False)

Expand All @@ -47,7 +61,7 @@ def get_template(self, request, *args, **kwargs):

# Editor panels configuration

content_panels = Page.content_panels + [
content_panels = ArticleBase.content_panels + [
FieldPanel("intro", classname="full"),
FieldPanel("with_cta_tender", classname="full"),
MultiFieldPanel([FieldPanel("categories", widget=forms.CheckboxSelectMultiple)], heading="Categories"),
Expand Down Expand Up @@ -225,3 +239,22 @@ def get_context(self, request, *args, **kwargs):
except PageFragment.DoesNotExist:
pass
return context


class FAQPage(ArticleBase):
faqs = StreamField(
[
("faq_group", blocks.FAQGroupBlock()),
],
blank=True,
use_json_field=True,
)
content_panels = ArticleBase.content_panels + [
FieldPanel("faqs"),
]

parent_page_types = ["wagtailcore.Page", "cms.HomePage", "cms.ArticleList", "cms.PaidArticleList"]

class Meta:
verbose_name = "FAQ Page"
verbose_name_plural = "FAQ Pages"
8 changes: 8 additions & 0 deletions lemarche/templates/cms/faq_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "layouts/base.html" %}
{% block content %}
<div class="container py-4 faq-page">
<h1>{{ page.title }}</h1>
<p>{{ page.intro|default:"" }}</p>
{% for block in page.faqs %}{{ 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-4">
<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>
12 changes: 9 additions & 3 deletions lemarche/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ def get_context_data(self, **kwargs):
try:
# Look for the blog category by its slug.
category = ArticleCategory.objects.get(slug=category_slug)
article_list = article_list.filter(categories__in=[category])
except Exception:
last_faq_page = category.faqpage_set.last()
article_list = article_list.filter(categories__in=[category])[:3]
if last_faq_page:
article_list = list(article_list[:2])
article_list.insert(0, last_faq_page)

except ArticleCategory.DoesNotExist:
category_slug = None
article_list = article_list[:3]

# set context ressources
context["current_slug_cat"] = category_slug
context["last_3_ressources"] = article_list[:3]
context["last_3_ressources"] = article_list

# for specific users
if user.kind == User.KIND_SIAE:
Expand Down
Loading