Implement view
This commit is contained in:
parent
7b90c17094
commit
17ff53277b
2 changed files with 46 additions and 3 deletions
|
@ -1,8 +1,20 @@
|
||||||
{% extends base.html %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Pétition — Réparons cette sonnette !</h1>
|
<h1>Pétition — Réparons cette sonnette !</h1>
|
||||||
|
|
||||||
|
{% if just_signed %}
|
||||||
|
<p style="background-color: #a7ffc0; font-size: 1.3em">
|
||||||
|
Merci d'avoir signé !
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if just_error %}
|
||||||
|
<p style="background-color: #a7ffc0; font-size: 1.3em">
|
||||||
|
Votre signature était invalide. N'avez-vous pas utilisé le même email deux
|
||||||
|
fois ?
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h2>Signez</h2>
|
<h2>Signez</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -11,11 +23,13 @@
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<table>
|
||||||
{{ form }}
|
{{ form }}
|
||||||
|
</table>
|
||||||
<input type="submit" value="Faire entendre votre droit à une sonnette !" />
|
<input type="submit" value="Faire entendre votre droit à une sonnette !" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</h2>Gens ayant déjà signé</h2>
|
<h2>Gens ayant déjà signé</h2>
|
||||||
|
|
||||||
{% if not signers %}
|
{% if not signers %}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,32 @@
|
||||||
from django.shortcuts import render
|
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)
|
||||||
|
|
Loading…
Reference in a new issue