-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout d’une page "Plan du site" (#279)
* First version * Fix tests * Update translations * Fix XML sitemap URL * Don't lazy load translations in URLS
- Loading branch information
Showing
17 changed files
with
204 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
content_manager/templates/content_manager/blocks/sitemap_entry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% load wagtailcore_tags i18n %} | ||
{% translate "Restricted access" as restricted_access_label %} | ||
{% for subpage in pagelist.get_children.live %} | ||
{% if not subpage.get_view_restrictions or user.is_authenticated %} | ||
<li> | ||
{% if subpage.get_view_restrictions %} | ||
<span class="fr-icon-lock-line" | ||
aria-hidden="true" | ||
title="{{ restricted_access_label }}"></span> | ||
{% endif %} | ||
<a href="{% pageurl subpage %}">{{ subpage.title }}</a> | ||
{% if subpage.get_view_restrictions %}<span class="fr-sr-only">({{ restricted_access_label }})</span>{% endif %} | ||
{% if subpage.get_children.count > 0 %} | ||
<ul> | ||
{% include "content_manager/blocks/sitemap_entry.html" with pagelist=subpage %} | ||
</ul> | ||
{% endif %} | ||
</li> | ||
{% endif %} | ||
{% endfor %} |
33 changes: 33 additions & 0 deletions
33
content_manager/templates/content_manager/sitemap_page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% extends "base.html" %} | ||
|
||
{% load static dsfr_tags wagtailcore_tags wagtailimages_tags i18n %} | ||
|
||
{% block title %} | ||
<title>{{ title }} — {{ settings.content_manager.CmsDsfrConfig.site_title }}</title> | ||
{% endblock title %} | ||
|
||
{% block description %} | ||
<meta name="description" content="{{ home_page.search_description }}" /> | ||
{% endblock description %} | ||
|
||
{% block content %} | ||
{% include "content_manager/blocks/messages.html" %} | ||
|
||
<div class="fr-container fr-mt-6w"> | ||
{% dsfr_breadcrumb breadcrumb %} | ||
<h1>{% translate "Sitemap" %}</h1> | ||
</div> | ||
|
||
<div class="fr-container fr-mt-6w"> | ||
<div class="fr-grid-row fr-grid-row--gutters fr-mb-3w"> | ||
<ul> | ||
<li> | ||
<a href="{% pageurl home_page %}">{{ home_page.title }}</a> | ||
<ul> | ||
{% include "content_manager/blocks/sitemap_entry.html" with pagelist=home_page %} | ||
</ul> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,84 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.core.management import call_command | ||
from django.urls import reverse | ||
from wagtail.models import Page | ||
from wagtail.rich_text import RichText | ||
from wagtail.test.utils import WagtailPageTestCase | ||
from wagtailmenus.models.menuitems import FlatMenuItem, MainMenuItem | ||
from wagtailmenus.models.menus import FlatMenu, MainMenu | ||
|
||
from content_manager.models import CatalogIndexPage, CmsDsfrConfig, ContentPage, MegaMenu, MegaMenuCategory | ||
from content_manager.services.accessors import get_or_create_content_page | ||
from content_manager.utils import get_default_site | ||
|
||
User = get_user_model() | ||
|
||
|
||
class ContentPageTestCase(WagtailPageTestCase): | ||
def setUp(self): | ||
home = Page.objects.get(slug="home") | ||
home_page = Page.objects.get(slug="home") | ||
self.admin = User.objects.create_superuser("test", "[email protected]", "pass") | ||
self.admin.save() | ||
self.content_page = home.add_child( | ||
self.public_content_page = home_page.add_child( | ||
instance=ContentPage( | ||
title="Page de contenu", | ||
slug="content-page", | ||
title="Page de contenu publique", | ||
slug="public-content-page", | ||
owner=self.admin, | ||
) | ||
) | ||
self.content_page.save() | ||
self.public_content_page.save() | ||
self.private_content_page = get_or_create_content_page( | ||
"private-content-page", | ||
title="Page de contenu privée", | ||
body=[("subpageslist", None)], | ||
parent_page=home_page, | ||
restriction_type="login", | ||
) | ||
self.private_content_page.save() | ||
|
||
def test_content_page_is_renderable(self): | ||
self.assertPageIsRenderable(self.content_page) | ||
self.assertPageIsRenderable(self.public_content_page) | ||
|
||
def test_content_page_has_minimal_content(self): | ||
url = self.content_page.url | ||
response = self.client.get(url) | ||
response = self.client.get(self.public_content_page.url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
self.assertContains( | ||
response, | ||
"<title>Page de contenu — Titre du site</title>", | ||
"<title>Page de contenu publique — Titre du site</title>", | ||
) | ||
|
||
def test_public_content_page_is_in_the_site_map(self): | ||
url = reverse("readable_sitemap") | ||
response = self.client.get(url) | ||
|
||
self.assertContains( | ||
response, | ||
"""<a href="/public-content-page/">Page de contenu publique</a>""", | ||
) | ||
|
||
def test_private_content_page_is_not_rendered_when_logged_out(self): | ||
response = self.client.get(self.private_content_page.url) | ||
|
||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_private_content_page_is_not_in_the_site_map_when_logged_out(self): | ||
url = reverse("readable_sitemap") | ||
response = self.client.get(url) | ||
|
||
self.assertNotContains( | ||
response, | ||
"""<a href="/private-content-page/">Page de contenu privée</a>""", | ||
) | ||
|
||
def test_private_content_page_is_in_the_site_map_when_logged_in(self): | ||
self.client.login(username="test", password="pass") | ||
url = reverse("readable_sitemap") | ||
response = self.client.get(url) | ||
|
||
self.assertContains( | ||
response, | ||
"""<a href="/private-content-page/">Page de contenu privée</a>""", | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.