2017-02-05 17:10:51 +01:00
|
|
|
from django import forms
|
|
|
|
from django.contrib.auth.models import User
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.forms import ModelForm
|
2020-09-14 11:40:21 +02:00
|
|
|
from django.forms.models import inlineformset_factory
|
2021-03-04 17:56:42 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from hcaptcha.fields import hCaptchaField
|
2019-01-05 18:14:29 +01:00
|
|
|
|
2018-11-25 00:37:22 +01:00
|
|
|
from petitscours.models import PetitCoursAbility, PetitCoursDemande
|
2017-02-05 17:10:51 +01:00
|
|
|
|
|
|
|
|
2021-03-04 17:56:42 +01:00
|
|
|
class hCaptchaFieldWithErrors(hCaptchaField):
|
|
|
|
"""
|
|
|
|
Pour l'instant, hCaptchaField ne supporte pas le paramètre `error_messages` lors de
|
|
|
|
l'initialisation. Du coup, on les redéfinit à la main.
|
|
|
|
"""
|
|
|
|
|
|
|
|
default_error_messages = {
|
|
|
|
"required": _("Veuillez vérifier que vous êtes bien humain·e."),
|
|
|
|
"error_hcaptcha": _("Erreur lors de la vérification."),
|
|
|
|
"invalid_hcaptcha": _("Échec de la vérification !"),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-05 17:10:51 +01:00
|
|
|
class DemandeForm(ModelForm):
|
2021-03-04 17:56:42 +01:00
|
|
|
captcha = hCaptchaFieldWithErrors()
|
2017-02-05 17:10:51 +01:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-01-16 16:22:52 +01:00
|
|
|
super().__init__(*args, **kwargs)
|
2018-10-06 12:35:49 +02:00
|
|
|
self.fields["matieres"].help_text = ""
|
2017-02-05 17:10:51 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PetitCoursDemande
|
2018-10-06 12:35:49 +02:00
|
|
|
fields = (
|
|
|
|
"name",
|
|
|
|
"email",
|
|
|
|
"phone",
|
|
|
|
"quand",
|
|
|
|
"freq",
|
|
|
|
"lieu",
|
|
|
|
"matieres",
|
|
|
|
"agrege_requis",
|
|
|
|
"niveau",
|
|
|
|
"remarques",
|
|
|
|
)
|
|
|
|
widgets = {"matieres": forms.CheckboxSelectMultiple}
|
2017-02-05 17:10:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
MatieresFormSet = inlineformset_factory(
|
|
|
|
User,
|
|
|
|
PetitCoursAbility,
|
|
|
|
fields=("matiere", "niveau", "agrege"),
|
|
|
|
)
|