From 7386f8bd2b289bc334360771aa287290fffd87f1 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Mon, 6 Feb 2017 18:56:28 +0100 Subject: Ne retourne pas de 404 si le token n'existe pas --- views.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/views.py b/views.py index 8696358..b5d4cbf 100644 --- a/views.py +++ b/views.py @@ -82,12 +82,14 @@ def confirm_subscription(request, token): return redirect("timetable", timetable_slug=subscription.group.timetable.slug, group_slug=subscription.group.slug, year=year, week=week) def cancel_subscription(request, token): - subscription = get_object_or_404(Subscription, token=token) - group = subscription.group - subscription.delete() + subscription = Subscription.objects.filter(token=token).first() + + if subscription is not None: + group = subscription.group + subscription.delete() - template = loader.get_template("mail/mail_unsubscribed.txt") - context = Context({"group": group}) - send_mail("Confirmation de la désinscription", template.render(context), settings.DEFAULT_FROM_EMAIL, [subscription.email]) + template = loader.get_template("mail/mail_unsubscribed.txt") + context = Context({"group": group}) + send_mail("Confirmation de la désinscription", template.render(context), settings.DEFAULT_FROM_EMAIL, [subscription.email]) return redirect("index") -- cgit v1.2.1