From b18cd6268dd83371602fc2ec77dd812b90cea046 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 9 Feb 2017 10:33:14 +0100 Subject: Les fonctions d'abonnement ne retournent pas une erreur 404 si les enregistrements ne rencontrent pas les critères --- views.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'views.py') 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): -- cgit v1.2.1 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(-) (limited to 'views.py') 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 From 50f4e5d3277d611f3b9a662f436346e03f6e3996 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 9 Feb 2017 11:34:59 +0100 Subject: Plus de décalage artificiel à la semaine prochaine dans les vues --- views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'views.py') diff --git a/views.py b/views.py index b5d4cbf..f02061e 100644 --- a/views.py +++ b/views.py @@ -8,7 +8,7 @@ from django.template import Context, loader from edt.forms import SubscribeForm from edt.models import Timetable, LastUpdate, Group, Subscription, Course -from edt.utils import get_current_or_next_week, get_week, group_courses +from edt.utils import get_current_week, get_week, group_courses import datetime @@ -16,7 +16,7 @@ def index(request): timetables = Timetable.objects.all() groups = Group.objects.filter(tp__isnull=False).order_by("name") - year, week = get_current_or_next_week() + year, week = get_current_week() start, _ = get_week(year, week) groups_weeks = Course.objects.get_weeks(begin__gte=start).values("groups__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") @@ -37,7 +37,7 @@ def index(request): def timetable(request, timetable_slug, group_slug, year=None, week=None): if year is None or week is None: - year, week = get_current_or_next_week() + year, week = get_current_week() start, end = get_week(int(year), int(week)) @@ -73,7 +73,7 @@ def subscribe(request, timetable_slug, group_slug, year, week): def confirm_subscription(request, token): subscription = Subscription.objects.filter(token=token).first() - year, week = get_current_or_next_week() + year, week = get_current_week() if subscription is not None and not subscription.active: subscription.active = True -- cgit v1.2.1 From 18e9abfc4b2160d71aa3842eb6ae1a093dcfeeac Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 9 Feb 2017 11:56:11 +0100 Subject: Ajout d'une licence (gpl2) --- views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'views.py') diff --git a/views.py b/views.py index f02061e..273720a 100644 --- a/views.py +++ b/views.py @@ -1,3 +1,19 @@ +# Copyright (C) 2017 Alban Gruin +# +# celcatsanitizer is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# celcatsanitizer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + from django.http import HttpResponse, Http404 from django.db.models import Count from django.shortcuts import get_object_or_404, redirect, render -- cgit v1.2.1