-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
289 additions
and
10 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
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 |
---|---|---|
|
@@ -5,12 +5,13 @@ | |
from wagtail.images.models import Image | ||
from wagtail.models import Page, Site | ||
from wagtail.rich_text import RichText | ||
from wagtailmenus.models.menuitems import FlatMenuItem | ||
from wagtailmenus.models.menuitems import FlatMenuItem, MainMenuItem | ||
|
||
from content_manager.models import ContentPage | ||
from content_manager.utils import get_or_create_footer_menu | ||
from content_manager.utils import get_or_create_footer_menu, get_or_create_main_menu | ||
from forms.models import FormField, FormPage | ||
|
||
ALL_ALLOWED_SLUGS = ["home", "mentions-legales", "accessibilite"] | ||
ALL_ALLOWED_SLUGS = ["home", "mentions-legales", "accessibilite", "contact"] | ||
|
||
|
||
class Command(BaseCommand): | ||
|
@@ -80,6 +81,8 @@ def handle(self, *args, **kwargs): | |
|
||
body.append(("alert", alert_block)) | ||
self.create_page(slug=slug, title=title, body=body, footer_label="Accessibilité : non conforme") | ||
elif slug == "contact": | ||
self.create_contact_page(slug) | ||
else: | ||
raise ValueError(f"Valeur inconnue : {slug}") | ||
|
||
|
@@ -171,3 +174,99 @@ def create_page(self, slug: str, title: str, body: list, footer_label: str = "") | |
FlatMenuItem.objects.create(**footer_item) | ||
|
||
self.stdout.write(self.style.SUCCESS(f"Page {slug} created with id {new_page.id}")) | ||
|
||
def create_contact_page(self, slug: str = "contact") -> None: | ||
""" | ||
Creates a contact page for the site and adds it the main menu | ||
""" | ||
|
||
# Don't replace a manually created page | ||
already_exists = ContentPage.objects.filter(slug=slug).first() | ||
if already_exists: | ||
self.stdout.write(f"The contact page seem to already exist with id {already_exists.id}") | ||
return | ||
|
||
# Create the form page | ||
title = "Contact" | ||
intro = RichText( | ||
""" | ||
<p>Bonjour, n’hésitez pas à nous contacter via le formulaire ci-dessous.</p> | ||
<p></p> | ||
<p>Vous pouvez également nous contacter via <autres méthodes>.</p> | ||
<p></p> | ||
<p>Les champs marqués d’une astérisque (*) sont obligatoires.</p>""" | ||
) | ||
|
||
thank_you_text = RichText("<p>Merci pour votre message ! Nous reviendrons vers vous rapidement.</p>") | ||
|
||
default_site = Site.objects.filter(is_default_site=True).first() | ||
home_page = default_site.root_page | ||
contact_page = home_page.add_child( | ||
instance=FormPage(title=title, slug=slug, intro=intro, thank_you_text=thank_you_text, show_in_menus=True) | ||
) | ||
|
||
# Create the form fields | ||
fields = [ | ||
{ | ||
"sort_order": 0, | ||
"clean_name": "votre_nom_complet", | ||
"label": "Votre nom complet", | ||
"required": True, | ||
"page": contact_page, | ||
"field_type": "singleline", | ||
}, | ||
{ | ||
"sort_order": 1, | ||
"clean_name": "votre_adresse_electronique", | ||
"label": "Votre adresse électronique", | ||
"required": True, | ||
"choices": "", | ||
"default_value": "", | ||
"help_text": "Format attendu : [email protected]", | ||
"page": contact_page, | ||
"field_type": "email", | ||
}, | ||
{ | ||
"sort_order": 2, | ||
"clean_name": "votre_numero_de_telephone", | ||
"label": "Votre numéro de téléphone", | ||
"required": False, | ||
"page": contact_page, | ||
"field_type": "singleline", | ||
}, | ||
{ | ||
"sort_order": 3, | ||
"clean_name": "titre_de_votre_message", | ||
"label": "Titre de votre message", | ||
"required": True, | ||
"page": contact_page, | ||
"field_type": "singleline", | ||
}, | ||
{ | ||
"sort_order": 4, | ||
"clean_name": "votre_message", | ||
"label": "Votre message", | ||
"required": True, | ||
"choices": "", | ||
"default_value": "", | ||
"help_text": "", | ||
"page": contact_page, | ||
"field_type": "multiline", | ||
}, | ||
] | ||
|
||
for field_data in fields: | ||
FormField.objects.create(**field_data) | ||
|
||
# Menu item | ||
main_menu = get_or_create_main_menu() | ||
|
||
menu_item = { | ||
"sort_order": MainMenuItem.objects.filter(menu=main_menu).count(), | ||
"link_page": contact_page, | ||
"link_text": title, | ||
"menu": main_menu, | ||
} | ||
MainMenuItem.objects.create(**menu_item) | ||
|
||
self.stdout.write(self.style.SUCCESS(f"Form page {slug} created with id {contact_page.id}")) |
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