diff --git a/gestioncof/cms/forms.py b/gestioncof/cms/forms.py new file mode 100644 index 00000000..d2766bf0 --- /dev/null +++ b/gestioncof/cms/forms.py @@ -0,0 +1,15 @@ +import re + +from django import forms +from django.utils.translation import gettext as _ + + +class CaptchaForm(forms.Form): + answer = forms.CharField(label="Réponse", max_length=32) + + def clean_answer(self): + value = self.cleaned_data["answer"] + if not re.match(r"(les|the)? *ernests?", value.strip().lower()): + raise forms.ValidationError(_("Réponse incorrecte")) + + return value diff --git a/gestioncof/cms/views.py b/gestioncof/cms/views.py index 8ea7c625..83a67ae6 100644 --- a/gestioncof/cms/views.py +++ b/gestioncof/cms/views.py @@ -1,25 +1,12 @@ -import re - -from django import forms from django.shortcuts import render -from django.utils.translation import gettext as _ + +from gestioncof.cms.forms import CaptchaForm def raw_calendar_view(request, year, month): return render(request, "cofcms/calendar_raw.html", {"month": month, "year": year}) -class CaptchaForm(forms.Form): - answer = forms.CharField(label="Réponse", max_length=32) - - def clean_answer(self): - value = self.cleaned_data["answer"] - if not re.match(r"(les|the)? *ernests?", value.strip().lower()): - raise forms.ValidationError(_("Réponse incorrecte")) - - return value - - def sympa_captcha_form_view(request): if request.method == "POST": form = CaptchaForm(request.POST)