petition-sonnette/petition/views.py

32 lines
760 B
Python

from django.shortcuts import render
from .models import Signature
from .forms import SignatureForm
def view_petition(req):
just_signed = False
just_error = False
signers = Signature.objects.all()
if req.method == 'POST':
form = SignatureForm(req.POST)
if form.is_valid():
if len(signers) < 5000:
form.save()
just_signed = True
else:
just_error = True
if just_signed:
signers = Signature.objects.all()
context = {
'form': SignatureForm(),
'just_signed': just_signed,
'just_error': just_error,
'num_signers': len(signers),
'signers': signers,
}
return render(req, 'petition/petition.html', context)