diff options
author | Alban Gruin | 2017-01-22 19:10:26 +0100 |
---|---|---|
committer | Alban Gruin | 2017-01-22 19:10:26 +0100 |
commit | e0d2b72c30ec26ca953c52d6bec33dc030d18947 (patch) | |
tree | 1861a7392ddcc062cae796bf0e43170036c75c80 | |
parent | c0f72b8c7062eceda834beae57efbe95d94eb4f9 (diff) |
Ajout d'un formulaire pour s'abonner à un emploi du temps
-rw-r--r-- | templates/subscribe.html | 15 | ||||
-rw-r--r-- | templates/timetable.html | 3 | ||||
-rw-r--r-- | urls.py | 1 | ||||
-rw-r--r-- | views.py | 14 |
4 files changed, 31 insertions, 2 deletions
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 %} + <h2>S'abonner à {{ timetable.name }} – {{ group.name }}</h2> + <form action="{% url "subscribe" timetable.slug year week group.slug %}" method="post"> + <input placeholder="Votre adresse mail" type="email" name="email" /> + {% csrf_token %} + <input type="submit" /> + </form> + <p>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.<br /> + Vous pouvez vous désabonner à tout moment à l'aide d'un lien contenu dans tout les mails que nous vous enverrons.<br /> + Nous ne partageons votre adresse à qui que se soit. Lorsque vous vous désabonnez, votre adresse est effacée de nos serveurs.</p> +{% 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 @@ <ul>{% for course in day %} <li class="course"><b>{{ course.name }}</b>, de {{ course.begin|date:"H:i" }} à {{ course.end|date:"H:i" }}{% if course.rooms.all|length > 0 %}<br /><em>Salle{% if course.rooms.all|length > 1 %}s{% endif %} {% for room in course.rooms.all %}{{ room }} {% endfor %}</em>{% endif %}</li>{% endfor %} </ul> - </section>{% endfor %}{% endblock %} + </section> + <p><a href="{% url "subscribe" timetable.slug year week group.slug %}">S'abonner à cet emploi du temps</a></p>{% endfor %}{% endblock %} @@ -5,6 +5,7 @@ from . import views urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^(?P<timetable_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-53]{1,2})/(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P<timetable_slug>[-\w]+)/(?P<year>[0-9]{4})/(?P<week>[0-53]{1,2})/(?P<group_slug>[-\w]+)/subscribe$", views.subscribe, name="subscribe"), url(r"^subscriptions/confirm/(?P<token>[0-9a-f]{40})$", views.confirm_subscription, name="confirm"), url(r"^subscriptions/cancel/(?P<token>[0-9a-f]{40})$", views.cancel_subscription, name="cancel"), ] @@ -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) |