From 826e45f6193f7e00e1ac49ab08a6c677d797329c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Tue, 25 Aug 2020 19:22:54 +0200 Subject: [PATCH] Move CaptchaFrom from views.py to forms.py --- gestioncof/cms/forms.py | 15 +++++++++++++++ gestioncof/cms/views.py | 17 ++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 gestioncof/cms/forms.py 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)