-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore: Migration des pages flatpage vers wagtail #1496
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
75bc94a
Migration de suppression des modèles FlatPage et PageFragment
chloend 4550954
Suppression de admin.py dans le module 'pages'
chloend 47bbdec
Suppression de pages obsolètes utilisant les flatpages
chloend 54816a1
Ajout d'un custom message à la place de PageFragment
chloend 4e4252d
Export des pages statiques wagtail vers les settings
chloend 86f6286
Intégration des liens wagtail
chloend 7aed830
Suppression des vues HomeView et Pageview
chloend dc48969
Commande et tests pour charger des pages à partir d'un JSON
chloend a8255de
Instruction sur la commande create_content_pages
chloend d2a4533
Test : assertion sur la réponse http d'une page nouvellement créée
chloend 37cd3a9
Suppression page 'accessibilité'
chloend f9addb9
Ajout des instructions de 'create_content_pages'
chloend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import json | ||
|
||
from django.core.management.base import BaseCommand | ||
from wagtail.models import Site | ||
|
||
from content_manager.models import ContentPage | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Creates a series of content pages. | ||
""" | ||
|
||
def handle(self, *args, **kwargs): | ||
try: | ||
with open("lemarche/fixtures/cms_content_pages.json") as f: | ||
pages_data = json.load(f) | ||
except FileNotFoundError: | ||
self.stdout.write( | ||
self.style.ERROR("Le fichier content_manager/fixtures/cms_content_pages.json n'existe pas.") | ||
) | ||
return | ||
except json.JSONDecodeError: | ||
self.stdout.write( | ||
self.style.ERROR( | ||
"Le fichier content_manager/fixtures/cms_content_pages.json n'est pas un fichier JSON valide." | ||
) | ||
) | ||
return | ||
|
||
home_page = Site.objects.filter(is_default_site=True).first().root_page | ||
|
||
for page_data in pages_data: | ||
slug = page_data["slug"] | ||
title = page_data["title"] | ||
body = page_data.get("body", []) | ||
|
||
self.create_content_page(slug, title, body, home_page) | ||
|
||
def create_content_page(self, slug: str, title: str, body: list, parent_page: ContentPage) -> ContentPage: | ||
""" | ||
Creates a page for the site. | ||
""" | ||
|
||
# Don't replace or duplicate an already existing page | ||
already_exists = ContentPage.objects.filter(slug=slug).first() | ||
if already_exists: | ||
self.stdout.write(f"The {slug} page seem to already exist with id {already_exists.id}") | ||
return already_exists | ||
|
||
new_page = parent_page.add_child(instance=ContentPage(title=title, body=body, slug=slug, show_in_menus=True)) | ||
|
||
self.stdout.write(self.style.SUCCESS(f"Page {slug} created with id {new_page.id}")) | ||
|
||
return new_page |
25 changes: 25 additions & 0 deletions
25
lemarche/cms/migrations/0014_homepage_sub_header_custom_message.py
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,25 @@ | ||
# Generated by Django 4.2.15 on 2024-10-23 10:31 | ||
|
||
import wagtail.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0013_alter_articlepage_intro_alter_faqpage_intro"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="homepage", | ||
name="sub_header_custom_message", | ||
field=wagtail.fields.StreamField( | ||
[("message", 0)], | ||
blank=True, | ||
block_lookup={0: ("wagtail.blocks.RichTextBlock", (), {"label": "Message personnalisé du bandeau"})}, | ||
help_text="Contenu affiché dans le bandeau sous l'en-tête.", | ||
null=True, | ||
verbose_name="Message personnalisé du bandeau", | ||
), | ||
), | ||
] |
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
Empty file.
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,43 @@ | ||
import json | ||
|
||
from django.core.management import call_command | ||
from django.test import Client, TestCase | ||
from wagtail.models import Site | ||
|
||
from content_manager.models import ContentPage | ||
|
||
|
||
class CreateContentPagesCommandTests(TestCase): | ||
def test_create_content_pages_with_json(self): | ||
client = Client() | ||
with open("lemarche/fixtures/cms_content_pages.json") as f: | ||
pages_data = json.load(f) | ||
|
||
call_command("create_content_pages") | ||
|
||
# Check that the pages were created | ||
for page_data in pages_data: | ||
slug = page_data["slug"] | ||
self.assertTrue( | ||
ContentPage.objects.filter(slug=slug).exists(), msg=f"La page avec le slug '{slug}' n'a pas été créée." | ||
) | ||
|
||
response = client.get(f"/{slug}/") | ||
self.assertEqual( | ||
response.status_code, | ||
200, | ||
msg=f"La page avec le slug '{slug}' n'est pas accessible (status: {response.status_code}).", | ||
) | ||
|
||
def test_prevent_duplicate_page_creation(self): | ||
"""Ensure the command does not create duplicate pages""" | ||
home_page = Site.objects.get(is_default_site=True).root_page | ||
home_page.add_child(instance=ContentPage(slug="mentions-legales", title="Mentions légales")) | ||
|
||
call_command("create_content_pages") | ||
|
||
self.assertEqual( | ||
ContentPage.objects.filter(slug="mentions-legales").count(), | ||
1, | ||
msg="Une page en double a été créée pour le slug 'mentions-legales'.", | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi t'as ajouté ça ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est pour remplacer l'utilisation du modèle PageFragment dans ArticleBase. Sorry j'ai oublié de préciser, j'avais oublié pourquoi j'avais ajouté ça en vrai héhé
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bien joué ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le mettre juste en charfield sinon :)