-
Notifications
You must be signed in to change notification settings - Fork 34
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
16 changed files
with
197 additions
and
113 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
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 @@ | ||
# Register your models here. |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FormsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "forms" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-06-25 10:02+0200\n" | ||
"PO-Revision-Date: 2024-06-25 10:09+0200\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: fr\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n > 1);\n" | ||
"X-Generator: Poedit 3.4.2\n" | ||
|
||
#: forms/models.py:14 | ||
msgid "Single line text" | ||
msgstr "Texte sur une ligne" | ||
|
||
#: forms/models.py:15 | ||
msgid "Multi-line text" | ||
msgstr "Texte sur plusieurs lignes" | ||
|
||
#: forms/models.py:16 | ||
msgid "Email" | ||
msgstr "Adresse e-mail" | ||
|
||
#: forms/models.py:17 | ||
msgid "Number" | ||
msgstr "Nombre" | ||
|
||
#: forms/models.py:18 | ||
msgid "URL" | ||
msgstr "URL" | ||
|
||
#: forms/models.py:19 | ||
msgid "Checkbox" | ||
msgstr "Case à cocher" | ||
|
||
#: forms/models.py:20 | ||
msgid "Checkboxes" | ||
msgstr "Cases à cocher" | ||
|
||
#: forms/models.py:21 | ||
msgid "Drop down" | ||
msgstr "Liste déroulante" | ||
|
||
#: forms/models.py:22 | ||
msgid "Radio buttons" | ||
msgstr "Boutons radio" | ||
|
||
#: forms/models.py:23 | ||
msgid "Date" | ||
msgstr "Date" | ||
|
||
#: forms/models.py:24 | ||
msgid "Date/time" | ||
msgstr "Date et heure" | ||
|
||
#: forms/models.py:25 | ||
msgid "Hidden field" | ||
msgstr "Champ caché" |
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,103 @@ | ||
from django.db import models | ||
from django.forms import widgets | ||
from django.template.response import TemplateResponse | ||
from django.utils.translation import gettext_lazy as _ | ||
from modelcluster.fields import ParentalKey | ||
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.fields import RichTextField | ||
|
||
|
||
class FormField(AbstractFormField): | ||
FORM_FIELD_CHOICES = ( | ||
("singleline", _("Single line text")), | ||
("multiline", _("Multi-line text")), | ||
("email", _("Email")), | ||
("number", _("Number")), | ||
("url", _("URL")), | ||
("checkbox", _("Checkbox")), | ||
("cmsfr_checkboxes", _("Checkboxes")), | ||
("dropdown", _("Drop down")), | ||
("cmsfr_radio", _("Radio buttons")), | ||
("cmsfr_date", _("Date")), | ||
("cmsfr_datetime", _("Date/time")), | ||
("hidden", _("Hidden field")), | ||
) | ||
|
||
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", heading="Introduction"), | ||
InlinePanel("form_fields", label="Champs de formulaire"), | ||
FieldPanel("thank_you_text", heading="Texte de remerciement"), | ||
MultiFieldPanel( | ||
[ | ||
FieldRowPanel( | ||
[ | ||
FieldPanel("from_address", classname="col6"), | ||
FieldPanel("to_address", classname="col6"), | ||
] | ||
), | ||
FieldPanel("subject"), | ||
], | ||
"Courriel", | ||
help_text="Facultatif", | ||
), | ||
] | ||
|
||
class Meta: | ||
verbose_name = "Page de formulaire" | ||
verbose_name_plural = "Pages de formulaire" | ||
|
||
def serve(self, request, *args, **kwargs): | ||
# These input widgets don't need the fr-input class | ||
if request.method == "POST": | ||
form = self.get_form(request.POST, request.FILES, page=self, user=request.user) | ||
|
||
if form.is_valid(): | ||
form_submission = self.process_form_submission(form) | ||
return self.render_landing_page(request, form_submission, *args, **kwargs) | ||
else: | ||
form = self.get_form(page=self, user=request.user) | ||
|
||
WIDGETS_NO_FR_INPUT = [ | ||
widgets.CheckboxInput, | ||
widgets.FileInput, | ||
widgets.ClearableFileInput, | ||
] | ||
|
||
for visible in form.visible_fields(): | ||
""" | ||
Depending on the widget, we have to add some classes: | ||
- on the outer group | ||
- on the form field itsef | ||
If a class is already set, we don't force the DSFR-specific classes. | ||
""" | ||
if "class" not in visible.field.widget.attrs: | ||
if type(visible.field.widget) in [ | ||
widgets.Select, | ||
widgets.SelectMultiple, | ||
]: | ||
visible.field.widget.attrs["class"] = "fr-select" | ||
visible.field.widget.group_class = "fr-select-group" | ||
elif isinstance(visible.field.widget, widgets.DateInput): | ||
visible.field.widget.attrs["class"] = "fr-input" | ||
visible.field.widget.attrs["type"] = "date" | ||
elif isinstance(visible.field.widget, widgets.RadioSelect): | ||
visible.field.widget.attrs["dsfr"] = "dsfr" | ||
visible.field.widget.group_class = "fr-radio-group" | ||
elif isinstance(visible.field.widget, widgets.CheckboxSelectMultiple): | ||
visible.field.widget.attrs["dsfr"] = "dsfr" | ||
elif type(visible.field.widget) not in WIDGETS_NO_FR_INPUT: | ||
visible.field.widget.attrs["class"] = "fr-input" | ||
|
||
context = self.get_context(request) | ||
context["form"] = form | ||
return TemplateResponse(request, self.get_template(request), context) |
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
File renamed without changes.
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 @@ | ||
# Create your tests here. |
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 @@ | ||
# Create your views here. |
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