2018-02-05 21:36:12 +01:00
|
|
|
from django.shortcuts import render
|
2018-02-05 22:16:52 +01:00
|
|
|
from .models import Signature
|
|
|
|
from .forms import SignatureForm
|
2018-02-05 21:36:12 +01:00
|
|
|
|
2018-02-05 22:16:52 +01:00
|
|
|
|
|
|
|
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)
|