forked from DGNum/gestioCOF
Move CaptchaFrom from views.py to forms.py
This commit is contained in:
parent
5989f65154
commit
826e45f619
2 changed files with 17 additions and 15 deletions
15
gestioncof/cms/forms.py
Normal file
15
gestioncof/cms/forms.py
Normal 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
|
|
@ -1,25 +1,12 @@
|
||||||
import re
|
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.shortcuts import render
|
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):
|
def raw_calendar_view(request, year, month):
|
||||||
return render(request, "cofcms/calendar_raw.html", {"month": month, "year": year})
|
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):
|
def sympa_captcha_form_view(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = CaptchaForm(request.POST)
|
form = CaptchaForm(request.POST)
|
||||||
|
|
Loading…
Add table
Reference in a new issue