Move CaptchaFrom from views.py to forms.py

This commit is contained in:
Martin Pépin 2020-08-25 19:22:54 +02:00
parent 5989f65154
commit 826e45f619
No known key found for this signature in database
GPG key ID: E7520278B1774448
2 changed files with 17 additions and 15 deletions

15
gestioncof/cms/forms.py Normal file
View file

@ -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

View file

@ -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)