Skip to content

Commit

Permalink
update dahsboard siaes and update FAQ models
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa committed Jul 16, 2024
1 parent a5f6612 commit 204633c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
30 changes: 23 additions & 7 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):
class ArticleBase(Page):
intro = models.TextField(verbose_name="Introduction", 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 @@ -227,19 +241,21 @@ def get_context(self, request, *args, **kwargs):
return context


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

content_panels = Page.content_panels + [
FieldPanel("body"),
content_panels = ArticleBase.content_panels + [
MultiFieldPanel([FieldPanel("categories", widget=forms.CheckboxSelectMultiple)], heading="Categories"),
FieldPanel("faqs"),
]

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

class Meta:
verbose_name = "FAQ Page"
verbose_name_plural = "FAQ Pages"
5 changes: 3 additions & 2 deletions lemarche/templates/cms/faq_page.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends "layouts/base.html" %}
{% block content %}
<div class="container pt-2 faq-page">
<div class="container py-4 faq-page">
<h1>{{ page.title }}</h1>
{% for block in page.body %}{{ block }}{% endfor %}
<p>{{ page.intro|default:"" }}</p>
{% for block in page.faqs %}{{ block }}{% endfor %}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion lemarche/templates/cms/streams/faq_group_block.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load wagtailcore_tags %}
<div class="faq-group mb-3">
<div class="faq-group mb-4">
<h3>{{ self.group_title }}</h3>
<div class="accordion" id="accordion{{ group_id }}">
{% for faq in self.faqs %}
Expand Down
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

0 comments on commit 204633c

Please sign in to comment.