aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'views.py')
-rw-r--r--views.py51
1 files changed, 2 insertions, 49 deletions
diff --git a/views.py b/views.py
index 2101a21..f445725 100644
--- a/views.py
+++ b/views.py
@@ -13,13 +13,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
-from django.shortcuts import get_object_or_404, redirect, render
-from django.core.mail import send_mail
-from django.conf import settings
-from django.template import Context, loader
+from django.shortcuts import get_object_or_404, render
-from .forms import SubscribeForm
-from .models import Timetable, LastUpdate, Group, Subscription, Course, Year
+from .models import Timetable, LastUpdate, Group, Course, Year
from .utils import get_current_week, get_week, group_courses
def index(request):
@@ -69,46 +65,3 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No
grouped_courses = group_courses(courses)
return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": int(week)})
-
-def subscribe(request, year_slug, timetable_slug, group_slug, year, week):
- group = get_object_or_404(Group, slug=group_slug, timetable__slug=timetable_slug, timetable__year__slug=year_slug)
-
- if request.method == "POST":
- form = SubscribeForm(request.POST)
- if form.is_valid():
- 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"]])
-
- return redirect("timetable", year_slug=year_slug, timetable_slug=timetable_slug, group_slug=group_slug, year=year, week=int(week))
- else:
- form = SubscribeForm()
-
- return render(request, "subscribe.html", {"year": year, "week": week, "group": group, "form": form})
-
-def confirm_subscription(request, token):
- subscription = Subscription.objects.filter(token=token).first()
- year, week = get_current_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):
- 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])
-
- return redirect("index")