Commit d9e968ce authored by Nicolas G.'s avatar Nicolas G.

(Bogue) antispam : id non contigu

L'antispam ne fonctionnait que si les enregistrements dans la table se
suivent strictement.
parent 21d29a48
......@@ -20,4 +20,8 @@ from django.contrib import admin
# Register your models here.
from antispam.models import Questions
admin.site.register(Questions)
class QuestionsAdmin(admin.ModelAdmin):
list_display=('question', 'reponse')
admin.site.register(Questions,QuestionsAdmin)
......@@ -23,17 +23,26 @@
from django import forms
from fj.models import Inscrits
from django.utils.translation import gettext_lazy as _
import random
from random import randint
from django.db.models import Min, Max
from antispam.models import Questions
class InscritsForm(forms.ModelForm):
""" Formulaire d'inscription """
nombre = Questions.objects.all().count() # Nombre de questions dans la base
aleatoire = random.randint(1,nombre) # Un id au hasard
question = Questions.objects.get(pk=aleatoire) # On en choisie une au hasard
boundaries = Questions.objects.aggregate(Min('id'), Max('id'))# Les extrémités
question = None
essais = 0
while question is None:
try:
question = Questions.objects.get(pk=randint(boundaries['id__min'], boundaries['id__max'])) # On en choisie une au hasard
except Questions.DoesNotExist:
essais += 1
else:
break
print(essais)
verification = forms.CharField(required=True,max_length=20, label=question.question) # Le champ de formulaire avec le libellé de la question
ident = forms.CharField(initial=str(aleatoire), widget=forms.HiddenInput()) # On transmet l'id de la question
ident = forms.CharField(initial=str(question.pk), widget=forms.HiddenInput()) # On transmet l'id de la question
class Meta:
model = Inscrits
fields = ('nom', 'prenom', 'asso', 'courriel', 'nb')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment