Skip to content

Commit

Permalink
Merge pull request #93 from numerique-gouv/page-types-update
Browse files Browse the repository at this point in the history
Mise à jour des ContentPage pour utiliser la nouvelle classe de base
  • Loading branch information
Ash-Crow authored Mar 11, 2024
2 parents fb47403 + a46ed44 commit c146e9d
Show file tree
Hide file tree
Showing 33 changed files with 3,935 additions and 271 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ dmypy.json
.vscode/

# Project-specific stuff
config.json
cron.json
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ init:
$(EXEC_CMD) poetry run pre-commit install
$(EXEC_CMD) poetry run python manage.py migrate
make collectstatic
$(EXEC_CMD) poetry run python manage.py set_config
$(EXEC_CMD) poetry run python manage.py create_sample_pages

.PHONY: runserver
Expand Down
7 changes: 0 additions & 7 deletions blog/managers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from django.db import models
from django.db.models import Count


class TagManager(models.Manager):
def most_common(self, blog_page):
entries = blog_page.get_entries()
return self.filter(entrypage__in=entries).annotate(num_times=Count("entrypage")).order_by("-num_times")


class CategoryManager(models.Manager):
Expand Down
1,081 changes: 1,081 additions & 0 deletions blog/migrations/0003_blogentrypage_header_color_class_and_more.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 5.0.2 on 2024-03-05 18:04

import modelcluster.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("blog", "0004_alter_blogentrypage_body_alter_blogindexpage_body"),
]

operations = [
migrations.DeleteModel(
name="Tag",
),
migrations.AddField(
model_name="blogentrypage",
name="header_cta_text",
field=models.CharField(blank=True, null=True, verbose_name="Call to action text"),
),
migrations.AddField(
model_name="blogindexpage",
name="header_cta_text",
field=models.CharField(blank=True, null=True, verbose_name="Call to action text"),
),
migrations.AlterField(
model_name="blogentrypage",
name="blog_categories",
field=modelcluster.fields.ParentalManyToManyField(
blank=True, through="blog.CategoryEntryPage", to="blog.category", verbose_name="Categories"
),
),
migrations.AlterField(
model_name="blogentrypage",
name="header_cta_label",
field=models.CharField(blank=True, null=True, verbose_name="Call to action label"),
),
migrations.AlterField(
model_name="blogentrypage",
name="header_cta_link",
field=models.URLField(blank=True, null=True, verbose_name="Call to action link"),
),
migrations.AlterField(
model_name="blogentrypage",
name="header_darken",
field=models.BooleanField(default=False, verbose_name="Darken background image"),
),
migrations.AlterField(
model_name="blogindexpage",
name="header_cta_label",
field=models.CharField(blank=True, null=True, verbose_name="Call to action label"),
),
migrations.AlterField(
model_name="blogindexpage",
name="header_cta_link",
field=models.URLField(blank=True, null=True, verbose_name="Call to action link"),
),
migrations.AlterField(
model_name="blogindexpage",
name="header_darken",
field=models.BooleanField(default=False, verbose_name="Darken background image"),
),
]
14 changes: 3 additions & 11 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
from django.utils.translation import get_language, gettext_lazy as _
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.tags import ClusterTaggableManager
from taggit.models import Tag as TaggitTag, TaggedItemBase
from taggit.models import TaggedItemBase
from wagtail.admin.panels import FieldPanel, FieldRowPanel, MultiFieldPanel, TitleFieldPanel
from wagtail.admin.widgets.slug import SlugInput
from wagtail.models.i18n import Locale, TranslatableMixin
from wagtail.search import index
from wagtail.snippets.models import register_snippet

from blog.managers import CategoryManager, TagManager
from blog.managers import CategoryManager
from content_manager.abstract import SitesFacilesBasePage
from content_manager.models import Tag


User = get_user_model()
Expand Down Expand Up @@ -163,7 +164,6 @@ class BlogEntryPage(SitesFacilesBasePage):
"Category",
through="CategoryEntryPage",
blank=True,
null=True,
verbose_name=_("Categories"),
)
date = models.DateTimeField(verbose_name=_("Post date"), default=timezone.now)
Expand Down Expand Up @@ -266,11 +266,3 @@ def __str__(self):

class TagEntryPage(TaggedItemBase):
content_object = ParentalKey("BlogEntryPage", related_name="entry_tags")


@register_snippet
class Tag(TaggitTag):
objects = TagManager()

class Meta:
proxy = True
2 changes: 1 addition & 1 deletion blog/templates/blog/blog_entry_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{% endblock social_media %}

{% block content %}
{% include "content_manager/blocks/hero_image.html" %}
{% include "content_manager/blocks/heading.html" %}
{% include "content_manager/blocks/messages.html" %}

<div class="fr-container fr-mt-6w">
Expand Down
68 changes: 33 additions & 35 deletions blog/templates/blog/blog_index_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{% endblock social_media %}

{% block content %}
{% include "content_manager/blocks/hero_image.html" %}
{% include "content_manager/blocks/heading.html" %}
{% include "content_manager/blocks/messages.html" %}

<div class="fr-container fr-mt-6w">
Expand All @@ -67,45 +67,43 @@ <h1>{{ page.title }}</h1>

<div class="fr-container fr-mt-6w">
<div class="fr-grid-row fr-grid-row--gutters fr-mb-3w">
{% if posts %}
{% for post in posts %}
<div class="fr-col fr-col-md-6">
<div class="fr-card fr-enlarge-link">
<div class="fr-card__body">
<div class="fr-card__content">
<h2 class="fr-card__title">
<a href="{{ post.url }}">{{ post.title }}</a>
</h2>
<p class="fr-card__desc">Publié le {{ post.date |date:'l j F Y' }}</p>
{% for post in posts %}
<div class="fr-col fr-col-md-6">
<div class="fr-card fr-enlarge-link">
<div class="fr-card__body">
<div class="fr-card__content">
<h2 class="fr-card__title">
<a href="{{ post.url }}">{{ post.title }}</a>
</h2>
<p class="fr-card__desc">Publié le {{ post.date |date:'l j F Y' }}</p>

{% if post.blog_categories.all %}
<div class="fr-card__start">
<ul class="fr-tags-group">
{% for category in post.blog_categories.all %}
<li>
<p class="fr-tag">{{ category.name }}</p>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
{% if post.header_image %}
<div class="fr-card__header">
<div class="fr-card__img">
<img class="fr-responsive-img"
src="{{ post.header_image.file.url }}"
alt="">
{% if post.blog_categories.all %}
<div class="fr-card__start">
<ul class="fr-tags-group">
{% for category in post.blog_categories.all %}
<li>
<p class="fr-tag">{{ category.name }}</p>
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% endif %}
</div>
</div>
{% if post.header_image %}
<div class="fr-card__header">
<div class="fr-card__img">
<img class="fr-responsive-img"
src="{{ post.header_image.file.url }}"
alt="">
</div>
</div>
{% endif %}
</div>
{% endfor %}
{% else %}
</div>
{% empty %}
<p>Aucun article trouvé.</p>
{% endif %}
{% endfor %}
</div>
</div>

Expand Down
9 changes: 9 additions & 0 deletions config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"header_brand": "Intitulé officiel",
"header_brand_html": "Intitulé<br />officiel",
"footer_brand": "Intitulé officiel",
"footer_brand_html": "Intitulé<br />officiel",
"site_title": "Titre du site",
"site_tagline": "Sous-titre du site",
"footer_description": "Description"
}
65 changes: 63 additions & 2 deletions content_manager/abstract.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from wagtail.admin.panels import FieldPanel
from dsfr.constants import COLOR_CHOICES
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.fields import StreamField
from wagtail.images import get_image_model_string
from wagtail.models import Page
from wagtail.search import index

from content_manager.blocks import STREAMFIELD_COMMON_BLOCKS
from content_manager.utils import get_streamfield_raw_text


class SitesFacilesBasePage(Page):
Expand All @@ -19,6 +22,8 @@ class SitesFacilesBasePage(Page):
blank=True,
use_json_field=True,
)
header_with_title = models.BooleanField(_("Show title in header image?"), default=False)

header_image = models.ForeignKey(
get_image_model_string(),
null=True,
Expand All @@ -28,14 +33,70 @@ class SitesFacilesBasePage(Page):
verbose_name=_("Header image"),
)

header_color_class = models.CharField(
_("Background color"),
choices=COLOR_CHOICES,
null=True,
blank=True,
help_text=_("Uses the French Design System colors"),
)

header_large = models.BooleanField(_("Full width"), default=False)
header_darken = models.BooleanField(_("Darken background image"), default=False)

header_cta_text = models.CharField(
_("Call to action text"),
null=True,
blank=True,
)

header_cta_label = models.CharField(
_("Call to action label"),
null=True,
blank=True,
)

header_cta_link = models.URLField(
_("Call to action link"),
null=True,
blank=True,
)

content_panels = Page.content_panels + [
FieldPanel("header_image"),
FieldPanel("body", heading=_("Body")),
]

promote_panels = [
MultiFieldPanel(Page.promote_panels, _("Common page configuration")),
MultiFieldPanel(
[
FieldPanel("header_with_title"),
FieldPanel("header_image"),
FieldPanel("header_color_class"),
FieldPanel("header_large"),
FieldPanel("header_darken"),
FieldPanel("header_cta_text"),
FieldPanel("header_cta_label"),
FieldPanel("header_cta_link"),
],
heading=_("Header options"),
),
]

search_fields = Page.search_fields + [
index.SearchField("body"),
]

def get_absolute_url(self):
return self.url

def save(self, *args, **kwargs):
if not self.search_description:
search_description = get_streamfield_raw_text(self.body, max_words=20)
if search_description:
self.search_description = search_description
return super().save(*args, **kwargs)

class Meta:
abstract = True
verbose_name = _("Base page")
Expand Down
Loading

0 comments on commit c146e9d

Please sign in to comment.