aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--templates/subscribe.html15
-rw-r--r--templates/timetable.html3
-rw-r--r--urls.py1
-rw-r--r--views.py14
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 }} &ndash; {{ 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 %}
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<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"),
]
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)