diff options
-rw-r--r-- | templates/index.html | 6 | ||||
-rw-r--r-- | urls.py | 1 | ||||
-rw-r--r-- | views.py | 15 |
3 files changed, 19 insertions, 3 deletions
diff --git a/templates/index.html b/templates/index.html index 005fd5b..c47a0be 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,7 +4,7 @@ <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> {% block head %}{% endblock %} - <title>{% block title %}{% if year %}{{ year }} – {% endif %}{% endblock %}celcatsanitizer</title> + <title>{% block title %}{% if year %}{{ year }}{% elif group %}{{ group }}{% endif %}{% if year or group %} – {% endif %}{% endblock %}celcatsanitizer</title> <link rel="stylesheet" href="{% static "celcatsanitizer/style.css" %}"> </head> <body> @@ -13,10 +13,10 @@ </header> <div class="content"> {% block body %} - <h3>{% if year %}{{ year }} – Choisissez votre mention{% else %}Choisissez votre année{% endif %}</h3> + <h3>{% if year %}{{ year }} – Choisissez votre mention{% elif group %}Calendriers disponibles pour le groupe {{ group }}{% else %}Choisissez votre année{% endif %}</h3> <ul> {% for element in elements %} - <li><a href="{% if year %}{% url "groups" year.slug element.slug %}{% else %}{% url "mentions" element.slug %}{% endif %}">{{ element }}</a></li> + <li><a href="{% if year %}{% url "groups" year.slug element.slug %}{% elif group %}{% url "ics-group" group.timetable.year.slug group.timetable.slug element.slug %}{% else %}{% url "mentions" element.slug %}{% endif %}">{{ element }}</a></li> {% empty %} <p><em>Aucun emploi du temps à afficher</em></p> {% endfor %} @@ -22,6 +22,7 @@ urlpatterns = [ url(r"^(?P<year_slug>[-\w]+)/$", views.mention_list, name="mentions"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/$", views.group_list, name="groups"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/$", views.timetable, name="timetable"), + url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendars$", views.calendar_list, name="calendar-list"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar.ics$", feeds.IcalFeed(), name="ics"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/calendar-group.ics$", feeds.IcalOnlyOneFeed(), name="ics-group"), url(r"^(?P<year_slug>[-\w]+)/(?P<timetable_slug>[-\w]+)/(?P<group_slug>[-\w]+)/feed.atom$", feeds.AtomFeed(), name="atom"), @@ -17,6 +17,7 @@ import datetime from django.conf import settings from django.db.models import Max +from django.db.models.functions import Length from django.http import Http404 from django.shortcuts import get_object_or_404, render @@ -95,5 +96,19 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No "year": year, "week": int(week), "is_old_timetable": is_old_timetable}) +def calendar_list(request, year_slug, timetable_slug, group_slug): + """Affiche une liste des ICS disponibles pour un groupe.""" + # On commence par récupérer l’emploi du temps associé, puis le groupe + # Si la récupération de l’un d’entre eux échoue, on affiche une erreur 404. + timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) + group = get_object_or_404(Group, slug=group_slug, timetable=timetable) + + # On récupère les groupes « parents » au groupe spécifié. + groups = Group.objects.get_parents(group).annotate(length=Length("subgroup")) \ + .order_by("length") + + # On réutilise encore la template principale + return render(request, "index.html", {"group": group, "elements": groups}) + def contact(request): return render(request, "contact.html", {"email": settings.ADMINS[0][1]}) |