aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--views.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/views.py b/views.py
index 473b319..8696358 100644
--- a/views.py
+++ b/views.py
@@ -57,12 +57,13 @@ def subscribe(request, timetable_slug, group_slug, year, week):
if request.method == "POST":
form = SubscribeForm(request.POST)
if form.is_valid():
- subscription = Subscription(email=request.POST["email"], group=group)
- subscription.save()
+ if not Subscription.objects.filter(email=request.POST["email"], group=group).exists():
+ subscription = Subscription(email=request.POST["email"], group=group)
+ subscription.save()
- template = loader.get_template("mail/mail_confirm.txt")
- context = Context({"group": group, "admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
- send_mail("Confirmation de l'abonnemenent", template.render(context), settings.DEFAULT_FROM_EMAIL, [request.POST["email"]])
+ template = loader.get_template("mail/mail_confirm.txt")
+ context = Context({"group": group, "admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
+ send_mail("Confirmation de l'abonnemenent", template.render(context), settings.DEFAULT_FROM_EMAIL, [request.POST["email"]])
return redirect("timetable", timetable_slug=timetable_slug, group_slug=group_slug, year=year, week=int(week))
else:
@@ -71,15 +72,13 @@ def subscribe(request, timetable_slug, group_slug, year, week):
return render(request, "subscribe.html", {"year": year, "week": week, "group": group, "form": form})
def confirm_subscription(request, token):
- subscription = get_object_or_404(Subscription, token=token)
- if subscription.active:
- raise Http404()
-
- subscription.active = True
- subscription.save()
-
+ subscription = Subscription.objects.filter(token=token).first()
year, week = get_current_or_next_week()
+ if subscription is not None and not subscription.active:
+ subscription.active = True
+ subscription.save()
+
return redirect("timetable", timetable_slug=subscription.group.timetable.slug, group_slug=subscription.group.slug, year=year, week=week)
def cancel_subscription(request, token):