Archived
1
Fork 0
This repository has been archived on 2024-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
lps-wagtail/lps/base/models.py

85 lines
2.5 KiB
Python

from django.db import models
from modelcluster.fields import ParentalKey
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
from wagtail.contrib.forms.panels import FormSubmissionsPanel
from wagtail.contrib.settings.models import BaseGenericSetting, register_setting
from wagtail.fields import RichTextField, StreamField
@register_setting
class NavigationSettings(BaseGenericSetting):
address = models.CharField(max_length=256, verbose_name="Adresse", blank=True)
phone = models.CharField(
max_length=32, verbose_name="Numéro de téléphone", blank=True
)
email = models.EmailField(verbose_name="Adresse de courriel", blank=True)
links = StreamField(
[
(
"link",
blocks.StructBlock(
[
("title", blocks.CharBlock()),
("url", blocks.URLBlock()),
]
),
)
],
blank=True,
)
panels = [
MultiFieldPanel(
[
FieldPanel("address"),
FieldPanel("phone"),
FieldPanel("email"),
FieldPanel("links"),
],
"Informations de contact",
)
]
@register_setting
class SiteSettings(BaseGenericSetting):
icon = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Icône du site",
)
panels = [MultiFieldPanel([FieldPanel("icon")], "Informations du site")]
class FormField(AbstractFormField):
page = ParentalKey("FormPage", on_delete=models.CASCADE, related_name="form_fields")
class FormPage(AbstractEmailForm):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
FormSubmissionsPanel(),
FieldPanel("intro"),
InlinePanel("form_fields", label="Champs de formulaire"),
FieldPanel("thank_you_text"),
MultiFieldPanel(
[
FieldRowPanel(
[
FieldPanel("from_address"),
FieldPanel("to_address"),
]
),
FieldPanel("subject"),
],
"Email",
),
]