diff options
author | Alban Gruin | 2017-02-09 10:33:14 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-09 10:33:14 +0100 |
commit | b18cd6268dd83371602fc2ec77dd812b90cea046 (patch) | |
tree | 9fc067bf8d278f0efb42e5a4cb7362947166f983 /views.py | |
parent | eabb136dcb27deaf2e899f4205cefcb588a28669 (diff) |
Les fonctions d'abonnement ne retournent pas une erreur 404 si les enregistrements ne rencontrent pas les critères
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -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): |