From e0d2b72c30ec26ca953c52d6bec33dc030d18947 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 22 Jan 2017 19:10:26 +0100 Subject: Ajout d'un formulaire pour s'abonner à un emploi du temps --- templates/subscribe.html | 15 +++++++++++++++ templates/timetable.html | 3 ++- urls.py | 1 + views.py | 14 +++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 templates/subscribe.html diff --git a/templates/subscribe.html b/templates/subscribe.html new file mode 100644 index 0000000..8fe4b79 --- /dev/null +++ b/templates/subscribe.html @@ -0,0 +1,15 @@ +{% extends "index.html" %} + +{% block title %}S'abonner à {{ timetable.name }} – {{ group.name }}{% endblock %} + +{% block body %} +

S'abonner à {{ timetable.name }} – {{ group.name }}

+
+ + {% csrf_token %} + +
+

Après l'abonnement, vous allez recevoir un mail avec un lien de confirmation. Aucun autre mail ne vous sera envoyé si vous n'avez pas validé votre abonnement.
+ Vous pouvez vous désabonner à tout moment à l'aide d'un lien contenu dans tout les mails que nous vous enverrons.
+ Nous ne partageons votre adresse à qui que se soit. Lorsque vous vous désabonnez, votre adresse est effacée de nos serveurs.

+{% endblock %} diff --git a/templates/timetable.html b/templates/timetable.html index 8c125c5..16a21c8 100644 --- a/templates/timetable.html +++ b/templates/timetable.html @@ -10,4 +10,5 @@ - {% endfor %}{% endblock %} + +

S'abonner à cet emploi du temps

{% endfor %}{% endblock %} diff --git a/urls.py b/urls.py index 1805bb0..95e51a5 100644 --- a/urls.py +++ b/urls.py @@ -5,6 +5,7 @@ from . import views urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^(?P[-\w]+)/(?P[0-9]{4})/(?P[0-53]{1,2})/(?P[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P[-\w]+)/(?P[0-9]{4})/(?P[0-53]{1,2})/(?P[-\w]+)/subscribe$", views.subscribe, name="subscribe"), url(r"^subscriptions/confirm/(?P[0-9a-f]{40})$", views.confirm_subscription, name="confirm"), url(r"^subscriptions/cancel/(?P[0-9a-f]{40})$", views.cancel_subscription, name="cancel"), ] diff --git a/views.py b/views.py index 729333f..9040c9e 100644 --- a/views.py +++ b/views.py @@ -40,7 +40,19 @@ def timetable(request, timetable_slug, year, week, group_slug): else: grouped_courses[-1].append(course) - return render_to_response("timetable.html", {"timetable": timetable, "group": group, "courses": grouped_courses, "last_update": last_update.date, "week": week}) + return render_to_response("timetable.html", {"timetable": timetable, "group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": week}) + +def subscribe(request, timetable_slug, year, week, group_slug): + group = get_object_or_404(Group, slug=group_slug) + + if request.method == "POST": + subscription = Subscription(email=request.POST["email"], group=group) + subscription.save() + + return redirect("timetable", timetable_slug=timetable_slug, year=year, week=week, group_slug=group_slug) + else: + timetable = get_object_or_404(Timetable, slug=timetable_slug) + return render(request, "subscribe.html", {"timetable": timetable, "year": year, "week": week, "group": group}) def confirm_subscription(request, token): subscription = get_object_or_404(Subscription, token=token) -- cgit v1.2.1