diff options
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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) |