diff options
-rw-r--r-- | urls.py | 3 | ||||
-rw-r--r-- | views.py | 37 |
2 files changed, 35 insertions, 5 deletions
@@ -19,7 +19,8 @@ from . import feeds, views urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^pages/", include("django.contrib.flatpages.urls")), - url(r"^salles/", views.rooms, name="rooms"), + url(r"^salles/$", views.rooms, name="rooms"), + url(r"^salles/(?P<room_slug>[-\w]+)$", views.room_timetable), 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"), @@ -15,12 +15,12 @@ import datetime -from django.db.models import Max -from django.db.models.functions import Length +from django.db.models import Count, Max +from django.db.models.functions import ExtractWeek, ExtractYear, Length from django.http import Http404 from django.shortcuts import get_object_or_404, render -from .models import Timetable, Group, Course, Year +from .models import Course, Group, Room, Timetable, Year from .utils import get_current_week, get_current_or_next_week, get_week, group_courses import edt @@ -97,7 +97,36 @@ def calendars(request, year_slug, timetable_slug, group_slug): return render(request, "calendars.html", {"group": group, "groups": groups}) def rooms(request): - return render(request, "index.html") + # On récupère les dates allant de cette semaine à dans un mois + start, _ = get_week(*get_current_week()) + end = start + datetime.timedelta(weeks=4) + + # Récupération des salles et de toutes les semaines où elles sont + # concernées + # Cette requête est un peu lente sur sqlite… j’espère que ce sera mieux + # sur la base de prod. + rooms = Room.objects.filter(course__begin__gte=start, course__begin__lt=end) \ + .annotate(year=ExtractYear("course__begin"), + week=ExtractWeek("course__begin")) \ + .order_by("name").annotate(c=Count("*")) + + rooms_weeks = [] + for room in rooms: + if len(rooms_weeks) == 0 or rooms_weeks[-1].id != room.id: + room.weeks = [] + rooms_weeks.append(room) + + date, _ = get_week(room.year, room.week) + rooms_weeks[-1].weeks.append(date) + + return render(request, "group_list.html", {"groups": rooms_weeks}) + +def room_timetable(request, room_slug): + room = get_object_or_404(Room, slug=room_slug) + courses = Course.objects.filter(rooms__in=(room,)).order_by("begin") + + return render(request, "timetable.html", {"group": room, "courser": courses, + }) def ctx_processor(request): return {"celcatsanitizer_version": edt.VERSION} |