diff --git a/petition/templates/petition/petition.html b/petition/templates/petition/petition.html index 0187fb2..0bd459e 100644 --- a/petition/templates/petition/petition.html +++ b/petition/templates/petition/petition.html @@ -1,8 +1,20 @@ -{% extends base.html %} +{% extends "base.html" %} {% block content %}

Pétition — Réparons cette sonnette !

+{% if just_signed %} +

+ Merci d'avoir signé ! +

+{% endif %} +{% if just_error %} +

+ Votre signature était invalide. N'avez-vous pas utilisé le même email deux + fois ? +

+{% endif %} +

Signez

@@ -11,11 +23,13 @@

{% csrf_token %} + {{ form }} +
-Gens ayant déjà signé +

Gens ayant déjà signé

{% if not signers %} diff --git a/petition/views.py b/petition/views.py index 91ea44a..f8565c0 100644 --- a/petition/views.py +++ b/petition/views.py @@ -1,3 +1,32 @@ from django.shortcuts import render +from .models import Signature +from .forms import SignatureForm -# Create your views here. + +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)