aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-01-22 19:20:05 +0100
committerAlban Gruin2017-01-22 19:20:05 +0100
commit245b978ee20a7091cb2924bc14ae36f4d0460477 (patch)
tree82a7275a03ea19d4dd7357d9e63a3882a3b21369 /views.py
parentab3885a7cc8551061da8bc41835933a75c9937e0 (diff)
Utilisation d'un formulaire Django pour faire ça proprement
Diffstat (limited to 'views.py')
-rw-r--r--views.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/views.py b/views.py
index 28b069e..c106668 100644
--- a/views.py
+++ b/views.py
@@ -3,6 +3,7 @@ from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
+from edt.forms import SubscribeForm
from edt.models import Timetable, LastUpdate, Group, Subscription, Course
from edt.utils import get_week
@@ -46,13 +47,17 @@ def subscribe(request, timetable_slug, year, week, group_slug):
group = get_object_or_404(Group, slug=group_slug)
if request.method == "POST":
- subscription = Subscription(email=request.POST["email"], group=group)
- subscription.save()
+ form = SubscribeForm(request.POST)
+ if form.is_valid():
+ subscription = Subscription(email=request.POST["email"], group=group)
+ subscription.save()
- return redirect("timetable", timetable_slug=timetable_slug, year=year, week=week, group_slug=group_slug)
+ return redirect("timetable", timetable_slug=timetable_slug, year=year, week=week, group_slug=group_slug)
else:
- timetable = get_object_or_404(Timetable, slug=timetable_slug)
- return render(request, "subscribe.html", {"timetable": timetable, "year": year, "week": week, "group": group})
+ form = SubscribeForm()
+
+ timetable = get_object_or_404(Timetable, slug=timetable_slug)
+ return render(request, "subscribe.html", {"timetable": timetable, "year": year, "week": week, "group": group, "form": form})
def confirm_subscription(request, token):
subscription = get_object_or_404(Subscription, token=token)